nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
datatypes.hpp
Go to the documentation of this file.
1// src/builtin/include/nk/builtin/datatypes.hpp
2//
3// Pure C++ Data types: cells, structures, type predicates, conversions, limits.
4#pragma once
5
6#include <memory_resource>
7#include <string>
8#include <vector>
9#include <nk/value/value.hpp>
10#include <nk/value/span.hpp>
11
12namespace nk::builtin {
13
16
17
24
25// ── Structure Manipulation ──────────────────────────────────────────────────
26
33Value isfield(const Value &s, const std::string &field, std::pmr::memory_resource *mr = nullptr);
34
41Value getfield(const Value &s, const std::string &field, std::pmr::memory_resource *mr = nullptr);
42
50Value setfield(const Value &s, const std::string &field, const Value &val, std::pmr::memory_resource *mr = nullptr);
51
57Value rmfield(const Value &s, const std::string &field, std::pmr::memory_resource *mr = nullptr);
58
63Value toDouble(const Value &x, std::pmr::memory_resource *mr = nullptr);
64
69Value single(const Value &x, std::pmr::memory_resource *mr = nullptr);
70
75Value int8(const Value &x, std::pmr::memory_resource *mr = nullptr);
76
81Value int16(const Value &x, std::pmr::memory_resource *mr = nullptr);
82
87Value int32(const Value &x, std::pmr::memory_resource *mr = nullptr);
88
93Value int64(const Value &x, std::pmr::memory_resource *mr = nullptr);
94
99Value uint8(const Value &x, std::pmr::memory_resource *mr = nullptr);
100
105Value uint16(const Value &x, std::pmr::memory_resource *mr = nullptr);
106
111Value uint32(const Value &x, std::pmr::memory_resource *mr = nullptr);
112
117Value uint64(const Value &x, std::pmr::memory_resource *mr = nullptr);
118
123Value logical(const Value &x, std::pmr::memory_resource *mr = nullptr);
124
125// ── Type Predicates & Introspection ─────────────────────────────────────────
126
132Value iscell(const Value &v, std::pmr::memory_resource *mr = nullptr);
133
139Value isstruct(const Value &v, std::pmr::memory_resource *mr = nullptr);
140
146Value isnumeric(const Value &v, std::pmr::memory_resource *mr = nullptr);
147
153Value isfloat(const Value &v, std::pmr::memory_resource *mr = nullptr);
154
160Value isinteger(const Value &v, std::pmr::memory_resource *mr = nullptr);
161
166Value islogical(const Value &v, std::pmr::memory_resource *mr = nullptr);
167
173Value ischar(const Value &v, std::pmr::memory_resource *mr = nullptr);
174
180Value isstring(const Value &v, std::pmr::memory_resource *mr = nullptr);
181
187Value isnan(const Value &v, std::pmr::memory_resource *mr = nullptr);
188
194Value isinf(const Value &v, std::pmr::memory_resource *mr = nullptr);
195
201Value isfinite(const Value &v, std::pmr::memory_resource *mr = nullptr);
202
207Value isempty(const Value &v, std::pmr::memory_resource *mr = nullptr);
208
214Value isscalar(const Value &v, std::pmr::memory_resource *mr = nullptr);
215
221Value isvector(const Value &v, std::pmr::memory_resource *mr = nullptr);
222
228Value isrow(const Value &v, std::pmr::memory_resource *mr = nullptr);
229
235Value iscolumn(const Value &v, std::pmr::memory_resource *mr = nullptr);
236
242Value ismatrix(const Value &v, std::pmr::memory_resource *mr = nullptr);
243
248Value issingle(const Value &x, std::pmr::memory_resource *mr = nullptr);
249
254Value issparse(const Value &x, std::pmr::memory_resource *mr = nullptr);
255
260Value ismissing(const Value &x, std::pmr::memory_resource *mr = nullptr);
261
267Value ismissing(const Value &x, const Value &indicator, std::pmr::memory_resource *mr = nullptr);
268
274Value issorted(const Value &x, const Value &mode = Value::Empty, std::pmr::memory_resource *mr = nullptr);
275
282Value isequal(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
283
290Value isequaln(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
291
292// ── Type Conversion & Limits ────────────────────────────────────────────────
293
299Value cast(const Value &v, const std::string &targetType, std::pmr::memory_resource *mr = nullptr);
300
306Value standardizeMissing(const Value &x, const Value &indicator, std::pmr::memory_resource *mr = nullptr);
307
312Value anymissing(const Value &x, std::pmr::memory_resource *mr = nullptr);
313
318Value isuniform(const Value &x, std::pmr::memory_resource *mr = nullptr);
319
324Value classOf(const Value &x, std::pmr::memory_resource *mr = nullptr);
325
330Value swapbytes(const Value &x, std::pmr::memory_resource *mr = nullptr);
331
337Value typecast(const Value &x, const std::string &datatype, std::pmr::memory_resource *mr = nullptr);
338
343Value allfinite(const Value &x, std::pmr::memory_resource *mr = nullptr);
344
349Value anynan(const Value &x, std::pmr::memory_resource *mr = nullptr);
350
356Value realmin(const std::string &className = "double", std::pmr::memory_resource *mr = nullptr);
357
362Value realmin(const Value &t, std::pmr::memory_resource *mr = nullptr);
363
369Value realmax(const std::string &className = "double", std::pmr::memory_resource *mr = nullptr);
370
375Value realmax(const Value &t, std::pmr::memory_resource *mr = nullptr);
376
382Value intmin(const std::string &className = "int32", std::pmr::memory_resource *mr = nullptr);
383
388Value intmin(const Value &t, std::pmr::memory_resource *mr = nullptr);
389
395Value intmax(const std::string &className = "int32", std::pmr::memory_resource *mr = nullptr);
396
401Value intmax(const Value &t, std::pmr::memory_resource *mr = nullptr);
402
407Value flintmax(const std::string &className = "double", std::pmr::memory_resource *mr = nullptr);
408
413Value flintmax(const Value &t, std::pmr::memory_resource *mr = nullptr);
414
415
417} // namespace nk::builtin
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
static const Value Empty
MATLAB-style empty matrix sentinel — a 0×0 DOUBLE value.
Definition value.hpp:136
Value isfloat(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a floating-point type (single or double) (isfloat(v)).
Value isscalar(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a 1x1 scalar (isscalar(v)).
Value isinf(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests array elements for Infinity (isinf(v)).
Value standardizeMissing(const Value &x, const Value &indicator, std::pmr::memory_resource *mr=nullptr)
Replaces specified indicator values with standard missing values (standardizeMissing(x,...
Value uint16(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 16-bit unsigned integer (uint16(x)).
Value uint8(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 8-bit unsigned integer (uint8(x)).
Value flintmax(const std::string &className="double", std::pmr::memory_resource *mr=nullptr)
Largest consecutive integer accurately representable in floating-point format (flintmax(className)).
Value iscell(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a cell array (iscell(v)).
Value isinteger(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is an integer class (isinteger(v)).
Value isvector(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a 1-D vector (1xN or Nx1) (isvector(v)).
Value islogical(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is logical type (islogical(v)).
Value issingle(const Value &x, std::pmr::memory_resource *mr=nullptr)
Tests if input is single-precision floating point (issingle(x)).
Value isnan(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests array elements for NaN (isnan(v)).
Value cast(const Value &v, const std::string &targetType, std::pmr::memory_resource *mr=nullptr)
Casts input array to target type name (cast(v, targetType)).
Value typecast(const Value &x, const std::string &datatype, std::pmr::memory_resource *mr=nullptr)
Reinterprets binary data between datatypes without changing underlying bytes (typecast(x,...
Value int8(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 8-bit signed integer (int8(x)).
Value swapbytes(const Value &x, std::pmr::memory_resource *mr=nullptr)
Swaps byte order of array elements between little-endian and big-endian (swapbytes(x)).
Value int16(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 16-bit signed integer (int16(x)).
Value setfield(const Value &s, const std::string &field, const Value &val, std::pmr::memory_resource *mr=nullptr)
Sets value of structure field by string name (setfield(s, field, val)).
Value realmax(const std::string &className="double", std::pmr::memory_resource *mr=nullptr)
Largest finite floating-point number (realmax(className)).
Value isfield(const Value &s, const std::string &field, std::pmr::memory_resource *mr=nullptr)
Tests if structure contains field by string name (isfield(s, field)).
Value anynan(const Value &x, std::pmr::memory_resource *mr=nullptr)
True if any array element is NaN (anynan(x)).
Value isstruct(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a structure (isstruct(v)).
Value isnumeric(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is numeric (double, single, integer) (isnumeric(v)).
Value isrow(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a 1xN row vector (isrow(v)).
Value logical(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to logical boolean array (logical(x)).
Value rmfield(const Value &s, const std::string &field, std::pmr::memory_resource *mr=nullptr)
Removes field from structure by string name (rmfield(s, field)).
Value isfinite(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests array elements for finiteness (isfinite(v)).
Value allfinite(const Value &x, std::pmr::memory_resource *mr=nullptr)
True if all elements are finite numbers (allfinite(x)).
Value intmax(const std::string &className="int32", std::pmr::memory_resource *mr=nullptr)
Largest integer value for specified integer class (intmax(className)).
Value ismissing(const Value &x, std::pmr::memory_resource *mr=nullptr)
Finds missing entries in array using default standard missing indicators (ismissing(x)).
Value intmin(const std::string &className="int32", std::pmr::memory_resource *mr=nullptr)
Smallest integer value for specified integer class (intmin(className)).
Value issparse(const Value &x, std::pmr::memory_resource *mr=nullptr)
Tests if input is a sparse array (issparse(x)).
Value ismatrix(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is a 2-D matrix (ismatrix(v)).
Value isstring(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is string array (isstring(v)).
Value anymissing(const Value &x, std::pmr::memory_resource *mr=nullptr)
Tests if array contains any missing entries (anymissing(x)).
Value isequal(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Determines if arrays are strictly identical in type, shape, and values (isequal(a,...
Value single(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to single-precision floating point (single(x)).
Value isuniform(const Value &x, std::pmr::memory_resource *mr=nullptr)
Tests if array has uniform element spacing (isuniform(x)).
Value isempty(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if array is empty (any dimension is 0) (isempty(v)).
Value iscolumn(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is an Nx1 column vector (iscolumn(v)).
Value int32(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 32-bit signed integer (int32(x)).
Value ischar(const Value &v, std::pmr::memory_resource *mr=nullptr)
Tests if input is character array (ischar(v)).
Value isequaln(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Determines if arrays are equal, treating NaNs as equal (isequaln(a, b)).
Value uint32(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 32-bit unsigned integer (uint32(x)).
Value getfield(const Value &s, const std::string &field, std::pmr::memory_resource *mr=nullptr)
Gets value of structure field by string name (getfield(s, field)).
Value int64(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 64-bit signed integer (int64(x)).
Value classOf(const Value &x, std::pmr::memory_resource *mr=nullptr)
Returns the class name of an object or array (class(x)).
Value uint64(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to 64-bit unsigned integer (uint64(x)).
Value realmin(const std::string &className="double", std::pmr::memory_resource *mr=nullptr)
Smallest positive normalized floating-point number (realmin(className)).
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 toDouble(const Value &x, std::pmr::memory_resource *mr=nullptr)
Converts input array to double-precision floating point (double(x)).