You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This namespace provides a Domain Specific Language (DSL) for batched tensor operations. These functions act as a routing layer: they take opaque involute::Tensor objects and translate the operation into highly optimized native calls for the active backend (MLX on Apple, oneMKL/SYCL on PC).
Usage Example
To initialize tensors and perform basic arithmetic using the Involute Math API, you can utilize the math::array and math::full functions for vector and scalar-based initialization. The following example demonstrates creating a 3-element vector tensor, a scalar tensor, and performing a fused operation with broadcasting:
#include<involute/core/math.hpp>
#include<vector>usingnamespaceinvolute::core;intmain() {
// 1. Initialize a tensor from a C++ vector (shape [3])
std::vector<float> vec_data = {1.0f, 2.0f, 3.0f};
Tensor vec_tensor = math::array(vec_data, {3}, DType::Float32);
// 2. Initialize a tensor from a scalar value (shape [1])
Tensor scalar_tensor = math::full({1}, 5.0f, DType::Float32);
// 3. Perform basic operations: (vec_tensor * scalar_tensor) + vec_tensor// Note: math::multiply and math::add support broadcasting
Tensor product = math::multiply(vec_tensor, scalar_tensor);
Tensor result = math::add(product, vec_tensor);
// Execute the computation and pull a value back to CPUmath::eval(result);
double first_val = math::to_double(math::slice(result, 0, 1));
}
1. Element-Wise Arithmetic
Function Signature
Description
Tensor add(const Tensor &a, const Tensor &b)
Element-wise addition of two tensors; supports broadcasting.
Expands the dimensions of a tensor. Essential for broadcasting (e.g., expanding a [N] tensor of norms to [N, 1, 1] to scale a batch of [N, d, d] matrices).
Batched Singular Value Decomposition (SVD). Returns a tuple of 3 tensors: {U, S, V_transpose}. Required for projecting the ambient Fréchet mean back onto the $SO(d)$ manifold.
std::tuple<Tensor, Tensor> qr(const Tensor &a)
Batched QR Decomposition. Returns a tuple of 2 tensors: {Q, R}. The Q matrix represents the direct chordal projection of an ambient matrix onto the orthogonal group in a single, non-iterative pass.
Tensor det(const Tensor &a)
Computes the determinant of a square matrix or a batch of square matrices. Returns a tensor containing the determinant(s).
Tensor inv(const Tensor &a)
Computes the explicit matrix inverse. Prefer solve for systems of equations.
Tensor trace(const Tensor &a)
Computes the sum of diagonal elements (the trace) of a matrix.
Generates a tensor filled with uniform random values in $[0, 1)$.
7. CPU-GPU Bridge
Warning: Operations that move data to the CPU inherently block the execution pipeline and trigger synchronization events.
Function Signature
Description
double to_double(const Tensor &a)
Pulls a scalar 0D or 1D tensor back to the CPU as a standard C++ double. This triggers a synchronization event. Use sparingly (e.g., once per step for checking convergence).