22 const std::size_t _stride;
23 const std::size_t _len;
27 : _data{data}, _stride{
stride}, _len{
len} {}
29 double&
operator[](std::size_t
i) {
return this->_data[
i * this->_stride]; }
30 const double&
operator[](std::size_t
i)
const {
return this->_data[
i * this->_stride]; }
33 for (std::size_t
i = 0;
i < this->_len; ++
i) this->_data[
i * this->_stride] =
v[
i];
38 for (std::size_t
i = 0;
i < this->_len; ++
i) this->_data[
i * this->_stride] =
scalar;
42 operator std::valarray<double>()
const {
43 std::valarray<double>
res(this->_len);
44 for (std::size_t
i = 0;
i < this->_len; ++
i)
res[
i] = this->_data[
i * this->_stride];
50 for (std::size_t
i = 0;
i < this->_len; ++
i)
s += this->_data[
i * this->_stride];
65 std::vector<double> data;
73 explicit Matrix(std::size_t ndim,
double init = 0.0) : ndim{ndim}, data(ndim * ndim,
init) {}
80 return this->data[
row * this->ndim +
col];
85 return this->data[
row * this->ndim +
col];
90 for (
auto&
v : this->data)
v *=
alpha;
104 for (std::size_t
i = 0;
i < this->ndim; ++
i)
d[
i] = 1.0;
129 for (std::size_t
i = 0;
i < this->ndim; ++
i) {
Square matrix with flat std::vector<double> storage.
Definition ell_matrix.hpp:63
SliceView column(std::size_t c)
Mutable view of column c (strided, stride = ndim)
Definition ell_matrix.hpp:116
void identity()
Set to identity matrix.
Definition ell_matrix.hpp:101
double & operator()(std::size_t row, std::size_t col)
Access element (row, col) — mutable.
Definition ell_matrix.hpp:79
Matrix operator*(double alpha) const
Return a scaled copy.
Definition ell_matrix.hpp:95
void clear(double value=0.0)
Reset all elements to value.
Definition ell_matrix.hpp:76
double trace() const
Sum of diagonal elements.
Definition ell_matrix.hpp:127
Matrix & operator*=(double alpha)
Scale all elements by alpha.
Definition ell_matrix.hpp:89
SliceView row(std::size_t r)
Mutable view of row r (contiguous, stride = 1)
Definition ell_matrix.hpp:111
Matrix(std::size_t ndim, double init=0.0)
Construct an ndim × ndim matrix.
Definition ell_matrix.hpp:73
SliceView diagonal()
Mutable view of the diagonal (stride = ndim + 1)
Definition ell_matrix.hpp:108
const double & operator()(std::size_t row, std::size_t col) const
Access element (row, col) — const.
Definition ell_matrix.hpp:84
Proxy view over a strided slice of a flat array.
Definition ell_matrix.hpp:20
double sum() const
Definition ell_matrix.hpp:48
SliceView & operator=(double scalar)
Definition ell_matrix.hpp:37
const double & operator[](std::size_t i) const
Definition ell_matrix.hpp:30
SliceView(double *data, std::size_t stride, std::size_t len) noexcept
Definition ell_matrix.hpp:26
double & operator[](std::size_t i)
Definition ell_matrix.hpp:29
SliceView & operator=(const std::valarray< double > &v)
Definition ell_matrix.hpp:32
auto invalid_value() -> T
Return an invalid/sentinel value for type T.
Definition cutting_plane.hpp:27