Elementary matrix constructors, shape modification, indexing, concatenation, and specialized test matrices. More...
Files | |
| file | elmat.hpp |
| Elementary matrices and array manipulation functions (MATLAB parity). | |
Classes | |
| struct | nk::builtin::Surface3 |
| 3-D surface mesh grid coordinate triple. More... | |
| struct | nk::builtin::ShiftDimAuto |
| Result of automatic dimension shift (shiftdim(x)). More... | |
Typedefs | |
| using | nk::builtin::Meshgrid2D = std::tuple<Value, Value> |
| Result of 2D grid generation via meshgrid/ndgrid. | |
| using | nk::builtin::Meshgrid3D = std::tuple<Value, Value, Value> |
| Result of 3D grid generation via meshgrid/ndgrid. | |
Enumerations | |
| enum class | nk::builtin::NanPlace { NanPlace::Auto , NanPlace::First , NanPlace::Last } |
| Placement policy for NaN elements during sorting. More... | |
Functions | |
| Value | nk::builtin::zeros (Span< const size_t > dims, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr) |
| Creates an array filled with zeros. | |
| Value | nk::builtin::zeros (size_t rows, size_t cols, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr) |
| Creates a 2D matrix of zeros. | |
| Value | nk::builtin::ones (Span< const size_t > dims, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr) |
| Creates an array filled with ones. | |
| Value | nk::builtin::ones (size_t rows, size_t cols, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr) |
| Creates a 2D matrix of ones. | |
| Value | nk::builtin::eye (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates an identity matrix of size n x n (eye(n)). | |
| Value | nk::builtin::eye (size_t m, size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates an identity matrix of size m x n (eye(m, n)). | |
| Value | nk::builtin::eye (size_t n, ValueType dtype, std::pmr::memory_resource *mr=nullptr) |
| Creates an identity matrix of size n x n with specified data type (eye(n, dtype)). | |
| Value | nk::builtin::eye (size_t m, size_t n, ValueType dtype, std::pmr::memory_resource *mr=nullptr) |
| Creates an identity matrix of size m x n with specified data type (eye(m, n, dtype)). | |
| Value | nk::builtin::size (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Returns array dimensions as a row vector (size(x)). | |
| Value | nk::builtin::size (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr) |
| Returns length of specified dimension (size(x, dim)). | |
| Value | nk::builtin::length (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Length of largest array dimension (length(x)). | |
| Value | nk::builtin::numel (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Number of array elements (numel(x)). | |
| Value | nk::builtin::ndims (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Number of array dimensions (ndims(x)). | |
| Value | nk::builtin::pagetranspose (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Page-wise transpose of N-D array (pagetranspose(x)). | |
| Value | nk::builtin::pagectranspose (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Page-wise complex conjugate transpose of N-D array (pagectranspose(x)). | |
| Value | nk::builtin::peaks (size_t n=49, std::pmr::memory_resource *mr=nullptr) |
| Generates peaks example surface function matrix (peaks(n)). | |
| Value | nk::builtin::linspace (double a, double b, size_t n=100, std::pmr::memory_resource *mr=nullptr) |
| Generates linearly spaced vector between a and b. | |
| Value | nk::builtin::logspace (double a, double b, size_t n=50, std::pmr::memory_resource *mr=nullptr) |
| Generates logarithmically spaced vector between 10^a and 10^b. | |
| Value | nk::builtin::magic (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates an n-by-n magic square. | |
| Value | nk::builtin::hilb (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates a Hilbert matrix of order n. | |
| Value | nk::builtin::invhilb (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates an exact inverse Hilbert matrix of order n. | |
| Value | nk::builtin::pascal (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates a Pascal matrix of order n. | |
| Value | nk::builtin::pascal (size_t n, int k, std::pmr::memory_resource *mr=nullptr) |
| Creates a Pascal matrix with form selector k (pascal(n, k)). | |
| Value | nk::builtin::toeplitz (const Value &c, const Value &r=Value(), std::pmr::memory_resource *mr=nullptr) |
| Creates a Toeplitz matrix. | |
| Value | nk::builtin::vander (const Value &v, std::pmr::memory_resource *mr=nullptr) |
| Creates a Vandermonde matrix. | |
| Value | nk::builtin::wilkinson (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates a Wilkinson eigenvalue test matrix. | |
| Value | nk::builtin::rosser (std::pmr::memory_resource *mr=nullptr) |
| Generates Rosser's test matrix (8x8 symmetric with exact eigenvalues). | |
| Value | nk::builtin::hadamard (size_t n, std::pmr::memory_resource *mr=nullptr) |
| Creates a Hadamard matrix of order n. | |
| Value | nk::builtin::hankel (const Value &c, const Value &r=Value(), std::pmr::memory_resource *mr=nullptr) |
| Creates a Hankel matrix. | |
| Value | nk::builtin::compan (const Value &p, std::pmr::memory_resource *mr=nullptr) |
| Creates companion matrix of polynomial coefficients (compan(p)). | |
| Surface3 | nk::builtin::sphere (size_t n=20, std::pmr::memory_resource *mr=nullptr) |
| Generates 3-D unit sphere surface coordinates ([X,Y,Z] = sphere(n)). | |
| Surface3 | nk::builtin::cylinder (const Value &R, size_t n=20, std::pmr::memory_resource *mr=nullptr) |
| Generates 3-D cylinder surface coordinates ([X,Y,Z] = cylinder(R, n)). | |
| Surface3 | nk::builtin::ellipsoid (double xc, double yc, double zc, double xr, double yr, double zr, size_t n=20, std::pmr::memory_resource *mr=nullptr) |
| Generates 3-D ellipsoid surface coordinates ([X,Y,Z] = ellipsoid(xc,yc,zc,xr,yr,zr,n)). | |
| Meshgrid2D | nk::builtin::meshgrid (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr) |
| 2-D meshgrid ([X, Y] = meshgrid(x, y)). | |
| Meshgrid2D | nk::builtin::meshgrid (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| 2-D symmetric meshgrid ([X, Y] = meshgrid(x)). | |
| Meshgrid3D | nk::builtin::meshgrid (const Value &x, const Value &y, const Value &z, std::pmr::memory_resource *mr=nullptr) |
| 3-D meshgrid ([X, Y, Z] = meshgrid(x, y, z)). | |
| Meshgrid2D | nk::builtin::ndgrid (const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr) |
| 2-D N-D grid ([X, Y] = ndgrid(x, y)). | |
| Meshgrid3D | nk::builtin::ndgrid (const Value &x, const Value &y, const Value &z, std::pmr::memory_resource *mr=nullptr) |
| 3-D N-D grid ([X, Y, Z] = ndgrid(x, y, z)). | |
| Value | nk::builtin::repmat (const Value &x, Span< const size_t > reps, std::pmr::memory_resource *mr=nullptr) |
| Replicates and tiles an array. | |
| Value | nk::builtin::repmat (const Value &x, size_t r, size_t c, std::pmr::memory_resource *mr=nullptr) |
| 2D convenience overload for repmat. | |
| Value | nk::builtin::repmat (const Value &x, size_t r, size_t c, size_t p, std::pmr::memory_resource *mr=nullptr) |
| 3D convenience overload for repmat (repmat(x, r, c, p)). | |
| Value | nk::builtin::repmatND (const Value &x, Span< const size_t > tiles, std::pmr::memory_resource *mr=nullptr) |
| N-D array tiling overload for repmat. | |
| Value | nk::builtin::repelem (const Value &x, Span< const size_t > reps, std::pmr::memory_resource *mr=nullptr) |
| Repeats elements of an array. | |
| Value | nk::builtin::reshape (const Value &x, Span< const size_t > newDims, std::pmr::memory_resource *mr=nullptr) |
| Reshapes array to new dimensions with the same total number of elements. | |
| Value | nk::builtin::reshape (const Value &x, size_t rows, size_t cols, size_t pages=0, std::pmr::memory_resource *mr=nullptr) |
| Reshapes array with explicit rows, cols, and optional pages. | |
| Value | nk::builtin::diag (const Value &x, int k=0, std::pmr::memory_resource *mr=nullptr) |
| Extracts diagonal or builds a diagonal matrix. | |
| Value | nk::builtin::blkdiag (Span< const Value > matrices, std::pmr::memory_resource *mr=nullptr) |
| Constructs a block diagonal matrix from input matrices. | |
| Value | nk::builtin::cat (int dim, Span< const Value > arrays, std::pmr::memory_resource *mr=nullptr) |
| Concatenates arrays along dimension dim. | |
| Value | nk::builtin::horzcat (Span< const Value > arrays, std::pmr::memory_resource *mr=nullptr) |
| Concatenates arrays horizontally (along columns, dim 2). | |
| Value | nk::builtin::vertcat (Span< const Value > arrays, std::pmr::memory_resource *mr=nullptr) |
| Concatenates arrays vertically (along rows, dim 1). | |
| Value | nk::builtin::rot90 (const Value &x, int k=1, std::pmr::memory_resource *mr=nullptr) |
| Rotates a 2D matrix by 90 degrees counterclockwise k times. | |
| Value | nk::builtin::fliplr (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Flips matrix left-to-right (along columns). | |
| Value | nk::builtin::flipud (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Flips matrix up-to-down (along rows). | |
| Value | nk::builtin::flip (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr) |
| Reverses the order of elements along specified dimension. | |
| Value | nk::builtin::circshift (const Value &x, int64_t k, std::pmr::memory_resource *mr=nullptr) |
| Circularly shifts elements of 1-D vector or along first non-singleton dimension (circshift(x, k)). | |
| Value | nk::builtin::circshift (const Value &x, int64_t kRow, int64_t kCol, std::pmr::memory_resource *mr=nullptr) |
| Circularly shifts elements of 2-D matrix along rows and columns (circshift(x, [kRow, kCol])). | |
| Value | nk::builtin::circshift (const Value &x, Span< const int64_t > shifts, std::pmr::memory_resource *mr=nullptr) |
| Circularly shifts elements of array by shift vector (circshift(x, shifts)). | |
| Value | nk::builtin::circshiftND (const Value &x, Span< const int64_t > shifts, std::pmr::memory_resource *mr=nullptr) |
| Circularly shifts elements of N-D array. | |
| Value | nk::builtin::repelem (const Value &x, size_t n, std::pmr::memory_resource *mr=nullptr) |
| Repeats elements of array uniformly (repelem(x, n)). | |
| Value | nk::builtin::repelem (const Value &x, size_t m, size_t n, std::pmr::memory_resource *mr=nullptr) |
| Repeats elements along rows and columns (repelem(x, m, n)). | |
| Value | nk::builtin::repelem (const Value &x, const Value &counts, std::pmr::memory_resource *mr=nullptr) |
| Repeats elements with variable counts per element (repelem(x, counts)). | |
| Value | nk::builtin::repelem (const Value &x, const Value &rCounts, const Value &cCounts, std::pmr::memory_resource *mr=nullptr) |
| Repeats elements along rows and columns with separate count vectors (repelem(x, rCounts, cCounts)). | |
| Value | nk::builtin::permute (const Value &x, Span< const int > order, std::pmr::memory_resource *mr=nullptr) |
| Permutes dimensions of an N-D array (permute(x, order)). | |
| Value | nk::builtin::permute (const Value &x, Span< const size_t > order, std::pmr::memory_resource *mr=nullptr) |
| Permutes dimensions of an N-D array using size_t order vector. | |
| Value | nk::builtin::ipermute (const Value &x, Span< const int > order, std::pmr::memory_resource *mr=nullptr) |
| Inverse permutes dimensions of an N-D array. | |
| Value | nk::builtin::ipermute (const Value &x, Span< const size_t > order, std::pmr::memory_resource *mr=nullptr) |
| Inverse permutes dimensions of an N-D array using size_t order vector. | |
| Value | nk::builtin::shiftdim (const Value &x, int n=0, std::pmr::memory_resource *mr=nullptr) |
| Shifts dimensions of array by n steps (shiftdim(x, n)). | |
| ShiftDimAuto | nk::builtin::shiftdimAuto (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Automatically shifts out leading singleton dimensions (shiftdim(x)). | |
| Value | nk::builtin::squeeze (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Removes singleton dimensions from an array. | |
| Value | nk::builtin::head (const Value &x, size_t k=8, std::pmr::memory_resource *mr=nullptr) |
| Returns the top k rows or elements of an array. | |
| Value | nk::builtin::tail (const Value &x, size_t k=8, std::pmr::memory_resource *mr=nullptr) |
| Returns the bottom k rows or elements of an array. | |
| Value | nk::builtin::paddata (const Value &x, size_t len, std::pmr::memory_resource *mr=nullptr) |
| Pads data array to specified length with zeros (paddata(x, len)). | |
| Value | nk::builtin::paddata (const Value &x, size_t len, int dim, const std::string &side="right", std::pmr::memory_resource *mr=nullptr) |
| Pads data array to length along dimension (paddata(x, len, dim, side)). | |
| Value | nk::builtin::trimdata (const Value &x, size_t len, std::pmr::memory_resource *mr=nullptr) |
| Trims data array to specified length (trimdata(x, len)). | |
| Value | nk::builtin::trimdata (const Value &x, size_t len, int dim, const std::string &side="right", std::pmr::memory_resource *mr=nullptr) |
| Trims data array along dimension (trimdata(x, len, dim, side)). | |
| Value | nk::builtin::resize (const Value &v, size_t n, std::pmr::memory_resource *mr=nullptr) |
| Resizes 1-D vector to length n by padding or trimming (resize(v, n)). | |
| Value | nk::builtin::sub2ind (const Value &siz, Span< const Value > subs, std::pmr::memory_resource *mr=nullptr) |
| Converts subscript indices to linear index (sub2ind(siz, i, j, ...)). | |
| std::vector< Value > | nk::builtin::ind2sub (const Value &siz, const Value &ind, size_t nout=0, std::pmr::memory_resource *mr=nullptr) |
| Converts linear indices to subscript indices ([I1, I2, ...] = ind2sub(siz, ind)). | |
| Value | nk::builtin::bsxfun (const std::string &op, const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr) |
| Applies element-wise binary operator with singleton expansion (broadcasting). | |
| Value | nk::builtin::tril (const Value &x, int k=0, std::pmr::memory_resource *mr=nullptr) |
| Extracts lower triangular part of a matrix. | |
| Value | nk::builtin::triu (const Value &x, int k=0, std::pmr::memory_resource *mr=nullptr) |
| Extracts upper triangular part of a matrix. | |
| std::tuple< Value, Value > | nk::builtin::sort (const Value &x, int dim=0, bool descend=false, NanPlace nanPlace=NanPlace::Auto, std::pmr::memory_resource *mr=nullptr) |
| Sorts array elements in ascending or descending order ([B, I] = sort(x, dim, direction)). | |
| std::tuple< Value, Value > | nk::builtin::sortrows (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Sorts rows of 2-D matrix in ascending order ([B, I] = sortrows(x)). | |
| std::tuple< Value, Value > | nk::builtin::sortrows (const Value &x, Span< const int > cols, std::pmr::memory_resource *mr=nullptr) |
| Sorts rows of 2-D matrix based on specified columns ([B, I] = sortrows(x, cols)). | |
| std::tuple< Value, Value > | nk::builtin::sortrows (const Value &x, Span< const int > cols, Span< const bool > desc, std::pmr::memory_resource *mr=nullptr) |
| Sorts rows based on columns and directions ([B, I] = sortrows(x, cols, direction)). | |
| Value | nk::builtin::issorted (const Value &x, int dim=0, bool descend=false, std::pmr::memory_resource *mr=nullptr) |
| Tests if array is sorted (issorted(x, dim, direction)). | |
| Value | nk::builtin::issortedrows (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Tests if rows of 2-D matrix are sorted in ascending order (issortedrows(x)). | |
| Value | nk::builtin::issortedrows (const Value &x, Span< const int > cols, Span< const bool > desc={}, std::pmr::memory_resource *mr=nullptr) |
| Tests if rows of 2-D matrix are sorted based on columns and directions (issortedrows(x, cols, desc)). | |
| std::tuple< Value, Value > | nk::builtin::topkrows (const Value &x, size_t k, Span< const int > cols={}, Span< const bool > desc={}, std::pmr::memory_resource *mr=nullptr) |
| Finds the top k sorted rows of a matrix ([B, I] = topkrows(x, k, cols, desc)). | |
| Value | nk::builtin::find (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Finds indices of non-zero array elements (find(x)). | |
| Value | nk::builtin::nnz (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Number of non-zero matrix elements (nnz(x)). | |
| Value | nk::builtin::nonzeros (const Value &x, std::pmr::memory_resource *mr=nullptr) |
| Non-zero elements of matrix as column vector (nonzeros(x)). | |
| Value | nk::builtin::xorOf (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr) |
| Logical exclusive OR of two arrays (xor(a, b)). | |
Elementary matrix constructors, shape modification, indexing, concatenation, and specialized test matrices.
| using nk::builtin::Meshgrid2D = std::tuple<Value, Value> |
| using nk::builtin::Meshgrid3D = std::tuple<Value, Value, Value> |
|
strong |
| Value nk::builtin::blkdiag | ( | Span< const Value > | matrices, |
| std::pmr::memory_resource * | mr = nullptr ) |
Constructs a block diagonal matrix from input matrices.
| matrices | List of matrices to place on the diagonal. |
| mr | Memory resource. |
| Value nk::builtin::bsxfun | ( | const std::string & | op, |
| const Value & | a, | ||
| const Value & | b, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Applies element-wise binary operator with singleton expansion (broadcasting).
| op | Binary operator name (e.g. "plus", "times", "rdivide", "power"). |
| a | First array operand. |
| b | Second array operand. |
| mr | Memory resource. |
| Value nk::builtin::cat | ( | int | dim, |
| Span< const Value > | arrays, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Concatenates arrays along dimension dim.
| dim | 1-based dimension (1=rows, 2=cols, 3=pages, etc.). |
| arrays | List of arrays to concatenate. |
| mr | Memory resource. |
| Value nk::builtin::circshift | ( | const Value & | x, |
| int64_t | k, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Circularly shifts elements of 1-D vector or along first non-singleton dimension (circshift(x, k)).
| x | Input array. |
| k | Shift amount. |
| mr | Memory resource. |
| Value nk::builtin::circshift | ( | const Value & | x, |
| int64_t | kRow, | ||
| int64_t | kCol, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Circularly shifts elements of 2-D matrix along rows and columns (circshift(x, [kRow, kCol])).
| x | Input matrix. |
| kRow | Row shift amount. |
| kCol | Column shift amount. |
| mr | Memory resource. |
| Value nk::builtin::circshift | ( | const Value & | x, |
| Span< const int64_t > | shifts, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Circularly shifts elements of array by shift vector (circshift(x, shifts)).
| x | Input array. |
| shifts | Span of shift amounts per dimension. |
| mr | Memory resource. |
| Value nk::builtin::circshiftND | ( | const Value & | x, |
| Span< const int64_t > | shifts, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Circularly shifts elements of N-D array.
| x | Input array. |
| shifts | Span of shift amounts. |
| mr | Memory resource. |
Creates companion matrix of polynomial coefficients (compan(p)).
| p | Polynomial coefficients vector. |
| mr | Memory resource. |
| Surface3 nk::builtin::cylinder | ( | const Value & | R, |
| size_t | n = 20, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generates 3-D cylinder surface coordinates ([X,Y,Z] = cylinder(R, n)).
| R | Profile curve radius vector. |
| n | Number of points around circumference (default: 20). |
| mr | Memory resource. |
Extracts diagonal or builds a diagonal matrix.
| x | Vector or matrix. |
| k | Diagonal offset (0=main, >0=above, <0=below). |
| mr | Memory resource. |
| Surface3 nk::builtin::ellipsoid | ( | double | xc, |
| double | yc, | ||
| double | zc, | ||
| double | xr, | ||
| double | yr, | ||
| double | zr, | ||
| size_t | n = 20, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generates 3-D ellipsoid surface coordinates ([X,Y,Z] = ellipsoid(xc,yc,zc,xr,yr,zr,n)).
| xc | Center x-coordinate. |
| yc | Center y-coordinate. |
| zc | Center z-coordinate. |
| xr | Semi-axis length x. |
| yr | Semi-axis length y. |
| zr | Semi-axis length z. |
| n | Number of facets (default: 20). |
| mr | Memory resource. |
| Value nk::builtin::eye | ( | size_t | m, |
| size_t | n, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an identity matrix of size m x n (eye(m, n)).
| m | Row count. |
| n | Column count. |
| mr | Memory resource. |
| Value nk::builtin::eye | ( | size_t | m, |
| size_t | n, | ||
| ValueType | dtype, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an identity matrix of size m x n with specified data type (eye(m, n, dtype)).
| m | Row count. |
| n | Column count. |
| dtype | Data type. |
| mr | Memory resource. |
| Value nk::builtin::eye | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an identity matrix of size n x n (eye(n)).
| n | Order of the identity matrix. |
| mr | Memory resource. |
| Value nk::builtin::eye | ( | size_t | n, |
| ValueType | dtype, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an identity matrix of size n x n with specified data type (eye(n, dtype)).
| n | Order of the identity matrix. |
| dtype | Data type (e.g. ValueType::SINGLE, ValueType::INT32). |
| mr | Memory resource. |
Reverses the order of elements along specified dimension.
| x | Input array. |
| dim | Dimension to flip along (0 = first non-singleton dimension). |
| mr | Memory resource. |
Flips matrix left-to-right (along columns).
| x | Input 2D matrix. |
| mr | Memory resource. |
Flips matrix up-to-down (along rows).
| x | Input 2D matrix. |
| mr | Memory resource. |
| Value nk::builtin::hadamard | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Hadamard matrix of order n.
| n | Order of the matrix (1, 2, or a multiple of 4). |
| mr | Memory resource. |
| Value nk::builtin::hankel | ( | const Value & | c, |
| const Value & | r = Value(), | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Hankel matrix.
| c | First column vector. |
| r | Last row vector (optional, elements beyond c default to zero). |
| mr | Memory resource. |
Returns the top k rows or elements of an array.
| x | Input array. |
| k | Number of rows/elements (default: 8). |
| mr | Memory resource. |
| Value nk::builtin::hilb | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Hilbert matrix of order n.
| n | Order of the Hilbert matrix. |
| mr | Memory resource. |
Concatenates arrays horizontally (along columns, dim 2).
| arrays | List of arrays. |
| mr | Memory resource. |
| std::vector< Value > nk::builtin::ind2sub | ( | const Value & | siz, |
| const Value & | ind, | ||
| size_t | nout = 0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Converts linear indices to subscript indices ([I1, I2, ...] = ind2sub(siz, ind)).
| siz | Array size vector. |
| ind | Linear index array. |
| nout | Number of subscript outputs requested. |
| mr | Memory resource. |
| Value nk::builtin::invhilb | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an exact inverse Hilbert matrix of order n.
| n | Order of the matrix (n <= 14). |
| mr | Memory resource. |
| Value nk::builtin::ipermute | ( | const Value & | x, |
| Span< const int > | order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Inverse permutes dimensions of an N-D array.
| x | Input array. |
| order | Ordering of dimensions used in previous permute call. |
| mr | Memory resource. |
| Value nk::builtin::ipermute | ( | const Value & | x, |
| Span< const size_t > | order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Inverse permutes dimensions of an N-D array using size_t order vector.
| x | Input array. |
| order | Ordering of dimensions. |
| mr | Memory resource. |
| Value nk::builtin::issorted | ( | const Value & | x, |
| int | dim = 0, | ||
| bool | descend = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Tests if array is sorted (issorted(x, dim, direction)).
| x | Input array. |
| dim | Operating dimension. |
| descend | True if checking for descending order. |
| mr | Memory resource. |
| Value nk::builtin::issortedrows | ( | const Value & | x, |
| Span< const int > | cols, | ||
| Span< const bool > | desc = {}, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Tests if rows of 2-D matrix are sorted based on columns and directions (issortedrows(x, cols, desc)).
| x | Input matrix. |
| cols | Column indices. |
| desc | Descending flags. |
| mr | Memory resource. |
Tests if rows of 2-D matrix are sorted in ascending order (issortedrows(x)).
| x | Input matrix. |
| mr | Memory resource. |
Length of largest array dimension (length(x)).
| x | Input array. |
| mr | Memory resource. |
| Value nk::builtin::linspace | ( | double | a, |
| double | b, | ||
| size_t | n = 100, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generates linearly spaced vector between a and b.
| a | Start point. |
| b | End point. |
| n | Number of points (default: 100). |
| mr | Memory resource. |
| Value nk::builtin::logspace | ( | double | a, |
| double | b, | ||
| size_t | n = 50, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generates logarithmically spaced vector between 10^a and 10^b.
| a | Exponent for start point (10^a). |
| b | Exponent for end point (10^b or pi if b == pi). |
| n | Number of points (default: 50). |
| mr | Memory resource. |
| Value nk::builtin::magic | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an n-by-n magic square.
| n | Order of the magic square (n >= 3). |
| mr | Memory resource. |
| Meshgrid3D nk::builtin::meshgrid | ( | const Value & | x, |
| const Value & | y, | ||
| const Value & | z, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
3-D meshgrid ([X, Y, Z] = meshgrid(x, y, z)).
| x | x-axis grid. |
| y | y-axis grid. |
| z | z-axis grid. |
| mr | Memory resource. |
| Meshgrid2D nk::builtin::meshgrid | ( | const Value & | x, |
| const Value & | y, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
2-D meshgrid ([X, Y] = meshgrid(x, y)).
| x | x-axis grid coordinates. |
| y | y-axis grid coordinates. |
| mr | Memory resource. |
| Meshgrid2D nk::builtin::meshgrid | ( | const Value & | x, |
| std::pmr::memory_resource * | mr = nullptr ) |
2-D symmetric meshgrid ([X, Y] = meshgrid(x)).
| x | Grid coordinates for both axes. |
| mr | Memory resource. |
| Meshgrid3D nk::builtin::ndgrid | ( | const Value & | x, |
| const Value & | y, | ||
| const Value & | z, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
3-D N-D grid ([X, Y, Z] = ndgrid(x, y, z)).
| x | First-axis grid. |
| y | Second-axis grid. |
| z | Third-axis grid. |
| mr | Memory resource. |
| Meshgrid2D nk::builtin::ndgrid | ( | const Value & | x, |
| const Value & | y, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
2-D N-D grid ([X, Y] = ndgrid(x, y)).
| x | First-axis grid. |
| y | Second-axis grid. |
| mr | Memory resource. |
Number of array dimensions (ndims(x)).
| x | Input array. |
| mr | Memory resource. |
Number of array elements (numel(x)).
| x | Input array. |
| mr | Memory resource. |
| Value nk::builtin::ones | ( | size_t | rows, |
| size_t | cols, | ||
| ValueType | dtype = ValueType::DOUBLE, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a 2D matrix of ones.
| rows | Number of rows. |
| cols | Number of columns. |
| dtype | Data type (default: ValueType::DOUBLE). |
| mr | Memory resource. |
| Value nk::builtin::paddata | ( | const Value & | x, |
| size_t | len, | ||
| int | dim, | ||
| const std::string & | side = "right", | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Pads data array to length along dimension (paddata(x, len, dim, side)).
| x | Input array. |
| len | Target length. |
| dim | Operating dimension. |
| side | Direction ("left", "right"). |
| mr | Memory resource. |
| Value nk::builtin::paddata | ( | const Value & | x, |
| size_t | len, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Pads data array to specified length with zeros (paddata(x, len)).
| x | Input array. |
| len | Target length. |
| mr | Memory resource. |
Page-wise complex conjugate transpose of N-D array (pagectranspose(x)).
| x | Input array. |
| mr | Memory resource. |
Page-wise transpose of N-D array (pagetranspose(x)).
| x | Input array. |
| mr | Memory resource. |
| Value nk::builtin::pascal | ( | size_t | n, |
| int | k, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Pascal matrix with form selector k (pascal(n, k)).
| n | Order of the matrix. |
| k | Form selector (0=symmetric, 1=lower triangular, 2=upper triangular Cholesky factor). |
| mr | Memory resource. |
| Value nk::builtin::pascal | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Pascal matrix of order n.
| n | Order of the matrix. |
| mr | Memory resource. |
| Value nk::builtin::peaks | ( | size_t | n = 49, |
| std::pmr::memory_resource * | mr = nullptr ) |
Generates peaks example surface function matrix (peaks(n)).
| n | Order of the square matrix (default: 49). |
| mr | Memory resource. |
| Value nk::builtin::permute | ( | const Value & | x, |
| Span< const int > | order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Permutes dimensions of an N-D array (permute(x, order)).
| x | Input array. |
| order | Dimension permutation order vector (1-based). |
| mr | Memory resource. |
| Value nk::builtin::permute | ( | const Value & | x, |
| Span< const size_t > | order, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Permutes dimensions of an N-D array using size_t order vector.
| x | Input array. |
| order | 1-based dimension indices. |
| mr | Memory resource. |
| Value nk::builtin::repelem | ( | const Value & | x, |
| const Value & | counts, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Repeats elements with variable counts per element (repelem(x, counts)).
| x | Input vector. |
| counts | Repetition counts vector. |
| mr | Memory resource. |
| Value nk::builtin::repelem | ( | const Value & | x, |
| const Value & | rCounts, | ||
| const Value & | cCounts, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Repeats elements along rows and columns with separate count vectors (repelem(x, rCounts, cCounts)).
| x | Input matrix. |
| rCounts | Row repeat counts vector. |
| cCounts | Column repeat counts vector. |
| mr | Memory resource. |
| Value nk::builtin::repelem | ( | const Value & | x, |
| size_t | m, | ||
| size_t | n, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Repeats elements along rows and columns (repelem(x, m, n)).
| x | Input matrix. |
| m | Row repetition factor. |
| n | Column repetition factor. |
| mr | Memory resource. |
Repeats elements of array uniformly (repelem(x, n)).
| x | Input array. |
| n | Repetition count per element. |
| mr | Memory resource. |
| Value nk::builtin::repelem | ( | const Value & | x, |
| Span< const size_t > | reps, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Repeats elements of an array.
| x | Input array. |
| reps | Repetition factors per dimension. |
| mr | Memory resource. |
| Value nk::builtin::repmat | ( | const Value & | x, |
| size_t | r, | ||
| size_t | c, | ||
| size_t | p, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
3D convenience overload for repmat (repmat(x, r, c, p)).
| x | Input array. |
| r | Row repetition factor. |
| c | Column repetition factor. |
| p | Page repetition factor. |
| mr | Memory resource. |
| Value nk::builtin::repmat | ( | const Value & | x, |
| size_t | r, | ||
| size_t | c, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
2D convenience overload for repmat.
| x | Input array. |
| r | Row repetition factor. |
| c | Column repetition factor. |
| mr | Memory resource. |
| Value nk::builtin::repmatND | ( | const Value & | x, |
| Span< const size_t > | tiles, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
N-D array tiling overload for repmat.
| x | Input array. |
| tiles | Span of repetition counts. |
| mr | Memory resource. |
| Value nk::builtin::reshape | ( | const Value & | x, |
| size_t | rows, | ||
| size_t | cols, | ||
| size_t | pages = 0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Reshapes array with explicit rows, cols, and optional pages.
| x | Input array. |
| rows | Target row count. |
| cols | Target column count. |
| pages | Target page count (0 for 2-D). |
| mr | Memory resource. |
| Value nk::builtin::reshape | ( | const Value & | x, |
| Span< const size_t > | newDims, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Reshapes array to new dimensions with the same total number of elements.
| x | Input array. |
| newDims | Target shape. |
| mr | Memory resource. |
Resizes 1-D vector to length n by padding or trimming (resize(v, n)).
| v | Input vector. |
| n | Target length. |
| mr | Memory resource. |
| Value nk::builtin::rosser | ( | std::pmr::memory_resource * | mr = nullptr | ) |
Generates Rosser's test matrix (8x8 symmetric with exact eigenvalues).
| mr | Memory resource. |
Rotates a 2D matrix by 90 degrees counterclockwise k times.
| x | Input 2D matrix. |
| k | Number of 90-degree rotations (default: 1). |
| mr | Memory resource. |
| Value nk::builtin::shiftdim | ( | const Value & | x, |
| int | n = 0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Shifts dimensions of array by n steps (shiftdim(x, n)).
| x | Input array. |
| n | Number of shifts (positive shifts left, negative shifts right / adds singletons). |
| mr | Memory resource. |
| ShiftDimAuto nk::builtin::shiftdimAuto | ( | const Value & | x, |
| std::pmr::memory_resource * | mr = nullptr ) |
Automatically shifts out leading singleton dimensions (shiftdim(x)).
| x | Input array. |
| mr | Memory resource. |
Returns length of specified dimension (size(x, dim)).
| x | Input array. |
| dim | 1-based dimension index. |
| mr | Memory resource. |
Returns array dimensions as a row vector (size(x)).
| x | Input array. |
| mr | Memory resource. |
| std::tuple< Value, Value > nk::builtin::sort | ( | const Value & | x, |
| int | dim = 0, | ||
| bool | descend = false, | ||
| NanPlace | nanPlace = NanPlace::Auto, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Sorts array elements in ascending or descending order ([B, I] = sort(x, dim, direction)).
| x | Input array. |
| dim | Operating dimension (0 for first non-singleton). |
| descend | True for descending order. |
| nanPlace | NaN positioning rule. |
| mr | Memory resource. |
| std::tuple< Value, Value > nk::builtin::sortrows | ( | const Value & | x, |
| Span< const int > | cols, | ||
| Span< const bool > | desc, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Sorts rows based on columns and directions ([B, I] = sortrows(x, cols, direction)).
| x | Input 2-D matrix. |
| cols | Column indices. |
| desc | Descending flags per column. |
| mr | Memory resource. |
| std::tuple< Value, Value > nk::builtin::sortrows | ( | const Value & | x, |
| Span< const int > | cols, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Sorts rows of 2-D matrix based on specified columns ([B, I] = sortrows(x, cols)).
| x | Input 2-D matrix. |
| cols | 1-based column indices. |
| mr | Memory resource. |
| std::tuple< Value, Value > nk::builtin::sortrows | ( | const Value & | x, |
| std::pmr::memory_resource * | mr = nullptr ) |
Sorts rows of 2-D matrix in ascending order ([B, I] = sortrows(x)).
| x | Input 2-D matrix. |
| mr | Memory resource. |
| Surface3 nk::builtin::sphere | ( | size_t | n = 20, |
| std::pmr::memory_resource * | mr = nullptr ) |
Generates 3-D unit sphere surface coordinates ([X,Y,Z] = sphere(n)).
| n | Number of facets (default: 20). |
| mr | Memory resource. |
Removes singleton dimensions from an array.
| x | Input array. |
| mr | Memory resource. |
| Value nk::builtin::sub2ind | ( | const Value & | siz, |
| Span< const Value > | subs, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Converts subscript indices to linear index (sub2ind(siz, i, j, ...)).
| siz | Array size vector. |
| subs | Subscript index values. |
| mr | Memory resource. |
Returns the bottom k rows or elements of an array.
| x | Input array. |
| k | Number of rows/elements (default: 8). |
| mr | Memory resource. |
| Value nk::builtin::toeplitz | ( | const Value & | c, |
| const Value & | r = Value(), | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Toeplitz matrix.
| c | First column vector. |
| r | First row vector (optional, defaults to c). |
| mr | Memory resource. |
| std::tuple< Value, Value > nk::builtin::topkrows | ( | const Value & | x, |
| size_t | k, | ||
| Span< const int > | cols = {}, | ||
| Span< const bool > | desc = {}, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Finds the top k sorted rows of a matrix ([B, I] = topkrows(x, k, cols, desc)).
| x | Input matrix. |
| k | Number of rows to return. |
| cols | Column indices. |
| desc | Descending flags. |
| mr | Memory resource. |
Extracts lower triangular part of a matrix.
| x | Input matrix. |
| k | Diagonal offset (0=main, >0=above, <0=below). |
| mr | Memory resource. |
| Value nk::builtin::trimdata | ( | const Value & | x, |
| size_t | len, | ||
| int | dim, | ||
| const std::string & | side = "right", | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Trims data array along dimension (trimdata(x, len, dim, side)).
| x | Input array. |
| len | Target length. |
| dim | Operating dimension. |
| side | Direction ("left", "right"). |
| mr | Memory resource. |
| Value nk::builtin::trimdata | ( | const Value & | x, |
| size_t | len, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Trims data array to specified length (trimdata(x, len)).
| x | Input array. |
| len | Target length. |
| mr | Memory resource. |
Extracts upper triangular part of a matrix.
| x | Input matrix. |
| k | Diagonal offset (0=main, >0=above, <0=below). |
| mr | Memory resource. |
Creates a Vandermonde matrix.
| v | Input vector of points. |
| mr | Memory resource. |
Concatenates arrays vertically (along rows, dim 1).
| arrays | List of arrays. |
| mr | Memory resource. |
| Value nk::builtin::wilkinson | ( | size_t | n, |
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a Wilkinson eigenvalue test matrix.
| n | Order of the matrix (must be odd). |
| mr | Memory resource. |
| Value nk::builtin::xorOf | ( | const Value & | a, |
| const Value & | b, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Logical exclusive OR of two arrays (xor(a, b)).
| a | First array. |
| b | Second array. |
| mr | Memory resource. |
| Value nk::builtin::zeros | ( | size_t | rows, |
| size_t | cols, | ||
| ValueType | dtype = ValueType::DOUBLE, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates a 2D matrix of zeros.
| rows | Number of rows. |
| cols | Number of columns. |
| dtype | Data type (default: ValueType::DOUBLE). |
| mr | Memory resource. |
| Value nk::builtin::zeros | ( | Span< const size_t > | dims, |
| ValueType | dtype = ValueType::DOUBLE, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Creates an array filled with zeros.
| dims | Dimensions of the target matrix or N-D array. |
| dtype | Data type of elements (default: ValueType::DOUBLE). |
| mr | Memory resource for allocations (nullptr for default). |