Arithmetic Operations
Element-wise Operations
add - Addition
sub - Subtraction
mul - Multiplication
div - Division
Mathematical Functions
pow - Power
sqrt - Square root
exp - Exponential
log - Natural logarithm
abs - Absolute value
neg - Negation
Trigonometric Functions
sin, cos, tan
arcsin, arccos, arctan
Comparison Operations
equal, not_equal
greater, less
Logical Operations
logical_and, logical_or, logical_not
Complete Example
#include <tensr/tensr.h>
#include <tensr/tensr_array.h>
int main() {
/* Create arrays */
float data_a[] = {1, 2, 3, 4};
float data_b[] = {2, 2, 2, 2};
size_t shape[] = {4};
Tensor* a = tensr_from_array(shape, 1, TENSR_FLOAT32, TENSR_CPU, data_a);
Tensor* b = tensr_from_array(shape, 1, TENSR_FLOAT32, TENSR_CPU, data_b);
/* Arithmetic */
Tensor* sum = tensr_add(a, b); /* [3, 4, 5, 6] */
Tensor* product = tensr_mul(a, b); /* [2, 4, 6, 8] */
Tensor* squared = tensr_pow(a, 2.0); /* [1, 4, 9, 16] */
/* Math functions */
Tensor* sqrt_a = tensr_sqrt(a);
Tensor* exp_a = tensr_exp(a);
/* Print results */
tensr_print(sum);
tensr_print(squared);
/* Cleanup */
tensr_free(a);
tensr_free(b);
tensr_free(sum);
tensr_free(product);
tensr_free(squared);
tensr_free(sqrt_a);
tensr_free(exp_a);
return 0;
}
Broadcasting
Operations automatically broadcast tensors of compatible shapes: