Skip to content

Commit

Permalink
Merge pull request #118 from BruceDai/add_notEqual
Browse files Browse the repository at this point in the history
Implement notEqual
  • Loading branch information
huningxin authored Dec 18, 2024
2 parents 2fbf635 + a01f892 commit 9897038
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/logical.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export const logicalNot = (input) => logicalNotImpl(input);
export const logicalOr =
(inputA, inputB) => binary(inputA, inputB, (a, b) => (!!a || !!b ? 1 : 0));
export const logicalXor = (inputA, inputB) => binary(inputA, inputB, (a, b) => (!!a ^ !!b));
export const notEqual = (inputA, inputB) => logicalNot(equal(inputA, inputB));
50 changes: 49 additions & 1 deletion test/logical_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import {equal, greater, greaterOrEqual, lesser, lesserOrEqual,
logicalAnd, logicalNot, logicalOr, logicalXor} from '../src/logical.js';
logicalAnd, logicalNot, logicalOr, logicalXor, notEqual} from '../src/logical.js';
import {Tensor} from '../src/lib/tensor.js';
import * as utils from './utils.js';

Expand Down Expand Up @@ -515,4 +515,52 @@ describe('test logical', function() {
};
testLogical(inputA, inputB, expected, logicalXor);
});

it('notEqual 0D scalar', function() {
const inputA = {
shape: [],
data: [0.5],
};
const inputB = {
shape: [],
data: [0.5],
};
const expected = {
shape: [],
data: [0],
};
testLogical(inputA, inputB, expected, notEqual);
});

it('notEqual 4D', function() {
const inputA = {
shape: [1, 2, 2, 1],
data: [-1, 1, 1, 0],
};
const inputB = {
shape: [1, 2, 2, 1],
data: [1, 0, -1, 0],
};
const expected = {
shape: [1, 2, 2, 1],
data: [1, 1, 1, 0],
};
testLogical(inputA, inputB, expected, notEqual);
});

it('notEqual 4D broadcast', function() {
const inputA = {
shape: [1, 2, 2, 1],
data: [-1, 1, 1, 0],
};
const inputB = {
shape: [1],
data: [1],
};
const expected = {
shape: [1, 2, 2, 1],
data: [1, 0, 0, 1],
};
testLogical(inputA, inputB, expected, notEqual);
});
});

0 comments on commit 9897038

Please sign in to comment.