Expand description
C-API (FFI) for tropical semiring tensor operations.
Extends [tenferro_capi] with tropical einsum functions for three
semirings: MaxPlus (⊕=max, ⊗=+), MinPlus (⊕=min, ⊗=+), and
MaxMul (⊕=max, ⊗=×).
§Design
- Reuses [
TfeTensorF64] handles fromtenferro-capi. SinceMaxPlus<f64>is#[repr(transparent)], it has the same memory layout asf64. Tropical functions accept f64 tensor handles, internally wrap data asMaxPlus<f64>(orMinPlus/MaxMul), perform the tropical einsum, and unwrap the result back to f64. - No new handle type — the algebra is selected by the function name, not the tensor type.
- Naming convention:
tfe_tropical_einsum_<algebra>_f64.
§Linking
This crate produces a separate shared library from tenferro-capi.
C/Julia/Python consumers load both:
// Core tensor operations
tfe_tensor_f64 *t = tfe_tensor_f64_from_data(...);
// Tropical einsum (from tenferro-tropical-capi)
const tfe_tensor_f64 *ops[] = {a, b};
tfe_tensor_f64 *c = tfe_tropical_einsum_maxplus_f64("ij,jk->ik", ops, 2, &status);§Example (C pseudocode)
#include "tenferro.h"
#include "tenferro_tropical.h"
tfe_status_t status;
size_t shape[] = {3, 4};
double data_a[12] = { /* ... */ };
double data_b[12] = { /* ... */ };
tfe_tensor_f64 *a = tfe_tensor_f64_from_data(data_a, 12, shape, 2, &status);
tfe_tensor_f64 *b = tfe_tensor_f64_from_data(data_b, 12, shape, 2, &status);
// MaxPlus tropical einsum: C[i,k] = max_j (A[i,j] + B[j,k])
const tfe_tensor_f64 *ops[] = {a, b};
tfe_tensor_f64 *c = tfe_tropical_einsum_maxplus_f64("ij,jk->ik", ops, 2, &status);
assert(status == TFE_SUCCESS);
tfe_tensor_f64_release(c);
tfe_tensor_f64_release(b);
tfe_tensor_f64_release(a);Functions§
- tfe_
tropical_ ⚠einsum_ frule_ maxmul_ f64 - Forward-mode rule (JVP) for MaxMul tropical einsum.
- tfe_
tropical_ ⚠einsum_ frule_ maxplus_ f64 - Forward-mode rule (JVP) for MaxPlus tropical einsum.
- tfe_
tropical_ ⚠einsum_ frule_ minplus_ f64 - Forward-mode rule (JVP) for MinPlus tropical einsum.
- tfe_
tropical_ ⚠einsum_ maxmul_ f64 - Execute tropical einsum under MaxMul algebra (⊕=max, ⊗=×).
- tfe_
tropical_ ⚠einsum_ maxplus_ f64 - Execute tropical einsum under MaxPlus algebra (⊕=max, ⊗=+).
- tfe_
tropical_ ⚠einsum_ minplus_ f64 - Execute tropical einsum under MinPlus algebra (⊕=min, ⊗=+).
- tfe_
tropical_ ⚠einsum_ rrule_ maxmul_ f64 - Reverse-mode rule (VJP) for MaxMul tropical einsum.
- tfe_
tropical_ ⚠einsum_ rrule_ maxplus_ f64 - Reverse-mode rule (VJP) for MaxPlus tropical einsum.
- tfe_
tropical_ ⚠einsum_ rrule_ minplus_ f64 - Reverse-mode rule (VJP) for MinPlus tropical einsum.