nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
ops.hpp
Go to the documentation of this file.
1// include/nk/builtin/ops.hpp
2//
3// Arithmetic, relational, logical operators and array transformations (MATLAB parity).
4#pragma once
5
6#include <memory_resource>
7#include <nk/value/value.hpp>
8#include <nk/value/span.hpp>
9
10namespace nk::builtin {
11
14
15
22
23// ── Arithmetic Operations ───────────────────────────────────────────────────
24
35Value plus(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
36
46Value minus(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
47
57Value times(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
58
70Value mtimes(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
71
81Value rdivide(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
82
92Value ldivide(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
93
103Value mrdivide(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
104
114Value mldivide(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
115
126Value power(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
127
129Value elementPower(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
130
140Value mpower(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
141
150Value uplus(const Value &a, std::pmr::memory_resource *mr = nullptr);
151
161Value uminus(const Value &a, std::pmr::memory_resource *mr = nullptr);
162
169
179Value pagemtimes(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
180
188Value pagemtimes(const Value &x, TranspOp tx, const Value &y, TranspOp ty, std::pmr::memory_resource *mr = nullptr);
189
190// ── Relational & Comparison Operations ──────────────────────────────────────
191
201Value eq(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
202
212Value ne(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
213
223Value lt(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
224
234Value le(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
235
245Value gt(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
246
256Value ge(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
257
258// ── Logical Operations & Predicates ─────────────────────────────────────────
259
269Value logical_and(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
270
272inline Value and_op(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr)
273{
274 return logical_and(a, b, mr);
275}
276
286Value logical_or(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
287
289inline Value or_op(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr)
290{
291 return logical_or(a, b, mr);
292}
293
302Value logical_not(const Value &a, std::pmr::memory_resource *mr = nullptr);
303
305inline Value not_op(const Value &a, std::pmr::memory_resource *mr = nullptr)
306{
307 return logical_not(a, mr);
308}
309
319Value logical_xor(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
320
322inline Value xor_op(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr)
323{
324 return logical_xor(a, b, mr);
325}
326
336Value any(const Value &x, int dim = 0, std::pmr::memory_resource *mr = nullptr);
337
347Value all(const Value &x, int dim = 0, std::pmr::memory_resource *mr = nullptr);
348
349// ── Transposition ──────────────────────────────────────────────────────────
350
360Value ctranspose(const Value &a, std::pmr::memory_resource *mr = nullptr);
361
370Value transpose(const Value &a, std::pmr::memory_resource *mr = nullptr);
371
373inline Value logicalAnd(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr) { return logical_and(a, b, mr); }
374
376inline Value logicalOr(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr) { return logical_or(a, b, mr); }
377
379inline Value logicalNot(const Value &a, std::pmr::memory_resource *mr = nullptr) { return logical_not(a, mr); }
380
382inline Value logicalXor(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr) { return logical_xor(a, b, mr); }
383
384inline Value transposeNC(const Value &a, std::pmr::memory_resource *mr = nullptr) { return transpose(a, mr); }
385
391Value bitand_(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
392
398Value bitor_(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
399
405Value bitxor_(const Value &a, const Value &b, std::pmr::memory_resource *mr = nullptr);
406
412Value bitshift(const Value &a, const Value &k, std::pmr::memory_resource *mr = nullptr);
413
419Value bitcmp(const Value &a, int width = 64, std::pmr::memory_resource *mr = nullptr);
420
427Value bitset(const Value &a, const Value &n, const Value &val = Value(), std::pmr::memory_resource *mr = nullptr);
428
434Value bitget(const Value &a, const Value &n, std::pmr::memory_resource *mr = nullptr);
435
436
438} // namespace nk::builtin
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
Value logicalOr(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Alias for logical_or.
Definition ops.hpp:376
Value all(const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
True if all elements of array are non-zero (y = all(x, dim)).
Value ge(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise greater than or equal (y = a >= b).
Value bitand_(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Bitwise AND of integer arrays (bitand(a, b)).
Value lt(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise less than (y = a < b).
Value eq(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise equality (y = a == b).
Value not_op(const Value &a, std::pmr::memory_resource *mr=nullptr)
Alias for logical_not (y = ~a).
Definition ops.hpp:305
Value or_op(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Alias for logical_or (y = a | b).
Definition ops.hpp:289
Value logical_not(const Value &a, std::pmr::memory_resource *mr=nullptr)
Elementwise logical NOT (y = ~a).
TranspOp
Transposition operator for page-wise matrix multiplication.
Definition ops.hpp:164
Value transpose(const Value &a, std::pmr::memory_resource *mr=nullptr)
Non-conjugate array transpose (y = a.
Value logicalAnd(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Alias for logical_and.
Definition ops.hpp:373
Value bitxor_(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Bitwise XOR of integer arrays (bitxor(a, b)).
Value minus(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise subtraction (y = a - b).
Value times(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise multiplication (y = a .
Value uminus(const Value &a, std::pmr::memory_resource *mr=nullptr)
Unary minus / negation (y = -a).
Value mrdivide(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Matrix right division / slash (y = A / B).
Value rdivide(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise right division (y = a .
Value logical_xor(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise logical exclusive OR (y = xor(a, b)).
Value bitcmp(const Value &a, int width=64, std::pmr::memory_resource *mr=nullptr)
Bitwise complement (bitcmp(a, width)).
Value mldivide(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Matrix left division / backslash (y = A \\ B).
Value logical_or(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise logical OR (y = a | b).
Value bitget(const Value &a, const Value &n, std::pmr::memory_resource *mr=nullptr)
Gets bit value at specified bit position in integer array (bitget(a, n)).
Value mtimes(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Matrix multiplication (Y = A * B).
Value mpower(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Matrix power (Y = A ^ B).
Value power(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise power (y = a .
Value plus(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise addition (y = a + b).
Value pagemtimes(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Page-wise matrix multiplication (pagemtimes(a, b)).
Value logicalNot(const Value &a, std::pmr::memory_resource *mr=nullptr)
Alias for logical_not.
Definition ops.hpp:379
Value xor_op(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Alias for logical_xor (y = xor(a, b)).
Definition ops.hpp:322
Value and_op(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Alias for logical_and (y = a & b).
Definition ops.hpp:272
Value uplus(const Value &a, std::pmr::memory_resource *mr=nullptr)
Unary plus (y = +a).
Value ldivide(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise left division (y = a .
Value ne(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise inequality (y = a ~= b).
Value ctranspose(const Value &a, std::pmr::memory_resource *mr=nullptr)
Complex conjugate transpose (y = a').
Value bitset(const Value &a, const Value &n, const Value &val=Value(), std::pmr::memory_resource *mr=nullptr)
Sets specified bit in integer array (bitset(a, n, val)).
Value bitshift(const Value &a, const Value &k, std::pmr::memory_resource *mr=nullptr)
Bitwise shift of integer values (bitshift(a, k)).
Value le(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise less than or equal (y = a <= b).
Value bitor_(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Bitwise OR of integer arrays (bitor(a, b)).
Value logical_and(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise logical AND (y = a & b).
Value any(const Value &x, int dim=0, std::pmr::memory_resource *mr=nullptr)
True if any element of array is non-zero (y = any(x, dim)).
Value gt(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise greater than (y = a > b).
Value logicalXor(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Alias for logical_xor.
Definition ops.hpp:382
Value elementPower(const Value &a, const Value &b, std::pmr::memory_resource *mr=nullptr)
Elementwise power alias (y = a .^ b).
@ CTranspose
Complex conjugate transpose (').
Definition ops.hpp:167
@ None
No transposition.
Definition ops.hpp:165
@ Transpose
Non-conjugate transpose (.').
Definition ops.hpp:166