Made it so that i can use it for my other projects
Tiny, header-friendly tensor library with NumPy-compatible strides, zero dependencies at runtime, and 100 % test coverage via GoogleTest.
Feature | Status | Notes |
---|---|---|
Zero-copy creation | ✅ | Takes unique_ptr<float[]> – no extra memcpy |
Scalar → 8-D tensors | ✅ | MAX_RANK = 8 , shape {0} = 0-D scalar |
NumPy strides | ✅ | Row-major, calculated exactly like NumPy |
Element-wise ops | ✅ | + , - , * (shape must match, no broadcast yet) |
Bounds checking | ✅ | operator() throws std::out_of_range |
Factory helpers | ✅ | createZeros , createOnes , createScalar |
Alignment | ✅ | All data 64-byte aligned for SIMD / cache lines |
Modern CMake | ✅ | FetchContent pulls GoogleTest, sanitizers in Debug |
Compiler warnings | ✅ | -Wall -Wextra -Werror (GCC/Clang) and /W4 /WX (MSVC) |
UB & AddressSanitizer | ✅ | Auto-enabled in Debug builds |
Suite | Tests | Highlights |
---|---|---|
TensorTest (30) | Shape & stride correctness | 1-D … 8-D, shapes with ones, negative/overflow indices |
Element access | Flat index vs. multi-index equivalence | |
Memory safety | 64-byte alignment, move semantics, unique ownership | |
Performance | 1 000 000-element zero-init < 50 ms | |
TensorOpsTest (12) | Scalar & 2-D ops | + , - , * with exact element verification |
Error handling | Mismatched shapes throw invalid_argument |
|
IEEE-754 edge cases | inf - inf = nan , nan + x = nan |
|
Alias safety | t*t does not mutate original tensor |
All tests pass in 31 ms on a cold run (Release build).
git clone https://github.com/yourname/minitensor.git
cd minitensor
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure
or
mkdir build && cd build
cmake ..
make
Run any program you want