braintools.spike.bitwise#
- braintools.spike.bitwise(x, y, op)#
Perform bitwise operations on spike tensors.
This function applies various bitwise operations on spike tensors based on the specified operation. It supports the
'or','and','iand','xor'and'ixor'operations.- Parameters:
- Returns:
The result of the bitwise operation applied to the input tensors.
- Return type:
Array|ndarray|bool|number|bool|int|float|complex|Quantity- Raises:
NotImplementedError – If an unsupported bitwise operation is specified.
See also
bitwise_or,bitwise_and,bitwise_iand,bitwise_xor,bitwise_ixorNotes
For numeric inputs the function uses the following expressions; boolean inputs use the equivalent logical functions and return a boolean mask:
\[\begin{split}\begin{array}{ccc} \hline \text { Mode } & \text { Expression for } \mathrm{g}(\mathrm{x}, \mathrm{y}) & \text { Code for } \mathrm{g}(\mathrm{x}, \mathrm{y}) \\ \hline \text { AND } & x \cap y & x \cdot y \\ \text { IAND } & (\neg x) \cap y & (1-x) \cdot y \\ \text { OR } & x \cup y & (x+y)-(x \cdot y) \\ \text { XOR } & (x \cup y) \cap \neg (x \cap y) & x+y-2 x \cdot y \\ \text { IXOR } & (x \cap \neg y) \cup (\neg x \cap y) & x \cdot (1-y)+(1-x) \cdot y \\ \hline \end{array}\end{split}\]Examples
>>> import jax.numpy as jnp >>> import braintools >>> x = jnp.array([0, 0, 1, 1]) >>> y = jnp.array([0, 1, 0, 1]) >>> braintools.spike.bitwise(x, y, 'xor') Array([0, 1, 1, 0], dtype=int32) >>> >>> braintools.spike.bitwise(x.astype(bool), y.astype(bool), 'and') Array([False, False, False, True], dtype=bool)