-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* If fn has rawArgs set, pass unevaluated args * Add shared helper function for evaluating truthiness * Add and & or transform functions for lazy evaluation * Add lazy evaluation of bitwise & and | operators * Add unit tests for lazy evaluation * Add lazy evaluation note to docs * Move documentation to Syntax page * Replace `testCondition()` with test evaluation of logical function itself * Use `isCollection()` to simplify bitwise transform functions * fix: do not copy scope in raw OperatorNode, test lazy operators scope * fix: linting issues --------- Co-authored-by: Brooks Smith <[email protected]>
- Loading branch information
1 parent
424735a
commit 7e9ff61
Showing
8 changed files
with
168 additions
and
5 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,23 @@ | ||
import { createAnd } from '../../function/logical/and.js' | ||
import { factory } from '../../utils/factory.js' | ||
import { isCollection } from '../../utils/is.js' | ||
|
||
const name = 'and' | ||
const dependencies = ['typed', 'matrix', 'zeros', 'add', 'equalScalar', 'not', 'concat'] | ||
|
||
export const createAndTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, not, concat }) => { | ||
const and = createAnd({ typed, matrix, equalScalar, zeros, not, concat }) | ||
|
||
function andTransform (args, math, scope) { | ||
const condition1 = args[0].compile().evaluate(scope) | ||
if (!isCollection(condition1) && !and(condition1, true)) { | ||
return false | ||
} | ||
const condition2 = args[1].compile().evaluate(scope) | ||
return and(condition1, condition2) | ||
} | ||
|
||
andTransform.rawArgs = true | ||
|
||
return andTransform | ||
}, { isTransformFunction: true }) |
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,28 @@ | ||
import { createBitAnd } from '../../function/bitwise/bitAnd.js' | ||
import { factory } from '../../utils/factory.js' | ||
import { isCollection } from '../../utils/is.js' | ||
|
||
const name = 'bitAnd' | ||
const dependencies = ['typed', 'matrix', 'zeros', 'add', 'equalScalar', 'not', 'concat'] | ||
|
||
export const createBitAndTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, zeros, not, concat }) => { | ||
const bitAnd = createBitAnd({ typed, matrix, equalScalar, zeros, not, concat }) | ||
|
||
function bitAndTransform (args, math, scope) { | ||
const condition1 = args[0].compile().evaluate(scope) | ||
if (!isCollection(condition1)) { | ||
if (isNaN(condition1)) { | ||
return NaN | ||
} | ||
if (condition1 === 0 || condition1 === false) { | ||
return 0 | ||
} | ||
} | ||
const condition2 = args[1].compile().evaluate(scope) | ||
return bitAnd(condition1, condition2) | ||
} | ||
|
||
bitAndTransform.rawArgs = true | ||
|
||
return bitAndTransform | ||
}, { isTransformFunction: true }) |
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 @@ | ||
import { createBitOr } from '../../function/bitwise/bitOr.js' | ||
import { factory } from '../../utils/factory.js' | ||
import { isCollection } from '../../utils/is.js' | ||
|
||
const name = 'bitOr' | ||
const dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'] | ||
|
||
export const createBitOrTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, concat }) => { | ||
const bitOr = createBitOr({ typed, matrix, equalScalar, DenseMatrix, concat }) | ||
|
||
function bitOrTransform (args, math, scope) { | ||
const condition1 = args[0].compile().evaluate(scope) | ||
if (!isCollection(condition1)) { | ||
if (isNaN(condition1)) { | ||
return NaN | ||
} | ||
if (condition1 === (-1)) { | ||
return -1 | ||
} | ||
if (condition1 === true) { | ||
return 1 | ||
} | ||
} | ||
const condition2 = args[1].compile().evaluate(scope) | ||
return bitOr(condition1, condition2) | ||
} | ||
|
||
bitOrTransform.rawArgs = true | ||
|
||
return bitOrTransform | ||
}, { isTransformFunction: true }) |
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,23 @@ | ||
import { createOr } from '../../function/logical/or.js' | ||
import { factory } from '../../utils/factory.js' | ||
import { isCollection } from '../../utils/is.js' | ||
|
||
const name = 'or' | ||
const dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'] | ||
|
||
export const createOrTransform = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix, concat }) => { | ||
const or = createOr({ typed, matrix, equalScalar, DenseMatrix, concat }) | ||
|
||
function orTransform (args, math, scope) { | ||
const condition1 = args[0].compile().evaluate(scope) | ||
if (!isCollection(condition1) && or(condition1, false)) { | ||
return true | ||
} | ||
const condition2 = args[1].compile().evaluate(scope) | ||
return or(condition1, condition2) | ||
} | ||
|
||
orTransform.rawArgs = true | ||
|
||
return orTransform | ||
}, { isTransformFunction: true }) |
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