Linear Algebra
Matrix Operations
dot - Dot product
Compute dot product of two 1D tensors.
matmul - Matrix multiplication
Multiply two matrices.
transpose - Matrix transpose
Matrix Decompositions
inv - Matrix inverse
det - Determinant
svd - Singular Value Decomposition
eig - Eigenvalues and Eigenvectors
Linear Systems
solve - Solve Ax = b
lstsq - Least squares solution
Complete Example
#include <tensr/tensr.h>
int main() {
/* Create matrices */
float data_a[] = {1, 2, 3, 4, 5, 6};
float data_b[] = {7, 8, 9, 10, 11, 12};
Tensor* a = tensr_from_array((size_t[]){2, 3}, 2, TENSR_FLOAT32, TENSR_CPU, data_a);
Tensor* b = tensr_from_array((size_t[]){3, 2}, 2, TENSR_FLOAT32, TENSR_CPU, data_b);
/* Matrix multiplication */
Tensor* c = tensr_matmul(a, b);
printf("Matrix multiplication result:\n");
tensr_print(c);
/* Transpose */
Tensor* at = tensr_transpose(a, NULL, 0);
printf("Transpose:\n");
tensr_print(at);
/* Identity matrix */
Tensor* eye = tensr_eye(3, TENSR_FLOAT32, TENSR_CPU);
Tensor* inv = tensr_inv(eye);
printf("Inverse of identity:\n");
tensr_print(inv);
/* Cleanup */
tensr_free(a);
tensr_free(b);
tensr_free(c);
tensr_free(at);
tensr_free(eye);
tensr_free(inv);
return 0;
}
GPU Acceleration
Linear algebra operations benefit greatly from GPU acceleration: