| Crates.io | tenflowers-core |
| lib.rs | tenflowers-core |
| version | 0.1.0-alpha.2 |
| created_at | 2025-09-27 18:56:56.405878+00 |
| updated_at | 2025-12-23 05:50:33.132291+00 |
| description | Core tensor operations and execution engine for TenfloweRS |
| homepage | https://github.com/cool-japan/tenflowers |
| repository | https://github.com/cool-japan/tenflowers |
| max_upload_size | |
| id | 1857540 |
| size | 6,837,024 |
The foundational crate of TenfloweRS, providing core tensor operations, device management, and the computational infrastructure for machine learning in Rust.
Alpha Release (0.1.0-alpha.1 ยท 2025-09-27) This crate participates in the first public alpha. Expect API refinements and additional safety/shape checks before 0.1.0 stable. Pin the exact pre-release version if used in downstream experiments.
tenflowers-core implements:
f32, f64, i32, i64, u8, and moreuse tenflowers_core::{Tensor, Device, DType};
// Create tensors
let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2], Device::Cpu)?;
let b = Tensor::ones(&[2, 2], DType::F32, Device::Cpu)?;
// Arithmetic operations
let c = &a + &b; // Element-wise addition
let d = a.matmul(&b)?; // Matrix multiplication
// Reductions
let sum = c.sum(None)?; // Sum all elements
let mean = c.mean(Some(&[0]))?; // Mean along axis 0
#[cfg(feature = "gpu")]
{
let gpu_device = Device::Gpu(0);
let a_gpu = a.to_device(&gpu_device)?;
let b_gpu = b.to_device(&gpu_device)?;
// Operations automatically dispatch to GPU kernels
let c_gpu = a_gpu.matmul(&b_gpu)?;
// Transfer back to CPU if needed
let c_cpu = c_gpu.to_device(&Device::Cpu)?;
}
use tenflowers_core::{Graph, Session};
// Build a computation graph
let mut graph = Graph::new();
let x = graph.placeholder("x", DType::F32, Some(&[None, 784]));
let w = graph.variable("w", Tensor::randn(&[784, 10], DType::F32, Device::Cpu)?);
let b = graph.variable("b", Tensor::zeros(&[10], DType::F32, Device::Cpu)?);
let logits = graph.matmul(&x, &w)?;
let output = graph.add(&logits, &b)?;
// Execute with session
let mut session = Session::new(&graph);
let result = session.run(
&[output],
&[("x", input_tensor)],
)?;
This crate is designed to work seamlessly with the broader Rust scientific computing ecosystem:
use numrs2::array::Array2;
use tenflowers_core::Tensor;
// Convert from NumRS2 arrays
let array = Array2::from_shape_vec((3, 3), vec![1.0; 9])?;
let tensor = Tensor::from_numrs2(array, Device::Cpu)?;
// Convert to NumRS2 arrays
let array_back: Array2<f32> = tensor.to_numrs2()?;
gpu: Enable GPU support via WGPU (default: disabled)blas-openblas: Use OpenBLAS for accelerated linear algebrablas-mkl: Use Intel MKL for accelerated linear algebrablas-accelerate: Use Apple Accelerate framework (macOS)f16: Enable half-precision floating point supportserialize: Enable serialization support via serdeCore dependencies:
ndarray: CPU tensor storage and operationsnum-traits: Numeric trait boundsrayon: Parallel CPU operationswgpu (optional): GPU compute supportndarray-linalg (optional): BLAS/LAPACK integrationContributions are welcome! Priority areas:
Dual-licensed under MIT OR Apache-2.0