Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
clustering::NDArray< T, N, L > Class Template Reference

Represents a multidimensional array (NDArray) of a fixed number of dimensions N and element type T. More...

#include <clustering/ndarray.h>

Classes

class  BaseAccessor
 Inner class providing base functionality for element access in NDArray. More...
class  ConstAccessor
 Provides read-only access to NDArray elements. More...
class  Accessor
 Provides read-write access to NDArray elements. More...

Public Member Functions

template<Layout L2 = L>
 NDArray (std::initializer_list< std::size_t > dims)
 Constructs a contiguous owned NDArray with specified dimensions.
template<Layout L2 = L>
 NDArray (std::array< std::size_t, N > shape)
 Constructs a contiguous owned NDArray from a runtime std::array of dimensions.
 NDArray (const NDArray &other)
 Copy constructor; re-seats m_data against m_vec for owned storage.
 NDArray (NDArray &&other) noexcept
 Move constructor; steals m_vec and re-seats m_data for owned storage.
NDArrayoperator= (const NDArray &other)
 Copy assignment; re-seats m_data against m_vec for owned storage.
NDArrayoperator= (NDArray &&other) noexcept
 Move assignment; steals m_vec and re-seats m_data for owned storage.
template<Layout L2 = L>
Accessor operator[] (std::size_t index) noexcept
 Provides access to the elements of the NDArray.
template<Layout L2 = L>
ConstAccessor operator[] (std::size_t index) const noexcept
 Provides read-only access to the elements of the NDArray.
template<class... Ix>
T & operator() (Ix... ix) noexcept
 Direct multi-index element access via strides.
template<class... Ix>
const T & operator() (Ix... ix) const noexcept
 Read-only multi-index element access via strides; mirrors the mutable overload.
T & flatIndex (std::size_t index) noexcept
 Provides direct access to the flat underlying array at a specific index.
const T & flatIndex (std::size_t index) const noexcept
 Provides read-only access to the flat underlying array at a specific index.
size_t dim (std::size_t index) const noexcept
 Returns the size of a specific dimension of the NDArray.
std::ptrdiff_t strideAt (std::size_t index) const noexcept
 Returns the stride (in elements) for dimension index.
bool isContiguous () const noexcept
 Reports whether the array's runtime layout is row-major contiguous with zero offset.
bool isMutable () const noexcept
 Reports whether writes through operator(), Accessor, or flatIndex are allowed.
bool isOwned () const noexcept
 Reports whether the array owns its underlying buffer.
const T * data () const noexcept
 Provides read-only access to the internal data array.
T * data () noexcept
 Provides read-write access to the internal data array.
T * baseData () const noexcept
 Returns the original (non-advanced) base pointer for storage-identity comparisons.
template<std::size_t A>
bool isAligned () const noexcept
 Tests whether data() is aligned to A bytes.
template<std::size_t A>
T * alignedData () noexcept
 Returns data() with an alignment hint of A bytes applied.
template<std::size_t A>
const T * alignedData () const noexcept
 Read-only overload of alignedData<A>; attaches the same alignment hint to the pointer.
template<std::size_t M = N>
NDArray< T, 2, Layout::MaybeStridedt () noexcept
 Transposes a rank-2 NDArray into a borrowed view with swapped axes.
template<std::size_t M = N>
NDArray< T, 2, Layout::MaybeStridedt () const noexcept
 Read-only transpose; the returned view carries m_mutable = false.
template<std::size_t M = N>
NDArray< T, N - 1, L > row (std::size_t i) noexcept
 Returns a borrowed view of row i with the leading dimension dropped.
template<std::size_t M = N>
NDArray< T, N - 1, L > row (std::size_t i) const noexcept
 Read-only row view; mirrors the mutable overload and flips m_mutable off.
template<std::size_t M = N>
NDArray< T, 1, Layout::MaybeStridedcol (std::size_t j) noexcept
 Returns a borrowed rank-1 view of column j of a rank-2 array.
template<std::size_t M = N>
NDArray< T, 1, Layout::MaybeStridedcol (std::size_t j) const noexcept
 Read-only column view; mirrors the mutable overload and flips m_mutable off.
NDArray< T, N, Layout::MaybeStridedslice (std::size_t axis, std::size_t begin, std::size_t end) noexcept
 Borrowed half-open slice along a single axis.
