nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Elementary Matrices and Array Manipulation (elmat)

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)).

Detailed Description

Elementary matrix constructors, shape modification, indexing, concatenation, and specialized test matrices.

Typedef Documentation

◆ Meshgrid2D

using nk::builtin::Meshgrid2D = std::tuple<Value, Value>

Result of 2D grid generation via meshgrid/ndgrid.

Definition at line 29 of file elmat.hpp.

◆ Meshgrid3D

using nk::builtin::Meshgrid3D = std::tuple<Value, Value, Value>

Result of 3D grid generation via meshgrid/ndgrid.

Definition at line 32 of file elmat.hpp.

Enumeration Type Documentation

◆ NanPlace

enum class nk::builtin::NanPlace
strong

Placement policy for NaN elements during sorting.

Enumerator
Auto 

Put NaNs at the end.

First 

Put NaNs at the beginning.

Last 

Put NaNs at the end.

Definition at line 640 of file elmat.hpp.

Function Documentation

◆ blkdiag()

Value nk::builtin::blkdiag ( Span< const Value > matrices,
std::pmr::memory_resource * mr = nullptr )

Constructs a block diagonal matrix from input matrices.

Parameters
matricesList of matrices to place on the diagonal.
mrMemory resource.
Returns
Block diagonal matrix.

◆ bsxfun()

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).

Parameters
opBinary operator name (e.g. "plus", "times", "rdivide", "power").
aFirst array operand.
bSecond array operand.
mrMemory resource.
Returns
Broadcasted result array.

◆ cat()

Value nk::builtin::cat ( int dim,
Span< const Value > arrays,
std::pmr::memory_resource * mr = nullptr )

Concatenates arrays along dimension dim.

Parameters
dim1-based dimension (1=rows, 2=cols, 3=pages, etc.).
arraysList of arrays to concatenate.
mrMemory resource.
Returns
Concatenated array.

◆ circshift() [1/3]

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)).

Parameters
xInput array.
kShift amount.
mrMemory resource.
Returns
Circularly shifted array.

◆ circshift() [2/3]

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])).

Parameters
xInput matrix.
kRowRow shift amount.
kColColumn shift amount.
mrMemory resource.
Returns
Circularly shifted matrix.

◆ circshift() [3/3]

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)).

Parameters
xInput array.
shiftsSpan of shift amounts per dimension.
mrMemory resource.
Returns
Circularly shifted array.

◆ circshiftND()

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.

Parameters
xInput array.
shiftsSpan of shift amounts.
mrMemory resource.
Returns
Circularly shifted array.

◆ compan()

Value nk::builtin::compan ( const Value & p,
std::pmr::memory_resource * mr = nullptr )

Creates companion matrix of polynomial coefficients (compan(p)).

Parameters
pPolynomial coefficients vector.
mrMemory resource.
Returns
Companion matrix.

◆ cylinder()

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)).

Parameters
RProfile curve radius vector.
nNumber of points around circumference (default: 20).
mrMemory resource.
Returns
Surface3 struct.

◆ diag()

Value nk::builtin::diag ( const Value & x,
int k = 0,
std::pmr::memory_resource * mr = nullptr )

Extracts diagonal or builds a diagonal matrix.

Parameters
xVector or matrix.
kDiagonal offset (0=main, >0=above, <0=below).
mrMemory resource.
Returns
Diagonal vector or diagonal matrix.
See also
blkdiag

◆ ellipsoid()

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)).

Parameters
xcCenter x-coordinate.
ycCenter y-coordinate.
zcCenter z-coordinate.
xrSemi-axis length x.
yrSemi-axis length y.
zrSemi-axis length z.
nNumber of facets (default: 20).
mrMemory resource.
Returns
Surface3 struct.

◆ eye() [1/4]

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)).

Parameters
mRow count.
nColumn count.
mrMemory resource.
Returns
m x n identity matrix.

◆ eye() [2/4]

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)).

Parameters
mRow count.
nColumn count.
dtypeData type.
mrMemory resource.
Returns
m x n typed identity matrix.

◆ eye() [3/4]

Value nk::builtin::eye ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates an identity matrix of size n x n (eye(n)).

Parameters
nOrder of the identity matrix.
mrMemory resource.
Returns
n x n identity matrix.

◆ eye() [4/4]

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)).

Parameters
nOrder of the identity matrix.
dtypeData type (e.g. ValueType::SINGLE, ValueType::INT32).
mrMemory resource.
Returns
n x n typed identity matrix.

