Numerical Tensor API
Complete reference for the numerical tensor operations API endpoint, including request formats, operations, and performance considerations.
Endpoint Overview
The Numerical Tensor API endpoint is designed for performing tensor operations with concrete numeric data. It leverages NumPy for efficient computation of numerical results. This endpoint is ideal for when you need to perform calculations with actual numbers rather than symbolic expressions.
All requests and responses use JSON format. The numerical API focuses on high-performance computation and is suitable for data processing, scientific computing, and machine learning applications.
Request Format
The JSON request to the numerical endpoint follows a similar structure to the symbolic endpoint, but with concrete numeric values instead of symbolic expressions. The core fields are:
Required Fields
operation
(string): The type of tensor operation to perform (e.g., "add", "multiply", "matmul", etc.)operands
(array): An array of tensor objects involved in the operation
Tensor Object Structure
name
(string, optional): A label for the tensor (e.g., "A", "B")shape
(array of integers): The dimensions of the tensor (e.g., [2, 2] for a 2×2 matrix)values
(nested array): The actual numeric data for the tensordtype
(string, optional): The data type of the numbers (e.g., "float64", "int32")
Optional Fields
options
(object): Additional parameters for specific operations (e.g., axis for reduction operations)
Supported Operations
The Numerical Tensor API supports a wide range of operations for numeric tensor manipulation. Here are the key operations:
add
Add two tensors of the same shape element-wise.
matmul
Perform matrix multiplication between compatible tensors.
contract
Contract indices of tensors, generalizing matrix multiplication to higher dimensions.
sum
Sum elements along a specified axis.
apply
Apply a function to each element of a tensor.
reshape
Change the shape of a tensor without changing its data.
zeros / ones
Create tensors filled with zeros or ones.
random
Create tensors with random values.
Response Format
The response from the numerical API will be a JSON object containing the result of the operation. The typical fields in the response include:
result
: The resulting tensor with its shape and numeric valuesoperation
: Echo of the operation that was performedelapsed_time
(optional): Performance information about how long the computation tookerror
(optional): Present only if an error occurred, with an explanation
Example Response
Error Handling
The API will perform validation on requests and return appropriate error responses for various conditions:
400 Bad Request
Returned when the request is invalid or missing required fields:
Shape Mismatch
Returned when tensor shapes are incompatible for the requested operation:
Data Type Issues
Returned when non-numeric data is found in values:
Computational Errors
Returned for operations that lead to mathematical errors:
Performance Considerations
When using the Numerical Tensor API, consider these performance optimization strategies:
Data Types
Choose appropriate data types for your tensors. Lower precision types (e.g., float32) consume less memory and may compute faster than higher precision types (e.g., float64), but with reduced numerical precision.
Tensor Size
Be mindful of tensor sizes. Very large tensors may lead to slower computations or memory errors. Break large operations into smaller chunks when possible.
Operation Chaining
When possible, combine multiple operations into a single API call to reduce network overhead. Sequential operations that must be sent as separate requests will be slower.
In-place Operations
Use in-place operations when available to modify tensors directly rather than creating new ones. This can save memory and reduce overhead.
Integration with Symbolic API
The Numerical and Symbolic APIs can be used together for a powerful hybrid approach:
- Derive expressions symbolically: Use the Symbolic API to create and simplify mathematical expressions with variables.
- Substitute values: Convert symbolic expressions to numerical ones by evaluating them with specific values.
- Compute numerically: Perform fast numerical computations on the resulting concrete tensors.