nerva_torch.matrix_operations
Matrix operations built on top of torch to support the math in the library.
The functions here intentionally mirror the names in the accompanying docs. They operate on 1D/2D tensors and keep broadcasting explicit for clarity.
Functions
|
Create diagonal matrix with x as diagonal. |
|
Element-wise application of function f to X. |
|
Repeat column vector x horizontally n times. |
|
Returns a column vector with the maximum values of each row in X. |
|
Returns a column vector with the mean values of each row in X. |
|
Sum over columns (returns row vector). |
|
Extract diagonal of X as a vector. |
|
Dot product of vectors x and y. |
|
Returns the sum of the elements of X. |
|
Element-wise exponential exp(X). |
|
Element-wise product X ⊙ Y. |
|
Returns the nxn identity matrix. |
|
Element-wise inverse square root X^(-1/2) with epsilon for stability. |
Check if x can be treated as a column vector. |
|
Check if x can be treated as a row vector. |
|
|
Check if X is a square matrix. |
|
Check if x is a 1D tensor. |
|
Element-wise natural logarithm log(X). |
|
Element-wise log(sigmoid(X)) computed stably. |
|
Returns an mxn matrix with all elements equal to 1. |
|
Matrix multiplication X @ Y. |
|
Element-wise reciprocal 1/X. |
|
Repeat row vector x vertically m times. |
|
Returns a row vector with the maximum values of each column in X. |
|
Returns a row vector with the mean values of each column in X. |
|
Sum over rows (returns column vector). |
|
Element-wise square root √X. |
|
Element-wise square X². |
|
Get size along first dimension. |
|
Returns an mxn matrix with all elements equal to 0. |
- nerva_torch.matrix_operations.is_column_vector(x: torch.Tensor) bool[source]
Check if x can be treated as a column vector.
- nerva_torch.matrix_operations.is_row_vector(x: torch.Tensor) bool[source]
Check if x can be treated as a row vector.
- nerva_torch.matrix_operations.vector_size(x: torch.Tensor) int[source]
Get size along first dimension.
- nerva_torch.matrix_operations.is_square(X: torch.Tensor) bool[source]
Check if X is a square matrix.
- nerva_torch.matrix_operations.dot(x: torch.Tensor, y: torch.Tensor)[source]
Dot product of vectors x and y.
- nerva_torch.matrix_operations.zeros(m: int, n=None) torch.Tensor[source]
Returns an mxn matrix with all elements equal to 0.
- nerva_torch.matrix_operations.ones(m: int, n=None) torch.Tensor[source]
Returns an mxn matrix with all elements equal to 1.
- nerva_torch.matrix_operations.identity(n: int) torch.Tensor[source]
Returns the nxn identity matrix.
- nerva_torch.matrix_operations.product(X: torch.Tensor, Y: torch.Tensor) torch.Tensor[source]
Matrix multiplication X @ Y.
- nerva_torch.matrix_operations.hadamard(X: torch.Tensor, Y: torch.Tensor) torch.Tensor[source]
Element-wise product X ⊙ Y.
- nerva_torch.matrix_operations.diag(X: torch.Tensor) torch.Tensor[source]
Extract diagonal of X as a vector.
- nerva_torch.matrix_operations.Diag(x: torch.Tensor) torch.Tensor[source]
Create diagonal matrix with x as diagonal.
- nerva_torch.matrix_operations.elements_sum(X: torch.Tensor)[source]
Returns the sum of the elements of X.
- nerva_torch.matrix_operations.column_repeat(x: torch.Tensor, n: int) torch.Tensor[source]
Repeat column vector x horizontally n times.
- nerva_torch.matrix_operations.row_repeat(x: torch.Tensor, m: int) torch.Tensor[source]
Repeat row vector x vertically m times.
- nerva_torch.matrix_operations.columns_sum(X: torch.Tensor) torch.Tensor[source]
Sum over columns (returns row vector).
- nerva_torch.matrix_operations.rows_sum(X: torch.Tensor) torch.Tensor[source]
Sum over rows (returns column vector).
- nerva_torch.matrix_operations.columns_max(X: torch.Tensor) torch.Tensor[source]
Returns a column vector with the maximum values of each row in X.
- nerva_torch.matrix_operations.rows_max(X: torch.Tensor) torch.Tensor[source]
Returns a row vector with the maximum values of each column in X.
- nerva_torch.matrix_operations.columns_mean(X: torch.Tensor) torch.Tensor[source]
Returns a column vector with the mean values of each row in X.
- nerva_torch.matrix_operations.rows_mean(X: torch.Tensor) torch.Tensor[source]
Returns a row vector with the mean values of each column in X.
- nerva_torch.matrix_operations.apply(f, X: torch.Tensor) torch.Tensor[source]
Element-wise application of function f to X.
- nerva_torch.matrix_operations.exp(X: torch.Tensor) torch.Tensor[source]
Element-wise exponential exp(X).
- nerva_torch.matrix_operations.log(X: torch.Tensor) torch.Tensor[source]
Element-wise natural logarithm log(X).
- nerva_torch.matrix_operations.reciprocal(X: torch.Tensor) torch.Tensor[source]
Element-wise reciprocal 1/X.
- nerva_torch.matrix_operations.sqrt(X: torch.Tensor) torch.Tensor[source]
Element-wise square root √X.