Skip to content

Commit

Permalink
Logical Ops: Allows logicalNot to be chained. (tensorflow#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
manrajgrover authored and Nikhil Thorat committed Apr 8, 2018
1 parent 6994ffc commit 3a4cfc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/ops/logicalop_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ describeWithFlags('logicalNot', ALL_ENVS, () => {
const a = dl.tensor1d([1, NaN, 0], 'bool');
expectArraysClose(dl.logicalNot(a), [0, boolNaN, 1]);
});
it('Tests chaining in Tensor1D', () => {
let a = dl.tensor1d([1, 0, 0], 'bool');
expectArraysClose(a.logicalNot(), [0, 1, 1]);

a = dl.tensor1d([0, 0, 0], 'bool');
expectArraysClose(a.logicalNot(), [1, 1, 1]);

a = dl.tensor1d([1, 1], 'bool');
expectArraysClose(a.logicalNot(), [0, 0]);
});

it('Tensor2D', () => {
let a = dl.tensor2d([[1, 0, 1], [0, 0, 0]], [2, 3], 'bool');
Expand Down
7 changes: 5 additions & 2 deletions src/tensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export class TensorBuffer<R extends Rank> {

private strides: number[];

constructor(
shape: ShapeMap[R], public dtype: DataType, values: TypedArray) {
constructor(shape: ShapeMap[R], public dtype: DataType, values: TypedArray) {
if (values != null) {
const n = values.length;
const size = util.sizeFromShape(shape);
Expand Down Expand Up @@ -671,6 +670,10 @@ export class Tensor<R extends Rank = Rank> {
this.throwIfDisposed();
return ops.logicalOr(this, x);
}
logicalNot<T extends Tensor>(this: T): T {
this.throwIfDisposed();
return ops.logicalNot(this);
}
logicalXor(x: Tensor): Tensor {
this.throwIfDisposed();
return ops.logicalXor(this, x);
Expand Down

0 comments on commit 3a4cfc4

Please sign in to comment.