◆ find()

Value nk::builtin::find ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Finds indices of non-zero array elements (find(x)).

Parameters
xInput array.
mrMemory resource.
Returns
1-based linear indices of non-zero elements.
See also
nnz, nonzeros

◆ flip()

Value nk::builtin::flip ( const Value & x,
int dim = 0,
std::pmr::memory_resource * mr = nullptr )

Reverses the order of elements along specified dimension.

Parameters
xInput array.
dimDimension to flip along (0 = first non-singleton dimension).
mrMemory resource.
Returns
Flipped array.

◆ fliplr()

Value nk::builtin::fliplr ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Flips matrix left-to-right (along columns).

Parameters
xInput 2D matrix.
mrMemory resource.
Returns
Flipped matrix.

◆ flipud()

Value nk::builtin::flipud ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Flips matrix up-to-down (along rows).

Parameters
xInput 2D matrix.
mrMemory resource.
Returns
Flipped matrix.

◆ hadamard()

Value nk::builtin::hadamard ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates a Hadamard matrix of order n.

Parameters
nOrder of the matrix (1, 2, or a multiple of 4).
mrMemory resource.
Returns
n x n Hadamard matrix.

◆ hankel()

Value nk::builtin::hankel ( const Value & c,
const Value & r = Value(),
std::pmr::memory_resource * mr = nullptr )

Creates a Hankel matrix.

Parameters
cFirst column vector.
rLast row vector (optional, elements beyond c default to zero).
mrMemory resource.
Returns
Hankel matrix.

◆ head()

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.

Parameters
xInput array.
kNumber of rows/elements (default: 8).
mrMemory resource.
Returns
Subarray containing top elements.
See also
tail

◆ hilb()

Value nk::builtin::hilb ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates a Hilbert matrix of order n.

Parameters
nOrder of the Hilbert matrix.
mrMemory resource.
Returns
n x n matrix where H(i,j) = 1 / (i + j - 1).
See also
invhilb

◆ horzcat()

Value nk::builtin::horzcat ( Span< const Value > arrays,
std::pmr::memory_resource * mr = nullptr )

Concatenates arrays horizontally (along columns, dim 2).

Parameters
arraysList of arrays.
mrMemory resource.
Returns
Horizontally concatenated array.

◆ ind2sub()

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)).

Parameters
sizArray size vector.
indLinear index array.
noutNumber of subscript outputs requested.
mrMemory resource.
Returns
Vector of subscript arrays.
See also
sub2ind

◆ invhilb()

Value nk::builtin::invhilb ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates an exact inverse Hilbert matrix of order n.

Parameters
nOrder of the matrix (n <= 14).
mrMemory resource.
Returns
n x n integer inverse Hilbert matrix.
See also
hilb

◆ ipermute() [1/2]

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.

Parameters
xInput array.
orderOrdering of dimensions used in previous permute call.
mrMemory resource.
Returns
Array with dimensions restored.

◆ ipermute() [2/2]

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.

Parameters
xInput array.
orderOrdering of dimensions.
mrMemory resource.
Returns
Array with dimensions restored.

◆ issorted()

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)).

Parameters
xInput array.
dimOperating dimension.
descendTrue if checking for descending order.
mrMemory resource.
Returns
Logical true if array is sorted.

◆ issortedrows() [1/2]

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)).

Parameters
xInput matrix.
colsColumn indices.
descDescending flags.
mrMemory resource.
Returns
Logical true if rows are sorted.

◆ issortedrows() [2/2]

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)).

Parameters
xInput matrix.
mrMemory resource.
Returns
Logical true if rows are sorted.

◆ length()

Value nk::builtin::length ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Length of largest array dimension (length(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Largest dimension length.

◆ linspace()

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.

Parameters
aStart point.
bEnd point.
nNumber of points (default: 100).
mrMemory resource.
Returns
Row vector of n evenly spaced points.
See also
logspace

◆ logspace()

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.

Parameters
aExponent for start point (10^a).
bExponent for end point (10^b or pi if b == pi).
nNumber of points (default: 50).
mrMemory resource.
Returns
Row vector of n logarithmically spaced points.
See also
linspace

◆ magic()

Value nk::builtin::magic ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates an n-by-n magic square.

Parameters
nOrder of the magic square (n >= 3).
mrMemory resource.
Returns
n x n magic square matrix.

◆ meshgrid() [1/3]

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)).