NDArray< T, N, Layout::MaybeStridedslice (std::size_t axis, std::size_t begin, std::size_t end) const noexcept
 Read-only single-axis slice; mirrors the mutable overload with m_mutable = false.
NDArray< T, N, Layout::MaybeStridedslice (const std::array< Range, N > &ranges) noexcept
 Borrowed multi-axis slice; each Range applies to its corresponding axis.
NDArray< T, N, Layout::MaybeStridedslice (const std::array< Range, N > &ranges) const noexcept
 Read-only multi-axis slice; mirrors the mutable overload with m_mutable = false.
NDArray< T, N, Layout::MaybeStridedpermute (const std::array< std::size_t, N > &perm) noexcept
 Borrowed view with axes reordered by perm.
NDArray< T, N, Layout::MaybeStridedpermute (const std::array< std::size_t, N > &perm) const noexcept
 Read-only permuted view; mirrors the mutable overload with m_mutable = false.
template<std::size_t M>
NDArray< T, M, Layout::Contigview (std::array< std::size_t, M > shape) noexcept
 Returns a borrowed contiguous rank-M view over the same buffer with shape shape.
template<std::size_t M>
NDArray< T, M, Layout::Contigview (std::array< std::size_t, M > shape) const noexcept
 Read-only rank-M view; mirrors the mutable overload with m_mutable = false.
template<std::size_t M>
NDArray< T, M, Layout::Contigreshape (std::array< std::size_t, M > shape)
 Returns a contiguous rank-M array with shape shape, copying only when needed.
template<std::size_t M>
NDArray< T, M, Layout::Contigreshape (std::array< std::size_t, M > shape) const
 Read-only rank-M reshape; aliases on contiguous sources, copies otherwise.
NDArray< T, N, Layout::Contigcontiguous ()
 Returns a contiguous rank-N array with the same shape, copying only when needed.
NDArray< T, N, Layout::Contigcontiguous () const
 Read-only contiguous view; aliases on contiguous sources, copies otherwise.
NDArray< T, N, Layout::Contigclone () const
 Returns a freshly-allocated owned contiguous array with deep-copied contents.
std::string debugDump () const
 Returns a formatted string representing the contents of the NDArray.

Static Public Member Functions

template<Layout L2 = L>
static NDArray borrow (T *ptr, std::array< std::size_t, N > shape) noexcept
 Borrows a contiguous buffer as an NDArray without taking ownership.
template<Layout L2 = L>
static NDArray borrow (const T *ptr, std::array< std::size_t, N > shape) noexcept
 Borrows a read-only contiguous buffer as an NDArray.
template<Layout L2 = L>
static NDArray borrow (T *ptr, std::array< std::size_t, N > shape, std::array< std::ptrdiff_t, N > strides) noexcept
 Borrows a strided buffer as an NDArray without taking ownership.
template<Layout L2 = L>
static NDArray borrow (const T *ptr, std::array< std::size_t, N > shape, std::array< std::ptrdiff_t, N > strides) noexcept
 Read-only strided borrow; flips m_mutable off so writes through the view assert.
template<std::size_t M = N>
static NDArray borrow1D (T *ptr, std::size_t n) noexcept
 Rank-1 convenience borrow; avoids the std::array<size_t, 1>{n} boilerplate.
template<std::size_t M = N>
static NDArray borrow1D (const T *ptr, std::size_t n) noexcept
 Read-only rank-1 convenience borrow; mirrors the mutable borrow1D.
