Elementary matrices and array manipulation functions (MATLAB parity). More...
#include <memory_resource>#include <string>#include <tuple>#include <vector>#include <nk/value/value.hpp>#include <nk/value/span.hpp>Go to the source code of this file.
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 matrices and array manipulation functions (MATLAB parity).
Provides a clean, engine-free C++ API for generating elementary matrices, reshaping, reordering, padding, splitting, and multidimensional array manipulations.
Definition in file elmat.hpp.