EllAlgo 1.6.13
Loading...
Searching...
No Matches
Classes | Functions | Variables
arr.hpp File Reference

Minimal flat-vector array class replacing xtensor for small optimization problems. More...

#include <cassert>
#include <cmath>
#include <cstdint>
#include <initializer_list>
#include <numeric>
#include <utility>
#include <vector>
Include dependency graph for arr.hpp:

Go to the source code of this file.

Classes

class  Arr
 1D or 2D array backed by std::vector<double> for small optimization problems More...
 
struct  Range
 Index range [start, end) with step for slicing views. More...
 

Functions

Arr view (const Arr &a, const Range &rows, const Range &cols)
 Extract a submatrix view from a 2D array using Range for rows and cols.
 
Arr view (const Arr &a, const Range &rows)
 Extract a subarray view (1D or 2D) using a single Range.
 
Arr zeros (size_t n)
 Create zero-initialized 1D array of size n.
 
Arr zeros (size_t r, size_t c)
 Create zero-initialized 2D array with r rows, c columns.
 
Arr ones (size_t r, size_t c)
 Create 2D array of ones with r rows, c columns.
 
Arr linspace (double start, double end, size_t n)
 Linearly spaced values from start to end, inclusive.
 
Arr arange (double start, double end)
 Values from start to end-1 with step 1.
 
Arr make_same_shape (const Arr &a)
 Create a zero-initialized Arr with the same shape as input.
 
Arr cos (const Arr &a)
 Element-wise cosine.
 
Arr log (const Arr &a)
 Element-wise natural logarithm.
 
Arr abs (const Arr &a)
 Element-wise absolute value.
 
Arr exp (const Arr &a)
 Element-wise exponential.
 
Arr sqrt (const Arr &a)
 Element-wise square root.
 
double sum (const Arr &a)
 Sum of all elements.
 
std::vector< Arrwhere (const Arr &condition)
 Find indices of non-zero elements.
 
Arr dot (const Arr &A, const Arr &x)
 Matrix-vector multiplication.
 
Arr outer (const Arr &u, const Arr &v)
 Outer product of two 1D vectors.
 
Arr concatenate (const Arr &a, const Arr &b, int=1)
 Concatenate two 2D arrays along columns (axis=1)
 
Arr operator- (const Arr &a)
 Unary negation (element-wise)
 
Arr operator+ (const Arr &a, const Arr &b)
 Element-wise addition of two arrays.
 
Arr operator- (const Arr &a, const Arr &b)
 Element-wise subtraction of two arrays.
 
Arr operator* (const Arr &a, const Arr &b)
 Element-wise multiplication of two arrays.
 
Arr operator* (double s, const Arr &a)
 Scalar multiplication (scalar × array)
 
Arr operator* (const Arr &a, double s)
 Scalar multiplication (array × scalar)
 
Arr operator/ (const Arr &a, double s)
 Scalar division (array / scalar)
 
Arr operator<= (const Arr &a, double s)
 Element-wise less-than-or-equal-to comparison with scalar.
 
Arr operator>= (const Arr &a, double s)
 Element-wise greater-than-or-equal-to comparison with scalar.
 
Arr operator< (const Arr &a, double s)
 Element-wise less-than comparison with scalar.
 
Arr operator> (const Arr &a, double s)
 Element-wise greater-than comparison with scalar.
 
Arr eval (Arr a)
 Identity function for Arr (for API compatibility)
 

Variables

constexpr size_t ALL = Range::ALL
 Convenience alias for Range::ALL.
 

Detailed Description

Minimal flat-vector array class replacing xtensor for small optimization problems.

Supports 1D (vector) and 2D (row-major matrix) with operations needed by ellipsoid-method-based solvers. Not a general-purpose array library.

Function Documentation

◆ abs()

Arr abs ( const Arr a)
inline

Element-wise absolute value.

◆ arange()

Arr arange ( double  start,
double  end 
)
inline

Values from start to end-1 with step 1.

Returns
1D Arr containing [start, start+1, ..., end-1]

◆ concatenate()

Arr concatenate ( const Arr a,
const Arr b,
int  = 1 
)
inline

Concatenate two 2D arrays along columns (axis=1)

Parameters
[in]aLeft 2D array
[in]bRight 2D array
Returns
2D array with rows = a.rows(), cols = a.cols() + b.cols()

◆ cos()

Arr cos ( const Arr a)
inline

Element-wise cosine.

◆ dot()

Arr dot ( const Arr A,
const Arr x 
)
inline

Matrix-vector multiplication.

\[ y = A x, \qquad y_i = \sum_{j=1}^{n} A_{ij} x_j \]

