nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Data Analysis and Fourier Transforms (datafun)

Reductions, basic summary statistics, cumulative operations, numerical differences, 1D/2D/N-D Fourier transforms, and accumarray. More...

Files

file  datafun.hpp
 Data analysis, reductions, search, set operations, and random distributions.

Classes

struct  nk::builtin::HistBinSpec
 Specification for automatic histogram bin estimation. More...
struct  nk::builtin::FindgroupsResult
 Result of findgroups — [G, ID]. More...
struct  nk::builtin::GroupcountsResult
 Result of groupcounts — [C, GR, P]. More...
struct  nk::builtin::GroupsummaryResult
 Result of the array form of groupsummary — [B, BG, BC]. More...

Enumerations

enum class  nk::builtin::HistBinMethod {
  Auto , Scott , Fd , Integers ,
  Sturges , Sqrt
}
 Binning method for histograms. More...
enum class  nk::builtin::HistNorm {
  Count , Probability , CountDensity , Pdf ,
  CumCount , Cdf
}
 Histogram normalization type. More...
enum class  nk::builtin::AccumReducer {
  AccumReducer::Sum , AccumReducer::Max , AccumReducer::Min , AccumReducer::Prod ,
  AccumReducer::Mean , AccumReducer::Any , AccumReducer::All
}
 Built-in reducers recognised by accumarray. More...

Functions

