-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from BruceDai/add_logical
Implement element-wise logical operations
- Loading branch information
Showing
4 changed files
with
425 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
import {Tensor, sizeOfShape} from './lib/tensor.js'; | ||
import {validateNotParams} from './lib/validate-input.js'; | ||
import {binary} from './binary.js'; | ||
|
||
/** | ||
* Compute the element-wise logical not operation of input tensors. | ||
* @param {Tensor} input | ||
* @return {Tensor} | ||
*/ | ||
function logicalNot(input) { | ||
validateNotParams(input); | ||
const outputShape = input.shape; | ||
const outputSize = sizeOfShape(outputShape); | ||
const output = new Tensor(outputShape); | ||
for (let i = 0; i < outputSize; ++i) { | ||
const a = input.getValueByIndex(i); | ||
const b = !a ? 1 : 0; | ||
output.setValueByIndex(i, b); | ||
} | ||
return output; | ||
} | ||
|
||
export const equal = (inputA, inputB) => binary(inputA, inputB, (a, b) => (a == b ? 1 : 0)); | ||
export const greater = (inputA, inputB) => binary(inputA, inputB, (a, b) => (a > b ? 1 : 0)); | ||
export const greaterOrEqual = | ||
(inputA, inputB) => binary(inputA, inputB, (a, b) => (a >= b ? 1 : 0)); | ||
export const lesser = (inputA, inputB) => binary(inputA, inputB, (a, b) => (a < b ? 1 : 0)); | ||
export const lesserOrEqual = | ||
(inputA, inputB) => binary(inputA, inputB, (a, b) => (a <= b ? 1 : 0)); | ||
export const not = (input) => logicalNot(input); |
Oops, something went wrong.