src/comparison

Procs

proc clip(arr: var NDArray; minVal: float; maxVal: float): var NDArray {.
    discardable, ...raises: [], tags: [], forbids: [].}
proc clipMax(arr: var NDArray; maxVal: float): var NDArray {.discardable,
    ...raises: [], tags: [], forbids: [].}
proc clipMin(arr: var NDArray; minVal: float): var NDArray {.discardable,
    ...raises: [], tags: [], forbids: [].}
proc newEqual(arr: NDArray; other: NDArray): NDArray {....raises: [ValueError],
    tags: [], forbids: [].}

Element-wise equality comparison (returns new array).

Returns 1.0 where arr == other, 0.0 elsewhere.

Parameters:

  • other - Array to compare (must have same shape)

Returns: New array with comparison results

Example:

let a = newOnes(@[2, 3])
let b = newOnes(@[2, 3])
let result = a.newEqual(b)  # All 1.0
proc newEqualScalar(arr: NDArray; value: float): NDArray {....raises: [ValueError],
    tags: [], forbids: [].}

Scalar equality comparison (returns new array).

Returns 1.0 where arr == value, 0.0 elsewhere.

Parameters:

  • value - Scalar value to compare

Returns: New array with comparison results

Example:

let arr = newArange(@[2, 3], 0.0, 6.0, 1.0)
let result = arr.newEqualScalar(3.0)  # 1.0 only at position with value 3
proc newGreater(arr: NDArray; other: NDArray): NDArray {....raises: [ValueError],
    tags: [], forbids: [].}

Element-wise greater-than comparison (returns new array).

Returns 1.0 where arr > other, 0.0 elsewhere.

Parameters:

  • other - Array to compare (must have same shape)

Returns: New array with comparison results

Example:

let a = newArange(@[2, 3], 0.0, 6.0, 1.0)
let b = newFull(@[2, 3], 2.5)
let result = a.newGreater(b)  # [0, 0, 0, 1, 1, 1]
proc newGreaterScalar(arr: NDArray; value: float): NDArray {.
    ...raises: [ValueError], tags: [], forbids: [].}

Scalar greater-than comparison (returns new array).

Returns 1.0 where arr > value, 0.0 elsewhere.

Parameters:

  • value - Scalar value to compare

Returns: New array with comparison results

Example:

let arr = newArange(@[2, 3], 0.0, 6.0, 1.0)
let result = arr.newGreaterScalar(2.5)  # 1.0 where values > 2.5
proc newLess(arr: NDArray; other: NDArray): NDArray {....raises: [ValueError],
    tags: [], forbids: [].}

Element-wise less-than comparison (returns new array).

Returns 1.0 where arr < other, 0.0 elsewhere.

Parameters:

  • other - Array to compare (must have same shape)

Returns: New array with comparison results

Example:

let a = newArange(@[2, 3], 0.0, 6.0, 1.0)
let b = newFull(@[2, 3], 3.0)
let result = a.newLess(b)  # [1, 1, 1, 0, 0, 0]
proc newLessScalar(arr: NDArray; value: float): NDArray {....raises: [ValueError],
    tags: [], forbids: [].}

Scalar less-than comparison (returns new array).

Returns 1.0 where arr < value, 0.0 elsewhere.

Parameters:

  • value - Scalar value to compare

Returns: New array with comparison results

Example:

let arr = newArange(@[2, 3], 0.0, 6.0, 1.0)
let result = arr.newLessScalar(3.0)  # 1.0 where values < 3
proc newLogicalAnd(arr: NDArray; other: NDArray): NDArray {.
    ...raises: [ValueError], tags: [], forbids: [].}

Logical AND operation (returns new array).

Returns 1.0 where both arr and other are non-zero, 0.0 elsewhere.

Parameters:

  • other - Array to AND with (must have same shape)

Returns: New array with logical AND results

Example:

let a = newArange(@[2, 3], 0.0, 6.0, 1.0)
let b = newGreaterScalar(a, 2.5)
let c = newLessScalar(a, 4.5)
let result = b.newLogicalAnd(c)  # 1.0 where 2.5 < val < 4.5
proc newLogicalNot(arr: NDArray): NDArray {....raises: [ValueError], tags: [],
    forbids: [].}

Logical NOT operation (returns new array).

Returns 1.0 where arr is zero, 0.0 where arr is non-zero.

Returns: New array with logical NOT results

Example:

let arr = newArange(@[2, 3], 0.0, 6.0, 1.0)
let mask = newLessScalar(arr, 3.0)
let inverted = mask.newLogicalNot()  # Inverts the mask
proc newLogicalOr(arr: NDArray; other: NDArray): NDArray {....raises: [ValueError],
    tags: [], forbids: [].}

Logical OR operation (returns new array).

Returns 1.0 where either arr or other is non-zero, 0.0 elsewhere.

Parameters:

  • other - Array to OR with (must have same shape)

Returns: New array with logical OR results

Example:

let a = newArange(@[2, 3], 0.0, 6.0, 1.0)
let b = newLessScalar(a, 2.0)
let c = newGreaterScalar(a, 4.0)
let result = b.newLogicalOr(c)  # 1.0 where val < 2 OR val > 4
proc newWhere(condition: NDArray; x: NDArray; y: NDArray): NDArray {.
    ...raises: [ValueError], tags: [], forbids: [].}

NumPy-style conditional selection (returns new array).

Returns x where condition is non-zero, y where condition is zero.

Parameters:

  • condition - Boolean array (non-zero = true)
  • x - Array to select from when condition is true
  • y - Array to select from when condition is false

Returns: New array with selected values

Example:

let data = newArange(@[2, 3], 0.0, 6.0, 1.0)
let mask = data.newGreaterScalar(2.5)
let zeros = newZeros(@[2, 3])
let filtered = newWhere(mask, data, zeros)  # Keep values > 2.5, rest = 0