Parameters
xx-axis grid.
yy-axis grid.
zz-axis grid.
mrMemory resource.
Returns
(X, Y, Z) grid triple of size numel(y) x numel(x) x numel(z).

◆ meshgrid() [2/3]

Meshgrid2D nk::builtin::meshgrid ( const Value & x,
const Value & y,
std::pmr::memory_resource * mr = nullptr )

2-D meshgrid ([X, Y] = meshgrid(x, y)).

Parameters
xx-axis grid coordinates.
yy-axis grid coordinates.
mrMemory resource.
Returns
(X, Y) grid pair of size numel(y) x numel(x).

◆ meshgrid() [3/3]

Meshgrid2D nk::builtin::meshgrid ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

2-D symmetric meshgrid ([X, Y] = meshgrid(x)).

Parameters
xGrid coordinates for both axes.
mrMemory resource.
Returns
(X, Y) grid pair.

◆ ndgrid() [1/2]

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)).

Parameters
xFirst-axis grid.
ySecond-axis grid.
zThird-axis grid.
mrMemory resource.
Returns
(X, Y, Z) grid triple of size numel(x) x numel(y) x numel(z).

◆ ndgrid() [2/2]

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)).

Parameters
xFirst-axis grid.
ySecond-axis grid.
mrMemory resource.
Returns
(X, Y) grid pair of size numel(x) x numel(y).

◆ ndims()

Value nk::builtin::ndims ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Number of array dimensions (ndims(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Dimension count (>= 2).

◆ nnz()

Value nk::builtin::nnz ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Number of non-zero matrix elements (nnz(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Count of non-zero elements.
See also
nonzeros, find

◆ nonzeros()

Value nk::builtin::nonzeros ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Non-zero elements of matrix as column vector (nonzeros(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Column vector of non-zero values.
See also
nnz, find

◆ numel()

Value nk::builtin::numel ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Number of array elements (numel(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Total number of elements.

◆ ones() [1/2]

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.

Parameters
rowsNumber of rows.
colsNumber of columns.
dtypeData type (default: ValueType::DOUBLE).
mrMemory resource.
Returns
rows x cols matrix of ones.

◆ ones() [2/2]

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.

Parameters
dimsDimensions of the target matrix or N-D array.
dtypeData type of elements (default: ValueType::DOUBLE).
mrMemory resource.
Returns
Array filled with ones of the requested shape and type.
See also
zeros, eye

◆ paddata() [1/2]

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)).

Parameters
xInput array.
lenTarget length.
dimOperating dimension.
sideDirection ("left", "right").
mrMemory resource.
Returns
Padded array.

◆ paddata() [2/2]

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)).

Parameters
xInput array.
lenTarget length.
mrMemory resource.
Returns
Padded array.
See also
trimdata

◆ pagectranspose()

Value nk::builtin::pagectranspose ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Page-wise complex conjugate transpose of N-D array (pagectranspose(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Array with first two dimensions conjugate transposed per page.

◆ pagetranspose()

Value nk::builtin::pagetranspose ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Page-wise transpose of N-D array (pagetranspose(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Array with first two dimensions transposed per page.

◆ pascal() [1/2]

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)).

Parameters
nOrder of the matrix.
kForm selector (0=symmetric, 1=lower triangular, 2=upper triangular Cholesky factor).
mrMemory resource.
Returns
n x n Pascal matrix.

◆ pascal() [2/2]

Value nk::builtin::pascal ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates a Pascal matrix of order n.

Parameters
nOrder of the matrix.
mrMemory resource.
Returns
n x n symmetric Pascal matrix.

◆ peaks()

Value nk::builtin::peaks ( size_t n = 49,
std::pmr::memory_resource * mr = nullptr )

Generates peaks example surface function matrix (peaks(n)).

Parameters
nOrder of the square matrix (default: 49).
mrMemory resource.
Returns
n x n peaks matrix.

◆ permute() [1/2]

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)).

Parameters
xInput array.
orderDimension permutation order vector (1-based).
mrMemory resource.
Returns
Permuted array.
See also
ipermute

◆ permute() [2/2]

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.

Parameters
xInput array.
order1-based dimension indices.
mrMemory resource.
Returns
Permuted array.

◆ repelem() [1/5]

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)).

Parameters
xInput vector.
countsRepetition counts vector.
mrMemory resource.
Returns
Expanded vector.

◆ repelem() [2/5]

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)).

Parameters
xInput matrix.
rCountsRow repeat counts vector.
cCountsColumn repeat counts vector.
mrMemory resource.
Returns
Expanded matrix.

◆ repelem() [3/5]

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)).

Parameters
xInput matrix.
mRow repetition factor.
nColumn repetition factor.
mrMemory resource.
Returns
Expanded matrix.

◆ repelem() [4/5]

Value nk::builtin::repelem ( const Value & x,
size_t n,
std::pmr::memory_resource * mr = nullptr )

Repeats elements of array uniformly (repelem(x, n)).

Parameters
xInput array.
nRepetition count per element.
mrMemory resource.
Returns
Array with repeated elements.

◆ repelem() [5/5]

Value nk::builtin::repelem ( const Value & x,
Span< const size_t > reps,
std::pmr::memory_resource * mr = nullptr )

Repeats elements of an array.

Parameters
xInput array.
repsRepetition factors per dimension.
mrMemory resource.
Returns
Array with repeated elements.

◆ repmat() [1/3]

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)).

Parameters
xInput array.
rRow repetition factor.
cColumn repetition factor.
pPage repetition factor.
mrMemory resource.
Returns
3-D tiled array.

◆ repmat() [2/3]

Value nk::builtin::repmat ( const Value & x,
size_t r,
size_t c,
std::pmr::memory_resource * mr = nullptr )

2D convenience overload for repmat.

Parameters
xInput array.
rRow repetition factor.
cColumn repetition factor.
mrMemory resource.
Returns
2-D tiled array.

◆ repmat() [3/3]

Value nk::builtin::repmat ( const Value & x,
Span< const size_t > reps,
std::pmr::memory_resource * mr = nullptr )

Replicates and tiles an array.

Parameters
xInput array.
repsRepetition factors along each dimension.
mrMemory resource.
Returns
Tiled array.
See also
repelem, reshape

◆ repmatND()

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.

Parameters
xInput array.
tilesSpan of repetition counts.
mrMemory resource.
Returns
N-D tiled array.
Tiled array.

◆ reshape() [1/2]

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.

Parameters
xInput array.
rowsTarget row count.
colsTarget column count.
pagesTarget page count (0 for 2-D).
mrMemory resource.
Returns
Reshaped array.

◆ reshape() [2/2]

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.

Parameters
xInput array.
newDimsTarget shape.
mrMemory resource.
Returns
Reshaped array (shares buffer COW when possible).

◆ resize()

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)).

Parameters
vInput vector.
nTarget length.
mrMemory resource.
Returns
Resized vector.

◆ rosser()

Value nk::builtin::rosser ( std::pmr::memory_resource * mr = nullptr)

Generates Rosser's test matrix (8x8 symmetric with exact eigenvalues).

Parameters
mrMemory resource.
Returns
8x8 Rosser matrix.

◆ rot90()

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.

Parameters
xInput 2D matrix.
kNumber of 90-degree rotations (default: 1).
mrMemory resource.
Returns
Rotated matrix.

◆ shiftdim()

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)).

Parameters
xInput array.
nNumber of shifts (positive shifts left, negative shifts right / adds singletons).
mrMemory resource.
Returns
Shifted array.
See also
shiftdimAuto, squeeze

◆ shiftdimAuto()

ShiftDimAuto nk::builtin::shiftdimAuto ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Automatically shifts out leading singleton dimensions (shiftdim(x)).

Parameters
xInput array.
mrMemory resource.
Returns
ShiftDimAuto struct with shifted array and number of dropped dimensions.

◆ size() [1/2]

Value nk::builtin::size ( const Value & x,
int dim,
std::pmr::memory_resource * mr = nullptr )

Returns length of specified dimension (size(x, dim)).

Parameters
xInput array.
dim1-based dimension index.
mrMemory resource.
Returns
Dimension length scalar.

◆ size() [2/2]

Value nk::builtin::size ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Returns array dimensions as a row vector (size(x)).

Parameters
xInput array.
mrMemory resource.
Returns
1 x D vector of dimension lengths.

◆ sort()

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)).

Parameters
xInput array.
dimOperating dimension (0 for first non-singleton).
descendTrue for descending order.
nanPlaceNaN positioning rule.
mrMemory resource.
Returns
Tuple containing {sorted_values, sort_indices}.
See also
sortrows, issorted

◆ sortrows() [1/3]

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)).

Parameters
xInput 2-D matrix.
colsColumn indices.
descDescending flags per column.
mrMemory resource.
Returns
Tuple containing {sorted_matrix, sort_indices}.

