binary¶
Binary operations for the Tricycle framework.
This module contains binary operations that can be applied to tensors of the same shape. These operations include element-wise addition, subtraction, multiplication, division, and comparison operations like maximum and minimum.
Note
In Tricycle, binary operations are only allowed on matrices of the same shape to simplify gradient computations.
- class BinaryAdd[source]¶
Bases:
Op
Element-wise addition of two tensors.
This class implements the forward pass for element-wise addition of two tensors.
- _out¶
The output of the forward pass.
- Type:
numpy._typing._array_like._SupportsArray[numpy.dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]] | bool | int | float | complex | str | bytes | numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes] | None
- class BinaryDivide[source]¶
Bases:
Op
Element-wise division of two tensors.
This class implements the forward pass for element-wise division of two tensors.
TODO: we should probably fuse these into a single op
- class BinaryMax[source]¶
Bases:
Op
Element-wise maximum of two tensors.
This class implements the forward and backward passes for element-wise maximum of two tensors.
- _is_bigger_1¶
Boolean array indicating where the first tensor is larger.
- _is_bigger_2¶
Boolean array indicating where the second tensor is larger or equal.
- _out¶
The output of the forward pass.
- Type:
numpy._typing._array_like._SupportsArray[numpy.dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]] | bool | int | float | complex | str | bytes | numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes] | None
- _grad_1¶
The gradient for the first tensor.
- _grad_2¶
The gradient for the second tensor.
- class BinaryMin[source]¶
Bases:
Op
Element-wise minimum of two tensors.
This class implements the forward and backward passes for element-wise minimum of two tensors.
- _is_smaller_1¶
Boolean array indicating where the first tensor is smaller.
- _is_smaller_2¶
Boolean array indicating where the second tensor is smaller or equal.
- _out¶
The output of the forward pass.
- Type:
numpy._typing._array_like._SupportsArray[numpy.dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]] | bool | int | float | complex | str | bytes | numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes] | None
- _grad_1¶
The gradient for the first tensor.
- _grad_2¶
The gradient for the second tensor.
- class BinaryMultiply[source]¶
Bases:
Op
Element-wise multiplication of two tensors.
This class implements the forward pass for element-wise multiplication of two tensors.
- class BinarySubtract[source]¶
Bases:
Op
Element-wise subtraction of two tensors.
This class implements the forward and backward passes for element-wise subtraction of two tensors.
- _grad¶
The gradient of the backward pass for the second tensor.
- _out¶
The output of the forward pass.
- Type:
numpy._typing._array_like._SupportsArray[numpy.dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]] | bool | int | float | complex | str | bytes | numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes] | None