template<Layout L2 = L>
static NDArray borrowBytes (T *ptr, std::array< std::size_t, N > shape, std::array< std::ptrdiff_t, N > stridesInBytes, bool isMutable) noexcept
 Borrow a buffer whose strides are expressed in bytes (NumPy's convention).
template<std::size_t M = N>
static NDArray fromSpan (std::span< T > s) noexcept
 Explicit std::span adapter for rank-1 borrows.
template<std::size_t M = N>
static NDArray fromSpan (std::span< const T > s) noexcept
 Read-only span adapter; delegates to the read-only borrow overload.

Friends

template<class U, std::size_t M, Layout LL>
class NDArray
bool operator== (const NDArray &, const NDArray &)=delete
bool operator!= (const NDArray &, const NDArray &)=delete

Detailed Description

template<class T, std::size_t N, Layout L = Layout::Contig>
class clustering::NDArray< T, N, L >

Represents a multidimensional array (NDArray) of a fixed number of dimensions N and element type T.

NDArray is a template class that provides a high-level representation of a multi-dimensional array. It offers element access, dimension information, and debug utilities. The array's dimensions are defined at compile time for type safety and efficiency.

Template Parameters
TThe type of elements stored in the NDArray.
NThe number of dimensions of the NDArray.
LLayout tag; Layout::Contig (default) enables the operator[] chain.

Definition at line 136 of file ndarray.h.

Constructor & Destructor Documentation

◆ NDArray() [1/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
clustering::NDArray< T, N, L >::NDArray ( std::initializer_list< std::size_t > dims)
inline

Constructs a contiguous owned NDArray with specified dimensions.

Only available for Layout::Contig; the MaybeStrided instantiation has no default constructor and is produced exclusively by strided-view factory methods.

Parameters
dimsInitializer list specifying the dimensions of the NDArray.

Definition at line 281 of file ndarray.h.

◆ NDArray() [2/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
clustering::NDArray< T, N, L >::NDArray ( std::array< std::size_t, N > shape)
inlineexplicit

Constructs a contiguous owned NDArray from a runtime std::array of dimensions.

Mirrors the initializer-list constructor but accepts a shape already materialized as a std::array, the form consumed by reshape, contiguous, and clone when they need to allocate a fresh buffer.

Parameters
shapeDimensions of the NDArray, one entry per axis.

Definition at line 308 of file ndarray.h.

◆ NDArray() [3/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
clustering::NDArray< T, N, L >::NDArray ( const NDArray< T, N, L > & other)
inline

Copy constructor; re-seats m_data against m_vec for owned storage.

Definition at line 325 of file ndarray.h.

◆ NDArray() [4/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
clustering::NDArray< T, N, L >::NDArray ( NDArray< T, N, L > && other)
inlinenoexcept

Move constructor; steals m_vec and re-seats m_data for owned storage.

Definition at line 333 of file ndarray.h.

Member Function Documentation

◆ alignedData() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t A>
const T * clustering::NDArray< T, N, L >::alignedData ( ) const
inlinenoexcept

Read-only overload of alignedData<A>; attaches the same alignment hint to the pointer.

Definition at line 554 of file ndarray.h.

◆ alignedData() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t A>
T * clustering::NDArray< T, N, L >::alignedData ( )
inlinenoexcept

Returns data() with an alignment hint of A bytes applied.

Calls __builtin_assume_aligned so downstream SIMD intrinsics (e.g. _mm256_load_ps) can assume an A -byte aligned pointer and emit aligned-load instructions under -O2. The debug assert guards against feeding an unaligned borrow into this path.

Template Parameters
ARequired alignment in bytes.
Returns
Aligned pointer into the buffer. Writes through the mutable overload on a read-only borrow are undefined; the caller is responsible for honoring the const contract.

Definition at line 548 of file ndarray.h.

◆ baseData()

template<class T, std::size_t N, Layout L = Layout::Contig>
T * clustering::NDArray< T, N, L >::baseData ( ) const
inlinenodiscardnoexcept

Returns the original (non-advanced) base pointer for storage-identity comparisons.

All view verbs propagate the source's base pointer unchanged; only a fresh owned allocation (or the clone / non-contiguous reshape paths) installs a new base. sameStorage uses this to decide whether two arrays share the underlying buffer.

Definition at line 525 of file ndarray.h.

◆ borrow() [1/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
NDArray clustering::NDArray< T, N, L >::borrow ( const T * ptr,
std::array< std::size_t, N > shape )
inlinestaticnoexcept

Borrows a read-only contiguous buffer as an NDArray.

Stores the caller's const T* as T* via const_cast and flips m_mutable off so any write through operator() or Accessor asserts in debug.

Definition at line 583 of file ndarray.h.

◆ borrow() [2/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
NDArray clustering::NDArray< T, N, L >::borrow ( const T * ptr,
std::array< std::size_t, N > shape,
std::array< std::ptrdiff_t, N > strides )
inlinestaticnoexcept

Read-only strided borrow; flips m_mutable off so writes through the view assert.

Definition at line 605 of file ndarray.h.

◆ borrow() [3/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
NDArray clustering::NDArray< T, N, L >::borrow ( T * ptr,
std::array< std::size_t, N > shape )
inlinestaticnoexcept

Borrows a contiguous buffer as an NDArray without taking ownership.

Available only when L == Layout::Contig. The returned array shares the caller's buffer, carries contiguous strides, and is writable through operator() and Accessor.

Parameters
ptrNon-owning pointer to the first element. Must stay alive for the view's lifetime.
shapeDimensions, one entry per axis.

Definition at line 570 of file ndarray.h.

◆ borrow() [4/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
NDArray clustering::NDArray< T, N, L >::borrow ( T * ptr,
std::array< std::size_t, N > shape,
std::array< std::ptrdiff_t, N > strides )
inlinestaticnoexcept

Borrows a strided buffer as an NDArray without taking ownership.

Available only when L == Layout::MaybeStrided. Strides are in elements, not bytes; see borrowBytes for the byte-stride entry point used at the Python binding boundary.

Definition at line 597 of file ndarray.h.

◆ borrow1D() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray clustering::NDArray< T, N, L >::borrow1D ( const T * ptr,
std::size_t n )
inlinestaticnoexcept

Read-only rank-1 convenience borrow; mirrors the mutable borrow1D.

Definition at line 623 of file ndarray.h.

◆ borrow1D() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray clustering::NDArray< T, N, L >::borrow1D ( T * ptr,
std::size_t n )
inlinestaticnoexcept

Rank-1 convenience borrow; avoids the std::array<size_t, 1>{n} boilerplate.

Definition at line 616 of file ndarray.h.

◆ borrowBytes()

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
NDArray clustering::NDArray< T, N, L >::borrowBytes ( T * ptr,
std::array< std::size_t, N > shape,
std::array< std::ptrdiff_t, N > stridesInBytes,
bool isMutable )
inlinestaticnoexcept

Borrow a buffer whose strides are expressed in bytes (NumPy's convention).

Byte strides are divided by sizeof(T) to recover element strides; non-divisible entries are undefined and asserted in debug. The result always carries Layout::MaybeStrided so arbitrary byte strides can be represented without a runtime contiguity check gating the Contig type-level invariant.

Parameters
ptrNon-owning pointer to the first element.
shapeDimensions, one entry per axis.
stridesInBytesByte offset between successive elements along each axis.
isMutableWhether writes through the view are permitted.

Definition at line 642 of file ndarray.h.

◆ clone()

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::Contig > clustering::NDArray< T, N, L >::clone ( ) const
inline

Returns a freshly-allocated owned contiguous array with deep-copied contents.

Always allocates; unlike contiguous, never aliases the source buffer. Equivalent to NumPy's ndarray.copy: the caller receives an independent owner with matching values and row-major layout.

Definition at line 977 of file ndarray.h.

◆ col() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray< T, 1, Layout::MaybeStrided > clustering::NDArray< T, N, L >::col ( std::size_t j) const
inlinenoexcept

Read-only column view; mirrors the mutable overload and flips m_mutable off.

Definition at line 758 of file ndarray.h.

◆ col() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray< T, 1, Layout::MaybeStrided > clustering::NDArray< T, N, L >::col ( std::size_t j)
inlinenoexcept

Returns a borrowed rank-1 view of column j of a rank-2 array.

Always MaybeStrided: column stride equals the row stride of the source, which is not 1 for any row-major source with more than one column.

Definition at line 746 of file ndarray.h.

◆ contiguous() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::Contig > clustering::NDArray< T, N, L >::contiguous ( )
inline

Returns a contiguous rank-N array with the same shape, copying only when needed.

Already-contiguous sources are aliased into a borrowed view sharing storage; strided sources allocate a dense owned copy. The return type drops the MaybeStrided tag so downstream hot paths can resume the operator[] chain.

Definition at line 947 of file ndarray.h.

◆ contiguous() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::Contig > clustering::NDArray< T, N, L >::contiguous ( ) const
inline

Read-only contiguous view; aliases on contiguous sources, copies otherwise.

Definition at line 959 of file ndarray.h.

◆ data() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
const T * clustering::NDArray< T, N, L >::data ( ) const
inlinenoexcept

Provides read-only access to the internal data array.

Returns
Constant pointer to the data array.

Definition at line 503 of file ndarray.h.

◆ data() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
T * clustering::NDArray< T, N, L >::data ( )
inlinenoexcept

Provides read-write access to the internal data array.

Asserts in debug that the array is mutable: a raw pointer grabbed from a read-only borrow would otherwise corrupt the source buffer without tripping any other write-path guard.

Returns
Pointer to the data array.

Definition at line 513 of file ndarray.h.

◆ debugDump()

template<class T, std::size_t N, Layout L = Layout::Contig>
std::string clustering::NDArray< T, N, L >::debugDump ( ) const
inline

Returns a formatted string representing the contents of the NDArray.

This method is primarily used for debugging purposes, providing a visual representation of the array's structure and contents. Walks the array through m_data, m_offset, and m_strides so Borrowed views report their actual viewable contents rather than the empty m_vec.

Returns
A string containing the formatted representation of the NDArray.

Definition at line 993 of file ndarray.h.

◆ dim()

template<class T, std::size_t N, Layout L = Layout::Contig>
size_t clustering::NDArray< T, N, L >::dim ( std::size_t index) const
inlinenoexcept

Returns the size of a specific dimension of the NDArray.

Parameters
indexIndex of the dimension.
Returns
Size of the specified dimension as a size_t.

Definition at line 461 of file ndarray.h.

◆ flatIndex() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
const T & clustering::NDArray< T, N, L >::flatIndex ( std::size_t index) const
inlinenoexcept

Provides read-only access to the flat underlying array at a specific index.

Parameters
indexIndex in the flat representation of the NDArray.
Returns
Constant reference to the element at the specified index.

Definition at line 453 of file ndarray.h.

◆ flatIndex() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
T & clustering::NDArray< T, N, L >::flatIndex ( std::size_t index)
inlinenoexcept

Provides direct access to the flat underlying array at a specific index.

Parameters
indexIndex in the flat representation of the NDArray.
Returns
Reference to the element at the specified index.

Definition at line 442 of file ndarray.h.

◆ fromSpan() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray clustering::NDArray< T, N, L >::fromSpan ( std::span< const T > s)
inlinestaticnoexcept

Read-only span adapter; delegates to the read-only borrow overload.

Definition at line 670 of file ndarray.h.

◆ fromSpan() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray clustering::NDArray< T, N, L >::fromSpan ( std::span< T > s)
inlinestaticnoexcept

Explicit std::span adapter for rank-1 borrows.

No implicit std::span conversion is provided; callers spell fromSpan to avoid overload-resolution ambiguity with the raw-pointer borrow overloads.

Definition at line 663 of file ndarray.h.

◆ isAligned()

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t A>
bool clustering::NDArray< T, N, L >::isAligned ( ) const
inlinenoexcept

Tests whether data() is aligned to A bytes.

Template Parameters
AAlignment to test in bytes.
Returns
True when data() is a null pointer or an A -byte boundary.

Definition at line 533 of file ndarray.h.

◆ isContiguous()

template<class T, std::size_t N, Layout L = Layout::Contig>
bool clustering::NDArray< T, N, L >::isContiguous ( ) const
inlinenodiscardnoexcept

Reports whether the array's runtime layout is row-major contiguous with zero offset.

For Layout::Contig arrays this is always true (the type encodes the guarantee). For Layout::MaybeStrided arrays the answer is computed from m_strides and m_offset.

Definition at line 474 of file ndarray.h.

◆ isMutable()

template<class T, std::size_t N, Layout L = Layout::Contig>
bool clustering::NDArray< T, N, L >::isMutable ( ) const
inlinenodiscardnoexcept

Reports whether writes through operator(), Accessor, or flatIndex are allowed.

Owned arrays are always mutable. Borrowed arrays carry the flag supplied at borrow time: borrow(const T*, ...) flips it off, borrow(T*, ...) leaves it on.

Definition at line 488 of file ndarray.h.

◆ isOwned()

template<class T, std::size_t N, Layout L = Layout::Contig>
bool clustering::NDArray< T, N, L >::isOwned ( ) const
inlinenodiscardnoexcept

Reports whether the array owns its underlying buffer.

Owned arrays hold their storage in m_vec; Borrowed arrays reference an external buffer whose lifetime is the caller's responsibility.

Definition at line 496 of file ndarray.h.

◆ operator()() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<class... Ix>
const T & clustering::NDArray< T, N, L >::operator() ( Ix... ix) const
inlinenoexcept

Read-only multi-index element access via strides; mirrors the mutable overload.

Definition at line 431 of file ndarray.h.

◆ operator()() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<class... Ix>
T & clustering::NDArray< T, N, L >::operator() ( Ix... ix)
inlinenoexcept

Direct multi-index element access via strides.

Available for all layouts.

Template Parameters
IxIntegral index pack, must have exactly N elements.
Parameters
ixIndices, one per dimension.
Returns
Reference to the element at m_offset + sum_k ix_k * m_strides[k].

Definition at line 424 of file ndarray.h.

◆ operator=() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray & clustering::NDArray< T, N, L >::operator= ( const NDArray< T, N, L > & other)
inline

Copy assignment; re-seats m_data against m_vec for owned storage.

Definition at line 343 of file ndarray.h.

◆ operator=() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray & clustering::NDArray< T, N, L >::operator= ( NDArray< T, N, L > && other)
inlinenoexcept

Move assignment; steals m_vec and re-seats m_data for owned storage.

Definition at line 359 of file ndarray.h.

◆ operator[]() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
ConstAccessor clustering::NDArray< T, N, L >::operator[] ( std::size_t index) const
inlinenoexcept

Provides read-only access to the elements of the NDArray.

Parameters
indexIndex in the first dimension.
Returns
A ConstAccessor to the specified index in the first dimension.

Definition at line 412 of file ndarray.h.

◆ operator[]() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<Layout L2 = L>
Accessor clustering::NDArray< T, N, L >::operator[] ( std::size_t index)
inlinenoexcept

Provides access to the elements of the NDArray.

Only defined for Layout::Contig. A MaybeStrided array has no operator[]; use the variadic operator()(i, j, ...) to read through strides.

Parameters
indexIndex in the first dimension.
Returns
An Accessor to the specified index in the first dimension.

Definition at line 399 of file ndarray.h.

◆ permute() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::MaybeStrided > clustering::NDArray< T, N, L >::permute ( const std::array< std::size_t, N > & perm) const
inlinenoexcept

Read-only permuted view; mirrors the mutable overload with m_mutable = false.

Definition at line 862 of file ndarray.h.

◆ permute() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::MaybeStrided > clustering::NDArray< T, N, L >::permute ( const std::array< std::size_t, N > & perm)
inlinenoexcept

Borrowed view with axes reordered by perm.

perm must be a valid permutation of {0, ..., N-1}; validation is an assert in debug.

Definition at line 848 of file ndarray.h.

◆ reshape() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M>
NDArray< T, M, Layout::Contig > clustering::NDArray< T, N, L >::reshape ( std::array< std::size_t, M > shape)
inline

Returns a contiguous rank-M array with shape shape, copying only when needed.

Aliases the existing buffer when the source is runtime-contiguous; allocates an owned dense copy otherwise. Callers that require no-hidden-allocation guarantees should use view instead, which asserts on non-contiguous input without the allocation fallback.

Template Parameters
MTarget rank. May differ from N.
Parameters
shapeDimensions of the result, one entry per axis.

Definition at line 914 of file ndarray.h.

◆ reshape() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M>
NDArray< T, M, Layout::Contig > clustering::NDArray< T, N, L >::reshape ( std::array< std::size_t, M > shape) const
inline

Read-only rank-M reshape; aliases on contiguous sources, copies otherwise.

Definition at line 928 of file ndarray.h.

◆ row() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray< T, N - 1, L > clustering::NDArray< T, N, L >::row ( std::size_t i) const
inlinenoexcept

Read-only row view; mirrors the mutable overload and flips m_mutable off.

Definition at line 724 of file ndarray.h.

◆ row() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray< T, N - 1, L > clustering::NDArray< T, N, L >::row ( std::size_t i)
inlinenoexcept

Returns a borrowed view of row i with the leading dimension dropped.

Layout is preserved: a row of a Contig array is still Contig because the inner strides remain the contiguous layout for the reduced shape.

Definition at line 708 of file ndarray.h.

◆ slice() [1/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::MaybeStrided > clustering::NDArray< T, N, L >::slice ( const std::array< Range, N > & ranges) const
inlinenoexcept

Read-only multi-axis slice; mirrors the mutable overload with m_mutable = false.

Definition at line 823 of file ndarray.h.

◆ slice() [2/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::MaybeStrided > clustering::NDArray< T, N, L >::slice ( const std::array< Range, N > & ranges)
inlinenoexcept

Borrowed multi-axis slice; each Range applies to its corresponding axis.

Step must be positive (no reversed views in v1). end defaults to the axis size via the sentinel Range::all().

Definition at line 802 of file ndarray.h.

◆ slice() [3/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::MaybeStrided > clustering::NDArray< T, N, L >::slice ( std::size_t axis,
std::size_t begin,
std::size_t end ) const
inlinenoexcept

Read-only single-axis slice; mirrors the mutable overload with m_mutable = false.

Definition at line 785 of file ndarray.h.

◆ slice() [4/4]

template<class T, std::size_t N, Layout L = Layout::Contig>
NDArray< T, N, Layout::MaybeStrided > clustering::NDArray< T, N, L >::slice ( std::size_t axis,
std::size_t begin,
std::size_t end )
inlinenoexcept

Borrowed half-open slice along a single axis.

Returned view always carries MaybeStrided; callers that need the Contig guarantee back (e.g. axis-0 slice of a contiguous source) can round-trip through contiguous().

Definition at line 773 of file ndarray.h.

◆ strideAt()

template<class T, std::size_t N, Layout L = Layout::Contig>
std::ptrdiff_t clustering::NDArray< T, N, L >::strideAt ( std::size_t index) const
inlinenoexcept

Returns the stride (in elements) for dimension index.

Definition at line 466 of file ndarray.h.

◆ t() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray< T, 2, Layout::MaybeStrided > clustering::NDArray< T, N, L >::t ( ) const
inlinenoexcept

Read-only transpose; the returned view carries m_mutable = false.

Definition at line 693 of file ndarray.h.

◆ t() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M = N>
NDArray< T, 2, Layout::MaybeStrided > clustering::NDArray< T, N, L >::t ( )
inlinenoexcept

Transposes a rank-2 NDArray into a borrowed view with swapped axes.

The returned view reuses the source buffer; sameStorage returns true against the source. Result is always Layout::MaybeStrided because transposition breaks row-major contiguity for any contiguous source with more than one column.

Definition at line 683 of file ndarray.h.

◆ view() [1/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M>
NDArray< T, M, Layout::Contig > clustering::NDArray< T, N, L >::view ( std::array< std::size_t, M > shape) const
inlinenoexcept

Read-only rank-M view; mirrors the mutable overload with m_mutable = false.

Definition at line 896 of file ndarray.h.

◆ view() [2/2]

template<class T, std::size_t N, Layout L = Layout::Contig>
template<std::size_t M>
NDArray< T, M, Layout::Contig > clustering::NDArray< T, N, L >::view ( std::array< std::size_t, M > shape)
inlinenoexcept

Returns a borrowed contiguous rank-M view over the same buffer with shape shape.

Strict no-alloc primitive: the source must be runtime-contiguous (debug-asserted). Callers that want the copy-on-nonconfig fallback should use reshape instead. The element count of shape must equal the source's element count.

Template Parameters
MTarget rank. May differ from N.
Parameters
shapeDimensions of the returned view, one entry per axis.

Definition at line 886 of file ndarray.h.

◆ NDArray

template<class T, std::size_t N, Layout L = Layout::Contig>
template<class U, std::size_t M, Layout LL>
friend class NDArray
friend

Definition at line 148 of file ndarray.h.

◆ operator!=

template<class T, std::size_t N, Layout L = Layout::Contig>
bool operator!= ( const NDArray< T, N, L > & ,
const NDArray< T, N, L > &  )
friend

◆ operator==

template<class T, std::size_t N, Layout L = Layout::Contig>
bool operator== ( const NDArray< T, N, L > & ,
const NDArray< T, N, L > &  )
friend

The documentation for this class was generated from the following file: