6#include <memory_resource>
10#include <nk/value/value.hpp>
11#include <nk/value/span.hpp>
13namespace nk::builtin {
53Value zeros(
size_t rows,
size_t cols, ValueType dtype = ValueType::DOUBLE, std::pmr::memory_resource *mr =
nullptr);
69Value ones(
size_t rows,
size_t cols, ValueType dtype = ValueType::DOUBLE, std::pmr::memory_resource *mr =
nullptr);
75Value eye(
size_t n, std::pmr::memory_resource *mr =
nullptr);
82Value eye(
size_t m,
size_t n, std::pmr::memory_resource *mr =
nullptr);
89Value eye(
size_t n, ValueType dtype, std::pmr::memory_resource *mr =
nullptr);
97Value eye(
size_t m,
size_t n, ValueType dtype, std::pmr::memory_resource *mr =
nullptr);
146Value peaks(
size_t n = 49, std::pmr::memory_resource *mr =
nullptr);
155Value linspace(
double a,
double b,
size_t n = 100, std::pmr::memory_resource *mr =
nullptr);
164Value logspace(
double a,
double b,
size_t n = 50, std::pmr::memory_resource *mr =
nullptr);
170Value magic(
size_t n, std::pmr::memory_resource *mr =
nullptr);
177Value hilb(
size_t n, std::pmr::memory_resource *mr =
nullptr);
197Value pascal(
size_t n,
int k, std::pmr::memory_resource *mr =
nullptr);
272Surface3 ellipsoid(
double xc,
double yc,
double zc,
double xr,
double yr,
double zr,
size_t n = 20, std::pmr::memory_resource *mr =
nullptr);
335Value repmat(
const Value &x,
size_t r,
size_t c,
size_t p, std::pmr::memory_resource *mr =
nullptr);
366Value reshape(
const Value &x,
size_t rows,
size_t cols,
size_t pages = 0, std::pmr::memory_resource *mr =
nullptr);
547Value head(
const Value &x,
size_t k = 8, std::pmr::memory_resource *mr =
nullptr);
555Value tail(
const Value &x,
size_t k = 8, std::pmr::memory_resource *mr =
nullptr);
572Value paddata(
const Value &x,
size_t len,
int dim,
const std::string &side =
"right", std::pmr::memory_resource *mr =
nullptr);
589Value trimdata(
const Value &x,
size_t len,
int dim,
const std::string &side =
"right", std::pmr::memory_resource *mr =
nullptr);
613std::vector<Value>
ind2sub(
const Value &siz,
const Value &ind,
size_t nout = 0, std::pmr::memory_resource *mr =
nullptr);
661std::tuple<Value, Value>
sortrows(
const Value &x, std::pmr::memory_resource *mr =
nullptr);
684Value issorted(
const Value &x,
int dim = 0,
bool descend =
false, std::pmr::memory_resource *mr =
nullptr);
Core MATLAB-compatible multidimensional array and scalar value type.
Value issorted(const Value &x, const Value &mode=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Determines if array elements are sorted in ascending or descending order (issorted(x,...
Value linspace(double a, double b, size_t n=100, std::pmr::memory_resource *mr=nullptr)
Generates linearly spaced vector between a and b.
Value tail(const Value &x, size_t k=8, std::pmr::memory_resource *mr=nullptr)
Returns the bottom k rows or elements of an array.
Surface3 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,...
Value peaks(size_t n=49, std::pmr::memory_resource *mr=nullptr)
Generates peaks example surface function matrix (peaks(n)).
Value hilb(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates a Hilbert matrix of order n.
ShiftDimAuto shiftdimAuto(const Value &x, std::pmr::memory_resource *mr=nullptr)
Automatically shifts out leading singleton dimensions (shiftdim(x)).
Value head(const Value &x, size_t k=8, std::pmr::memory_resource *mr=nullptr)
Returns the top k rows or elements of an array.
Surface3 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)).
Value 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 vertcat(Span< const Value > arrays, std::pmr::memory_resource *mr=nullptr)
Concatenates arrays vertically (along rows, dim 1).
Value shiftdim(const Value &x, int n=0, std::pmr::memory_resource *mr=nullptr)
Shifts dimensions of array by n steps (shiftdim(x, n)).
Value ipermute(const Value &x, Span< const int > order, std::pmr::memory_resource *mr=nullptr)
Inverse permutes dimensions of an N-D array.
Value size(const Value &x, std::pmr::memory_resource *mr=nullptr)
Returns array dimensions as a row vector (size(x)).
Value 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 fliplr(const Value &x, std::pmr::memory_resource *mr=nullptr)
Flips matrix left-to-right (along columns).
Value pagetranspose(const Value &x, std::pmr::memory_resource *mr=nullptr)
Page-wise transpose of N-D array (pagetranspose(x)).
Value find(const Value &x, std::pmr::memory_resource *mr=nullptr)
Finds indices of non-zero array elements (find(x)).
Value toeplitz(const Value &c, const Value &r=Value(), std::pmr::memory_resource *mr=nullptr)
Creates a Toeplitz matrix.
Value repmat(const Value &x, Span< const size_t > reps, std::pmr::memory_resource *mr=nullptr)
Replicates and tiles an array.
Value rot90(const Value &x, int k=1, std::pmr::memory_resource *mr=nullptr)
Rotates a 2D matrix by 90 degrees counterclockwise k times.
Value 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 hadamard(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates a Hadamard matrix of order n.
Value 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 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 circshiftND(const Value &x, Span< const int64_t > shifts, std::pmr::memory_resource *mr=nullptr)
Circularly shifts elements of N-D array.
std::tuple< Value, Value > 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 nnz(const Value &x, std::pmr::memory_resource *mr=nullptr)
Number of non-zero matrix elements (nnz(x)).
Value pascal(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates a Pascal matrix of order n.
NanPlace
Placement policy for NaN elements during sorting.
std::vector< Value > 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 magic(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates an n-by-n magic square.
Surface3 sphere(size_t n=20, std::pmr::memory_resource *mr=nullptr)
Generates 3-D unit sphere surface coordinates ([X,Y,Z] = sphere(n)).
Value compan(const Value &p, std::pmr::memory_resource *mr=nullptr)
Creates companion matrix of polynomial coefficients (compan(p)).
Value horzcat(Span< const Value > arrays, std::pmr::memory_resource *mr=nullptr)
Concatenates arrays horizontally (along columns, dim 2).
Value numel(const Value &x, std::pmr::memory_resource *mr=nullptr)
Number of array elements (numel(x)).
std::tuple< Value, Value > Meshgrid2D
Result of 2D grid generation via meshgrid/ndgrid.
std::tuple< Value, Value, Value > Meshgrid3D
Result of 3D grid generation via meshgrid/ndgrid.
Value flipud(const Value &x, std::pmr::memory_resource *mr=nullptr)
Flips matrix up-to-down (along rows).
Meshgrid2D meshgrid(const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
2-D meshgrid ([X, Y] = meshgrid(x, y)).
Value hankel(const Value &c, const Value &r=Value(), std::pmr::memory_resource *mr=nullptr)
Creates a Hankel matrix.
Value repmatND(const Value &x, Span< const size_t > tiles, std::pmr::memory_resource *mr=nullptr)
N-D array tiling overload for repmat.
std::tuple< Value, Value > 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)).
Value nonzeros(const Value &x, std::pmr::memory_resource *mr=nullptr)
Non-zero elements of matrix as column vector (nonzeros(x)).
Value sub2ind(const Value &siz, Span< const Value > subs, std::pmr::memory_resource *mr=nullptr)
Converts subscript indices to linear index (sub2ind(siz, i, j, ...)).
Value cat(int dim, Span< const Value > arrays, std::pmr::memory_resource *mr=nullptr)
Concatenates arrays along dimension dim.
Value blkdiag(Span< const Value > matrices, std::pmr::memory_resource *mr=nullptr)
Constructs a block diagonal matrix from input matrices.
Value invhilb(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates an exact inverse Hilbert matrix of order n.
std::tuple< Value, Value > sortrows(const Value &x, std::pmr::memory_resource *mr=nullptr)
Sorts rows of 2-D matrix in ascending order ([B, I] = sortrows(x)).
Value length(const Value &x, std::pmr::memory_resource *mr=nullptr)
Length of largest array dimension (length(x)).
Value zeros(Span< const size_t > dims, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr)
Creates an array filled with zeros.
Value 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 ones(Span< const size_t > dims, ValueType dtype=ValueType::DOUBLE, std::pmr::memory_resource *mr=nullptr)
Creates an array filled with ones.
Value flip(const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
Reverses the order of elements along specified dimension.
Value pagectranspose(const Value &x, std::pmr::memory_resource *mr=nullptr)
Page-wise complex conjugate transpose of N-D array (pagectranspose(x)).
Value tril(const Value &x, int k=0, std::pmr::memory_resource *mr=nullptr)
Extracts lower triangular part of a matrix.
Value ndims(const Value &x, std::pmr::memory_resource *mr=nullptr)
Number of array dimensions (ndims(x)).
Meshgrid2D ndgrid(const Value &x, const Value &y, std::pmr::memory_resource *mr=nullptr)
2-D N-D grid ([X, Y] = ndgrid(x, y)).
Value wilkinson(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates a Wilkinson eigenvalue test matrix.
Value diag(const Value &x, int k=0, std::pmr::memory_resource *mr=nullptr)
Extracts diagonal or builds a diagonal matrix.
Value eye(size_t n, std::pmr::memory_resource *mr=nullptr)
Creates an identity matrix of size n x n (eye(n)).
Value triu(const Value &x, int k=0, std::pmr::memory_resource *mr=nullptr)
Extracts upper triangular part of a matrix.
Value repelem(const Value &x, Span< const size_t > reps, std::pmr::memory_resource *mr=nullptr)
Repeats elements of an array.
Value 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,...
Value xorOf(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Logical exclusive OR of two arrays (xor(a, b)).
Value rosser(std::pmr::memory_resource *mr=nullptr)
Generates Rosser's test matrix (8x8 symmetric with exact eigenvalues).
Value squeeze(const Value &x, std::pmr::memory_resource *mr=nullptr)
Removes singleton dimensions from an array.
Value vander(const Value &v, std::pmr::memory_resource *mr=nullptr)
Creates a Vandermonde matrix.
Value trimdata(const Value &x, size_t len, std::pmr::memory_resource *mr=nullptr)
Trims data array to specified length (trimdata(x, len)).
Value issortedrows(const Value &x, std::pmr::memory_resource *mr=nullptr)
Tests if rows of 2-D matrix are sorted in ascending order (issortedrows(x)).
@ Auto
Put NaNs at the end.
@ First
Put NaNs at the beginning.
@ Last
Put NaNs at the end.
Result of automatic dimension shift (shiftdim(x)).
int dropped
Number of leading singleton dimensions removed.
3-D surface mesh grid coordinate triple.