In this section, an overview of the three fundamental NumXX types will be given. These are the building blocks used to create NumXX. The types in question are Shape, NArray and Matrix.
After reading this section, a more detailed documentation of each type can be explored via the links at the bottom of the page.
struct Shape {
std::vector<size_t> dimensions;
}
The Shape struct is a lightweight wrapper around std::vector<size_t> that stores the dimensional structure of numerical arrays. It determines how a contiguous memory block is interpreted and accessed as a multi-dimensional array.
Shape provides the metadata needed to interpret flat memory as multi-dimensional data. It handles dimension queries, stride calculations, and shape transformations (transpose, flatten, reshape) that are essential for array operations.
template <typename dtype = double>
class NArray {
std::shared_ptr<dtype> _data_ptr;
Shape _shape;
}
The NArray class is the primary container for N-dimensional arrays in NumXX. It combines shape information with actual data storage to provide a flexible, efficient array type similar to NumPy's ndarray.
NArray serves as the workhorse container for numerical computations. Its shared pointer design allows multiple NArrays to reference the same underlying data, enabling efficient slicing, views, and memory-safe operations without unnecessary copying. This makes operations like array slicing and reshaping both fast and memory-efficient.
template <typename dtype = double>
class Matrix final : public NArray<dtype> {
using NArray<dtype>::_data_ptr;
using NArray<dtype>::_shape;
}
The Matrix class is a specialized form of NArray that restricts dimensionality to a maximum of two dimensions. It inherits from NArray and adds matrix-specific functionality.
Matrix inherits the same member variables from NArray:
Matrix provides a type-safe interface for linear algebra operations. The key distinction from NArray is its multiplication behavior: the operator* performs matrix multiplication (matmul) rather than element-wise multiplication. This makes matrix algebra more intuitive and aligns with mathematical conventions. Despite being a specialized type, Matrix maintains full compatibility with NArray operations through inheritance.
For a more comprehensive API documentation, please navigate using the buttons below.