cpptensor/Tensors & views
Tensors & views
The cpptensor Tensor type — dtypes, views, broadcasting, and contiguous materialization.
Tensor is an N-dimensional array with explicit support for views and
contiguous materialization. Operations may return zero-copy views; you can
materialize a dense, contiguous copy when you need one.
Creating tensors
using namespace cpptensor;
Tensor z = Tensor::zeros({2, 3});
Tensor o = Tensor::ones({2, 3});
Tensor f = Tensor::full({2, 2}, 1.0f);
Tensor r = Tensor::randn({4, 4});Dtypes
Each tensor tracks element dtype metadata: bool, int32, float32, and
float64. Dtype is preserved across views, clone / contiguous, and factory
creation. Comparison operators produce bool tensors.
Views vs. copies
Many shape operations return a view that shares storage with the source. Reshape, transpose, concat, and stack are available; materialize a contiguous copy when a dense layout is required.
Broadcasting
cpptensor exposes explicit broadcasting helpers:
| API | Semantics |
|---|---|
expand(shape) / broadcast_to(shape) | Zero-copy broadcast view — size-1 dimensions become stride-0. |
repeat(repeats) | Materializes tiled data (copy semantics). |
Tensor a = Tensor::full({1, 3}, 1.0f);
Tensor b = a.broadcast_to({4, 3}); // view, no copy
Tensor c = a.repeat({4, 1}); // materialized copyNext
- See the full op catalog in Operations.
- Learn how kernels are selected in Backends & ISA.