Parameters
[in]A2D matrix (m × n)
[in]x1D vector (n)
Returns
Result vector (m)

◆ eval()

Arr eval ( Arr  a)
inline

Identity function for Arr (for API compatibility)

◆ exp()

Arr exp ( const Arr a)
inline

Element-wise exponential.

◆ linspace()

Arr linspace ( double  start,
double  end,
size_t  n 
)
inline

Linearly spaced values from start to end, inclusive.

\[ x_i = x_{\text{start}} + i \cdot \frac{x_{\text{end}} - x_{\text{start}}}{n - 1}, \qquad i = 0, \dots, n-1 \]

Parameters
[in]startFirst value
[in]endLast value
[in]nNumber of points
Returns
1D Arr of n equally spaced values

◆ log()

Arr log ( const Arr a)
inline

Element-wise natural logarithm.

◆ make_same_shape()

Arr make_same_shape ( const Arr a)
inline

Create a zero-initialized Arr with the same shape as input.

◆ ones()

Arr ones ( size_t  r,
size_t  c 
)
inline

Create 2D array of ones with r rows, c columns.

◆ operator*() [1/3]

Arr operator* ( const Arr a,
const Arr b 
)
inline

Element-wise multiplication of two arrays.

◆ operator*() [2/3]

Arr operator* ( const Arr a,
double  s 
)
inline

Scalar multiplication (array × scalar)

◆ operator*() [3/3]

Arr operator* ( double  s,
const Arr a 
)
inline

Scalar multiplication (scalar × array)

◆ operator+()

Arr operator+ ( const Arr a,
const Arr b 
)
inline

Element-wise addition of two arrays.

◆ operator-() [1/2]

Arr operator- ( const Arr a)
inline

Unary negation (element-wise)

◆ operator-() [2/2]

Arr operator- ( const Arr a,
const Arr b 
)
inline

Element-wise subtraction of two arrays.

◆ operator/()

Arr operator/ ( const Arr a,
double  s 
)
inline

Scalar division (array / scalar)

◆ operator<()

Arr operator< ( const Arr a,
double  s 
)
inline

Element-wise less-than comparison with scalar.

Returns
Arr of 1.0/0.0 indicating true/false

◆ operator<=()

Arr operator<= ( const Arr a,
double  s 
)
inline

Element-wise less-than-or-equal-to comparison with scalar.

Returns
Arr of 1.0/0.0 indicating true/false

◆ operator>()

Arr operator> ( const Arr a,
double  s 
)
inline

Element-wise greater-than comparison with scalar.

Returns
Arr of 1.0/0.0 indicating true/false

◆ operator>=()

Arr operator>= ( const Arr a,
double  s 
)
inline

Element-wise greater-than-or-equal-to comparison with scalar.

Returns
Arr of 1.0/0.0 indicating true/false

◆ outer()

Arr outer ( const Arr u,
const Arr v 
)
inline

Outer product of two 1D vectors.

\[ C = u \otimes v, \qquad C_{ij} = u_i v_j \]

Parameters
[in]uFirst 1D vector
[in]vSecond 1D vector
Returns
2D matrix where result(i,j) = u(i) × v(j)

◆ sqrt()

Arr sqrt ( const Arr a)
inline

Element-wise square root.

◆ sum()

double sum ( const Arr a)
inline

Sum of all elements.

◆ view() [1/2]

Arr view ( const Arr a,
const Range rows 
)
inline

Extract a subarray view (1D or 2D) using a single Range.

Parameters
[in]aInput array (1D or 2D)
[in]rowsRow range (or element range for 1D)
Returns
New Arr containing the subarray

◆ view() [2/2]

Arr view ( const Arr a,
const Range rows,
const Range cols 
)
inline

Extract a submatrix view from a 2D array using Range for rows and cols.

Parameters
[in]aInput 2D array
[in]rowsRow range [start, end, step]
[in]colsColumn range [start, end, step]
Returns
New Arr containing the submatrix

◆ where()

std::vector< Arr > where ( const Arr condition)
inline

Find indices of non-zero elements.

Parameters
[in]conditionInput 1D array (non-zero = true)
Returns
Vector containing [indices] as a 1D Arr

◆ zeros() [1/2]

Arr zeros ( size_t  n)
inline

Create zero-initialized 1D array of size n.

◆ zeros() [2/2]

Arr zeros ( size_t  r,
size_t  c 
)
inline

Create zero-initialized 2D array with r rows, c columns.

Variable Documentation

◆ ALL

constexpr size_t ALL = Range::ALL
inlineconstexpr

Convenience alias for Range::ALL.