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>
Go to the source code of this file.
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
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.