Value nk::builtin::sum (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Sum of array elements along first non-singleton dimension (sum(x)).
Value nk::builtin::sum (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Sum of array elements along specified dimension (sum(x, dim)).
Value nk::builtin::prod (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Product of array elements along first non-singleton dimension (prod(x)).
Value nk::builtin::prod (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Product of array elements along specified dimension (prod(x, dim)).
Value nk::builtin::mean (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Mean (arithmetic average) of array elements (mean(x)).
Value nk::builtin::mean (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Mean (arithmetic average) of array elements along dimension (mean(x, dim)).
std::tuple< Value, Value > nk::builtin::max (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Largest elements in array.
std::tuple< Value, Value > nk::builtin::max (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Largest elements in array along specified dimension ([M, I] = max(x, [], dim)).
Value nk::builtin::max (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Element-wise maximum of two arrays (max(a, b)).
std::tuple< Value, Value > nk::builtin::maxOmitNan (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Largest elements in array along dimension omitting NaN values (max(x, [], dim, 'omitnan')).
Value nk::builtin::maxOmitNanBinary (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Element-wise maximum of two arrays omitting NaNs (max(a, b, 'omitnan')).
std::tuple< Value, Value > nk::builtin::min (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Smallest elements in array.
std::tuple< Value, Value > nk::builtin::min (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Smallest elements in array along dimension ([M, I] = min(x, [], dim)).
Value nk::builtin::min (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Element-wise minimum of two arrays (min(a, b)).
std::tuple< Value, Value > nk::builtin::minOmitNan (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Smallest elements in array along dimension omitting NaNs (min(x, [], dim, 'omitnan')).
Value nk::builtin::minOmitNanBinary (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Element-wise minimum of two arrays omitting NaNs (min(a, b, 'omitnan')).
Value nk::builtin::cumsum (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Cumulative sum of array elements (cumsum(x)).
Value nk::builtin::cumsum (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Cumulative sum of array elements along specified dimension (cumsum(x, dim)).
Value nk::builtin::cumprod (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Cumulative product of array elements (cumprod(x)).
Value nk::builtin::cumprod (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Cumulative product of array elements along specified dimension (cumprod(x, dim)).
Value nk::builtin::cummax (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Cumulative maximum of array elements (cummax(x)).
Value nk::builtin::cummax (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Cumulative maximum of array elements along dimension (cummax(x, dim)).
Value nk::builtin::cummin (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Cumulative minimum of array elements (cummin(x)).
Value nk::builtin::cummin (const Value &x, int dim, std::pmr::memory_resource *mr=nullptr)
 Cumulative minimum of array elements along dimension (cummin(x, dim)).
Value nk::builtin::diff (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Differences between adjacent elements (diff(x)).
Value nk::builtin::diff (const Value &x, int n, int dim=0, std::pmr::memory_resource *mr=nullptr)
 Nth-order differences between elements along dimension (diff(x, n, dim)).
Value nk::builtin::anyOf (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 True if any element along dimension is nonzero (any(x, dim)).
Value nk::builtin::allOf (const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
 True if all elements along dimension are nonzero (all(x, dim)).
Value nk::builtin::unique (const Value &x, std::pmr::memory_resource *mr=nullptr, bool stable=false)
 Unique values in array (unique(x)).
Value nk::builtin::uniqueRows (const Value &x, std::pmr::memory_resource *mr=nullptr, bool stable=false)
 Unique rows of 2-D matrix (unique(x, 'rows')).
std::tuple< Value, Value, Value > nk::builtin::uniqueWithIndices (const Value &x, std::pmr::memory_resource *mr=nullptr, bool stable=false, bool last=false)
 Unique values with index mappings ([C, ia, ic] = unique(x)).
std::tuple< Value, Value, Value > nk::builtin::uniqueRowsWithIndices (const Value &x, std::pmr::memory_resource *mr=nullptr, bool stable=false, bool last=false)
 Unique rows with index mappings ([C, ia, ic] = unique(x, 'rows')).
Value nk::builtin::ismember (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Tests if array elements are members of set (ismember(a, b)).
std::pair< Value, Value > nk::builtin::ismemberComplex (const Value &a, const Value &b, bool wantLoc, std::pmr::memory_resource *mr)
 Tests membership for complex/general types with location indices ([lia, loc] = ismember(...)).
Value nk::builtin::setUnion (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr, bool stable=false)
 Set union of two arrays (union(a, b)).
Value nk::builtin::setIntersect (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr, bool stable=false)
 Set intersection of two arrays (intersect(a, b)).
Value nk::builtin::setDiff (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr, bool stable=false)
 Set difference (setdiff(a, b)).
Value nk::builtin::setxor (const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
 Set exclusive OR (setxor(a, b)).
Value nk::builtin::discretize (const Value &x, const Value &edges, std::pmr::memory_resource *mr=nullptr)
 Groups numeric data into bins (discretize(x, edges)).
Value nk::builtin::histc (const Value &x, const Value &edges, std::pmr::memory_resource *mr=nullptr)
 Histogram count of data into bins (histc(x, edges)).
Value nk::builtin::histcounts (const Value &x, const Value &edges, std::pmr::memory_resource *mr=nullptr)
 Computes histogram bin counts (histcounts(x, edges)).
Value nk::builtin::histcounts (const Value &x, const Value &edges, HistNorm norm, std::pmr::memory_resource *mr=nullptr)
 Computes normalized histogram bin values (histcounts(x, edges, norm)).
Value nk::builtin::histcountsAutoEdges (const Value &x, const HistBinSpec &spec, std::pmr::memory_resource *mr=nullptr)
 Computes histogram with automatic bin edges selection (histcounts(x, spec)).
Value nk::builtin::allunique (const Value &x, std::pmr::memory_resource *mr=nullptr)
 True if all elements in array are unique (allunique(x)).
Value nk::builtin::numunique (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Number of unique elements in array (numunique(x)).
Value nk::builtin::ismembertol (const Value &a, const Value &s, double tol=1e-6, std::pmr::memory_resource *mr=nullptr)
 Membership test within numerical tolerance (ismembertol(a, s, tol)).
Value nk::builtin::uniquetol (const Value &x, double tol=1e-6, std::pmr::memory_resource *mr=nullptr)
 Unique elements within numerical tolerance (uniquetol(x, tol)).
FindgroupsResult nk::builtin::findgroups (const Value &g, std::pmr::memory_resource *mr=nullptr)
 Assign 1-based group IDs ([G, ID] = findgroups(g)).
GroupcountsResult nk::builtin::groupcounts (const Value &g, std::pmr::memory_resource *mr=nullptr)
 Count elements per group ([C, GR, P] = groupcounts(g)).
GroupsummaryResult nk::builtin::groupsummary (const Value &A, const Value &G, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Per-group reduction ([B, BG, BC] = groupsummary(A, G, method)).
Value nk::builtin::grouptransform (const Value &A, const Value &G, const std::string &method, std::pmr::memory_resource *mr=nullptr)
 Group transformation (grouptransform(A, G, method)).
Value nk::builtin::accumarray (const Value &subs, const Value &vals, Span< const size_t > outShape, AccumReducer op=AccumReducer::Sum, double fillVal=0.0, std::pmr::memory_resource *mr=nullptr)
 Group-by reduction (A = accumarray(subs, vals, sz, fn, fillVal)).

Detailed Description

Reductions, basic summary statistics, cumulative operations, numerical differences, 1D/2D/N-D Fourier transforms, and accumarray.

Enumeration Type Documentation

◆ AccumReducer

enum class nk::builtin::AccumReducer
strong

Built-in reducers recognised by accumarray.

Enumerator
Sum 

@sum (additive identity 0).

Max 

@max.

Min 

@min.

Prod 

@prod (multiplicative identity 1).

Mean 

@mean.

Any 

@any (logical OR).

All 

@all (logical AND).

Definition at line 499 of file datafun.hpp.

◆ HistBinMethod

enum class nk::builtin::HistBinMethod
strong

Binning method for histograms.

Definition at line 240 of file datafun.hpp.

◆ HistNorm

enum class nk::builtin::HistNorm
strong

Histogram normalization type.

Definition at line 250 of file datafun.hpp.

Function Documentation

◆ accumarray()

Value nk::builtin::accumarray ( const Value & subs,
const Value & vals,
Span< const size_t > outShape,
AccumReducer op = AccumReducer::Sum,
double fillVal = 0.0,
std::pmr::memory_resource * mr = nullptr )

Group-by reduction (A = accumarray(subs, vals, sz, fn, fillVal)).

Each row of subs is a 1-based multi-dim index into the output A. vals(i) is contributed to A(subs(i, :)) via the reducer op. Output shape is outShape; pass empty span to auto-derive from max(subs) per column. Cells with no contributions get fillVal.

Parameters
subsN x D matrix of 1-based subscripts.
valsLength-N vector of contributions, or a scalar (broadcast).
outShapeOutput shape; empty span -> derive from max(subs).
opBuilt-in reducer (see AccumReducer).
fillValDefault value for untouched cells (default 0).
mrMemory resource (nullptr -> process default).
Returns
Accumulated output array of shape outShape.

◆ allOf()

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

True if all elements along dimension are nonzero (all(x, dim)).

Parameters
xInput array.
dimOperating dimension (0 for first non-singleton).
mrMemory resource.
Returns
Logical array.

◆ allunique()

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

True if all elements in array are unique (allunique(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Logical scalar.

◆ anyOf()

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

True if any element along dimension is nonzero (any(x, dim)).

Parameters
xInput array.
dimOperating dimension (0 for first non-singleton).
mrMemory resource.
Returns
Logical array.

◆ cummax() [1/2]

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

Cumulative maximum of array elements along dimension (cummax(x, dim)).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Cumulative maximum array.

◆ cummax() [2/2]

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

Cumulative maximum of array elements (cummax(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Cumulative maximum array.
See also
max, cummin

◆ cummin() [1/2]

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

Cumulative minimum of array elements along dimension (cummin(x, dim)).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Cumulative minimum array.

◆ cummin() [2/2]

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

Cumulative minimum of array elements (cummin(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Cumulative minimum array.
See also
min, cummax

◆ cumprod() [1/2]

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

Cumulative product of array elements along specified dimension (cumprod(x, dim)).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Cumulative product array.

◆ cumprod() [2/2]

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

Cumulative product of array elements (cumprod(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Cumulative product array.
See also
prod, cumsum

◆ cumsum() [1/2]

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

Cumulative sum of array elements along specified dimension (cumsum(x, dim)).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Cumulative sum array.

◆ cumsum() [2/2]

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

Cumulative sum of array elements (cumsum(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Cumulative sum array.
See also
sum, cumprod

◆ diff() [1/2]

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

Nth-order differences between elements along dimension (diff(x, n, dim)).

Parameters
xInput array.
nDifference order (default 1).
dimOperating dimension (default 0 for first non-singleton).
mrMemory resource.
Returns
Nth-order difference array.

◆ diff() [2/2]

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

Differences between adjacent elements (diff(x)).

Parameters
xInput array.
mrMemory resource.
Returns
First-order differences array.

◆ discretize()

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

Groups numeric data into bins (discretize(x, edges)).

Parameters
xData array.
edgesBin edges vector.
mrMemory resource.
Returns
Bin indices array.

◆ findgroups()

FindgroupsResult nk::builtin::findgroups ( const Value & g,
std::pmr::memory_resource * mr = nullptr )

Assign 1-based group IDs ([G, ID] = findgroups(g)).

G[i] is the group ID of g[i], based on the sorted-unique order of the finite values of g; ID is the column of those unique values. NaN entries are treated as missing (G[i] = NaN, excluded from ID), matching MATLAB R2025b. G takes the shape of g.

Parameters
gGrouping variable (numeric / logical / char).
mrMemory resource.
Returns
FindgroupsResult { G, ID }.
See also
groupcounts, groupsummary, grouptransform

◆ groupcounts()

GroupcountsResult nk::builtin::groupcounts ( const Value & g,
std::pmr::memory_resource * mr = nullptr )

Count elements per group ([C, GR, P] = groupcounts(g)).

C is the per-group element count over the sorted-unique values of g; GR the matching representatives; P the percentages. NaN entries form a single trailing bucket (matching MATLAB R2025b).

Parameters
gGrouping variable.
mrMemory resource.
Returns
GroupcountsResult { C, GR, P }.
See also
findgroups, groupsummary

◆ groupsummary()

GroupsummaryResult nk::builtin::groupsummary ( const Value & A,
const Value & G,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Per-group reduction ([B, BG, BC] = groupsummary(A, G, method)).

Groups the rows of A (length-size(A,1) grouping vector G) and applies method per group, per column. Supported method strings: "sum", "mean", "median", "max", "min", "std", "var", "numunique", "nnz", "mode", "all", "any". NaN group values form a single trailing bucket.

Parameters
AColumn vector or matrix (DOUBLE).
GGrouping vector, length size(A,1).
methodReduction method string.
mrMemory resource.
Returns
GroupsummaryResult { B, BG, BC }.
See also
findgroups, groupcounts, grouptransform

◆ grouptransform()

Value nk::builtin::grouptransform ( const Value & A,
const Value & G,
const std::string & method,
std::pmr::memory_resource * mr = nullptr )

Group transformation (grouptransform(A, G, method)).

Supported string methods: "meancenter", "zscore", "norm", "rescale", "meanfill", "linearfill".

Parameters
AColumn vector or matrix (DOUBLE).
GGrouping vector, length size(A,1).
methodTransformation method string.
mrMemory resource.
Returns
Transformed array with same shape as A.
See also
groupsummary, findgroups

◆ histc()

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

Histogram count of data into bins (histc(x, edges)).

Parameters
xData array.
edgesBin edges vector.
mrMemory resource.
Returns
Bin counts array.

◆ histcounts() [1/2]

Value nk::builtin::histcounts ( const Value & x,
const Value & edges,
HistNorm norm,
std::pmr::memory_resource * mr = nullptr )

Computes normalized histogram bin values (histcounts(x, edges, norm)).

Parameters
xData array.
edgesBin edges vector.
normNormalization scheme (Count, Probability, Pdf, etc.).
mrMemory resource.
Returns
Normalized bin values.

◆ histcounts() [2/2]

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

Computes histogram bin counts (histcounts(x, edges)).

Parameters
xData array.
edgesBin edges vector.
mrMemory resource.
Returns
Count of values in each bin.

◆ histcountsAutoEdges()

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

Computes histogram with automatic bin edges selection (histcounts(x, spec)).

Parameters
xData array.
specBin specification struct.
mrMemory resource.
Returns
Bin counts array.

◆ ismember()

Value nk::builtin::ismember ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Tests if array elements are members of set (ismember(a, b)).

Parameters
aQuery array.
bSet array.
mrMemory resource.
Returns
Logical array matching shape of a.
See also
unique, setIntersect

◆ ismemberComplex()

std::pair< Value, Value > nk::builtin::ismemberComplex ( const Value & a,
const Value & b,
bool wantLoc,
std::pmr::memory_resource * mr )

Tests membership for complex/general types with location indices ([lia, loc] = ismember(...)).

Parameters
aQuery array.
bSet array.
wantLocTrue to return matched index locations.
mrMemory resource.
Returns
Pair {lia, loc}.

◆ ismembertol()

Value nk::builtin::ismembertol ( const Value & a,
const Value & s,
double tol = 1e-6,
std::pmr::memory_resource * mr = nullptr )

Membership test within numerical tolerance (ismembertol(a, s, tol)).

Parameters
aQuery array.
sSet array.
tolRelative/absolute tolerance.
mrMemory resource.
Returns
Logical array.

◆ max() [1/3]

Value nk::builtin::max ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Element-wise maximum of two arrays (max(a, b)).

Parameters
aFirst array.
bSecond array.
mrMemory resource.
Returns
Element-wise maximum array.

◆ max() [2/3]

std::tuple< Value, Value > nk::builtin::max ( const Value & x,
int dim,
std::pmr::memory_resource * mr = nullptr )

Largest elements in array along specified dimension ([M, I] = max(x, [], dim)).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Tuple containing {max_values, max_indices}.

◆ max() [3/3]

std::tuple< Value, Value > nk::builtin::max ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Largest elements in array.

Returns tuple (values, indices) ([M, I] = max(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Tuple containing {max_values, max_indices}.
See also
min, maxOmitNan

◆ maxOmitNan()

std::tuple< Value, Value > nk::builtin::maxOmitNan ( const Value & x,
int dim,
std::pmr::memory_resource * mr = nullptr )

Largest elements in array along dimension omitting NaN values (max(x, [], dim, 'omitnan')).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Tuple containing {max_values, max_indices}.

◆ maxOmitNanBinary()

Value nk::builtin::maxOmitNanBinary ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Element-wise maximum of two arrays omitting NaNs (max(a, b, 'omitnan')).

Parameters
aFirst array.
bSecond array.
mrMemory resource.
Returns
Element-wise maximum.

◆ mean() [1/2]

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

Mean (arithmetic average) of array elements along dimension (mean(x, dim)).

Parameters
xInput array.
dimOperating dimension (1-based, 0 = first non-singleton).
mrMemory resource.
Returns
Mean array.
See also
sum, median

◆ mean() [2/2]

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

Mean (arithmetic average) of array elements (mean(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Mean array.
See also
sum, median

◆ min() [1/3]

Value nk::builtin::min ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Element-wise minimum of two arrays (min(a, b)).

Parameters
aFirst array.
bSecond array.
mrMemory resource.
Returns
Element-wise minimum.

◆ min() [2/3]

std::tuple< Value, Value > nk::builtin::min ( const Value & x,
int dim,
std::pmr::memory_resource * mr = nullptr )

Smallest elements in array along dimension ([M, I] = min(x, [], dim)).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Tuple containing {min_values, min_indices}.

◆ min() [3/3]

std::tuple< Value, Value > nk::builtin::min ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Smallest elements in array.

Returns tuple (values, indices) ([M, I] = min(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Tuple containing {min_values, min_indices}.
See also
max, minOmitNan

◆ minOmitNan()

std::tuple< Value, Value > nk::builtin::minOmitNan ( const Value & x,
int dim,
std::pmr::memory_resource * mr = nullptr )

Smallest elements in array along dimension omitting NaNs (min(x, [], dim, 'omitnan')).

Parameters
xInput array.
dimOperating dimension.
mrMemory resource.
Returns
Tuple containing {min_values, min_indices}.

◆ minOmitNanBinary()

Value nk::builtin::minOmitNanBinary ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Element-wise minimum of two arrays omitting NaNs (min(a, b, 'omitnan')).

Parameters
aFirst array.
bSecond array.
mrMemory resource.
Returns
Element-wise minimum.

◆ numunique()

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

Number of unique elements in array (numunique(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Count of distinct values.

◆ prod() [1/2]

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

Product of array elements along specified dimension (prod(x, dim)).

Parameters
xInput array.
dimDimension along which to operate (1-based, 0 = first non-singleton).
mrMemory resource.
Returns
Product array.
See also
sum, mean, cumprod

◆ prod() [2/2]

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

Product of array elements along first non-singleton dimension (prod(x)).

Parameters
xInput array.
mrMemory resource.
Returns
Product array.
See also
sum, mean, cumprod

◆ setDiff()

Value nk::builtin::setDiff ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr,
bool stable = false )

Set difference (setdiff(a, b)).

Parameters
aFirst set array.
bSecond set array.
mrMemory resource.
stableTrue to keep order.
Returns
Elements in a not in b.
See also
setUnion, setxor

◆ setIntersect()

Value nk::builtin::setIntersect ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr,
bool stable = false )

Set intersection of two arrays (intersect(a, b)).

Parameters
aFirst set array.
bSecond set array.
mrMemory resource.
stableTrue to keep order.
Returns
Common unique values.
See also
setUnion, setDiff

◆ setUnion()

Value nk::builtin::setUnion ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr,
bool stable = false )

Set union of two arrays (union(a, b)).

Parameters
aFirst set array.
bSecond set array.
mrMemory resource.
stableTrue to keep occurrence order.
Returns
Combined unique values.
See also
setIntersect, setDiff

◆ setxor()

Value nk::builtin::setxor ( const Value & a,
const Value & b,
std::pmr::memory_resource * mr = nullptr )

Set exclusive OR (setxor(a, b)).

Parameters
aFirst set array.
bSecond set array.
mrMemory resource.
Returns
Elements in either a or b but not both.
See also
setUnion, setIntersect

◆ sum() [1/2]

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

Sum of array elements along specified dimension (sum(x, dim)).

Parameters
xInput array.
dimDimension along which to sum (1-based, 0 = first non-singleton).
mrMemory resource.
Returns
Sum array.
See also
prod, mean, cumsum

◆ sum() [2/2]

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

Sum of array elements along first non-singleton dimension (sum(x)).

Parameters
xInput array.
mrMemory resource for allocations.
Returns
Sum array.
See also
prod, mean, cumsum

◆ unique()

Value nk::builtin::unique ( const Value & x,
std::pmr::memory_resource * mr = nullptr,
bool stable = false )

Unique values in array (unique(x)).

Parameters
xInput array.
mrMemory resource.
stableTrue to preserve original order, false to return sorted values.
Returns
Vector of unique values.
See also
ismember, setUnion

◆ uniqueRows()

Value nk::builtin::uniqueRows ( const Value & x,
std::pmr::memory_resource * mr = nullptr,
bool stable = false )

Unique rows of 2-D matrix (unique(x, 'rows')).

Parameters
x2-D matrix.
mrMemory resource.
stableTrue to preserve order.
Returns
Matrix containing unique rows.

◆ uniqueRowsWithIndices()

std::tuple< Value, Value, Value > nk::builtin::uniqueRowsWithIndices ( const Value & x,
std::pmr::memory_resource * mr = nullptr,
bool stable = false,
bool last = false )

Unique rows with index mappings ([C, ia, ic] = unique(x, 'rows')).

Parameters
x2-D matrix.
mrMemory resource.
stableTrue for occurrence ordering.
lastTrue to return last occurrence index.
Returns
Tuple containing {C, ia, ic}.

◆ uniquetol()

Value nk::builtin::uniquetol ( const Value & x,
double tol = 1e-6,
std::pmr::memory_resource * mr = nullptr )

Unique elements within numerical tolerance (uniquetol(x, tol)).

Parameters
xInput array.
tolRelative/absolute tolerance.
mrMemory resource.
Returns
Unique elements within tolerance.

◆ uniqueWithIndices()

std::tuple< Value, Value, Value > nk::builtin::uniqueWithIndices ( const Value & x,
std::pmr::memory_resource * mr = nullptr,
bool stable = false,
bool last = false )

Unique values with index mappings ([C, ia, ic] = unique(x)).

Parameters
xInput array.
mrMemory resource.
stableTrue for occurrence ordering.
lastTrue to return last occurrence index instead of first.
Returns
Tuple containing {C, ia, ic}.