v2.0.0
Loading...
Searching...
No Matches
ml_tensor.cpp File Reference

Implementation of MLLIB::MlTensor including row-major/Eigen interop and shared-buffer reshape. More...

#include "ml_tensor.h"
#include <algorithm>
#include <cstring>
#include <numeric>
#include <stdexcept>
Include dependency graph for ml_tensor.cpp:

Go to the source code of this file.

Detailed Description

Implementation of MLLIB::MlTensor including row-major/Eigen interop and shared-buffer reshape.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors

Author
Christoph Dinh chris.nosp@m.toph.nosp@m..dinh.nosp@m.@mne.nosp@m.-cpp..nosp@m.org
Since
2.2.0
Date
April 2026

The translation unit keeps the storage rule in one place: every owning constructor allocates a std::shared_ptr<std::vector<float>> sized from the product of the shape, copies (or moves) the caller's buffer in, and points m_data at the shared vector. The static MLLIB::MlTensor::view factory bypasses that allocation and leaves m_storage null so MLLIB::MlTensor::isView can still distinguish the two cases later.

Eigen interop is handled with Eigen::Map: row-major maps over the tensor's own buffer for in-place access, and assignment from a column-major MatrixXf / MatrixXd transposes the layout in a single Eigen expression. MLLIB::MlTensor::reshape simply clones the shared_ptr and rewrites the shape vector, which is why any number of reshaped or sliced tensors can share one allocation without lifetime headaches.

Definition in file ml_tensor.cpp.