◆ sortrows() [2/3]

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)).

Parameters
xInput 2-D matrix.
cols1-based column indices.
mrMemory resource.
Returns
Tuple containing {sorted_matrix, sort_indices}.

◆ sortrows() [3/3]

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)).

Parameters
xInput 2-D matrix.
mrMemory resource.
Returns
Tuple containing {sorted_matrix, sort_indices}.
See also
sort

◆ sphere()

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)).

Parameters
nNumber of facets (default: 20).
mrMemory resource.
Returns
Surface3 struct.

◆ squeeze()

Value nk::builtin::squeeze ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Removes singleton dimensions from an array.

Parameters
xInput array.
mrMemory resource.
Returns
Squeezed array.

◆ sub2ind()

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, ...)).

Parameters
sizArray size vector.
subsSubscript index values.
mrMemory resource.
Returns
Linear index array.
See also
ind2sub

◆ tail()

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.

Parameters
xInput array.
kNumber of rows/elements (default: 8).
mrMemory resource.
Returns
Subarray containing bottom elements.
See also
head

◆ toeplitz()

Value nk::builtin::toeplitz ( const Value & c,
const Value & r = Value(),
std::pmr::memory_resource * mr = nullptr )

Creates a Toeplitz matrix.

Parameters
cFirst column vector.
rFirst row vector (optional, defaults to c).
mrMemory resource.
Returns
Toeplitz matrix formed from c and r.

◆ topkrows()

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)).

Parameters
xInput matrix.
kNumber of rows to return.
colsColumn indices.
descDescending flags.
mrMemory resource.
Returns
Tuple containing {top_k_rows, indices}.

◆ tril()

Value nk::builtin::tril ( const Value & x,
int k = 0,
std::pmr::memory_resource * mr = nullptr )

Extracts lower triangular part of a matrix.

Parameters
xInput matrix.
kDiagonal offset (0=main, >0=above, <0=below).
mrMemory resource.
Returns
Lower triangular matrix.
See also
triu

◆ trimdata() [1/2]

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)).

Parameters
xInput array.
lenTarget length.
dimOperating dimension.
sideDirection ("left", "right").
mrMemory resource.
Returns
Trimmed array.

◆ trimdata() [2/2]

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)).

Parameters
xInput array.
lenTarget length.
mrMemory resource.
Returns
Trimmed array.
See also
paddata

◆ triu()

Value nk::builtin::triu ( const Value & x,
int k = 0,
std::pmr::memory_resource * mr = nullptr )

Extracts upper triangular part of a matrix.

Parameters
xInput matrix.
kDiagonal offset (0=main, >0=above, <0=below).
mrMemory resource.
Returns
Upper triangular matrix.
See also
tril

◆ vander()

Value nk::builtin::vander ( const Value & v,
std::pmr::memory_resource * mr = nullptr )

Creates a Vandermonde matrix.

Parameters
vInput vector of points.
mrMemory resource.
Returns
Vandermonde matrix whose columns are powers of v.

◆ vertcat()

Value nk::builtin::vertcat ( Span< const Value > arrays,
std::pmr::memory_resource * mr = nullptr )

Concatenates arrays vertically (along rows, dim 1).

Parameters
arraysList of arrays.
mrMemory resource.
Returns
Vertically concatenated array.

◆ wilkinson()

Value nk::builtin::wilkinson ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates a Wilkinson eigenvalue test matrix.

Parameters
nOrder of the matrix (must be odd).
mrMemory resource.
Returns
n x n tridiagonal Wilkinson matrix.

◆ xorOf()

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)).

Parameters
aFirst array.
bSecond array.
mrMemory resource.
Returns
Logical array where true indicates either a or b is nonzero, but not both.

◆ zeros() [1/2]

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.

Parameters
rowsNumber of rows.
colsNumber of columns.
dtypeData type (default: ValueType::DOUBLE).
mrMemory resource.
Returns
rows x cols matrix of zeros.

◆ zeros() [2/2]

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.

Parameters
dimsDimensions of the target matrix or N-D array.
dtypeData type of elements (default: ValueType::DOUBLE).
mrMemory resource for allocations (nullptr for default).
Returns
Array filled with zeros of the requested shape and type.
auto Z = nk::builtin::zeros({3, 3});
Value zeros(Span< const size_t > dims, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr)
Creates an array filled with zeros.
See also
ones, eye