1#ifndef DVRLIB_GSL_WRAPPER_H
2#define DVRLIB_GSL_WRAPPER_H
4#include <gsl/gsl_vector.h>
5#include <gsl/gsl_matrix.h>
48 vector(
int n,
const double* x);
62 void set(
int i,
double val);
64 double get(
int i)
const;
124 double get(
int i)
const;
126 void set(
int i,
double val);
163 matrix(
int n1,
int n2,
bool id =
false,
const double* diag =
nullptr);
165 matrix(
int n1,
int n2,
const double* x);
172 matrix(
int n1,
int n2,
const double (*x)[n]);
177 matrix(
const gsl_matrix* src);
191 void set(
int i,
int j,
double val);
193 double get(
int i,
int j)
const;
258 m = gsl_matrix_alloc(n1, n2);
259 gsl_matrix_const_view src = gsl_matrix_const_view_array(x[0], n1, n2);
260 gsl_matrix_memcpy(
m, &src.matrix);
290 double get(
int i,
int j)
const;
292 void set(
int i,
int j,
double val);
306std::ostream&
operator<<(std::ostream& out,
const gsl_vector& v);
307std::ostream&
operator<<(std::ostream& out,
const gsl_matrix& m);
308std::ostream&
operator<<(std::ostream& out,
const gsl_matrix_view& mv);
Non-owning view into a rectangular sub-region of a matrix.
Definition gsl_wrapper.h:277
int size1() const
Return the number of rows.
Definition gsl_wrapper.cc:534
void set(int i, int j, double val)
Set element (i, j) to val (modifies the underlying data).
Definition gsl_wrapper.cc:546
matrix_view & operator=(const matrix &src)
Copy values from src into the viewed memory.
Definition gsl_wrapper.cc:554
gsl_matrix_view mv
Definition gsl_wrapper.h:278
double get(int i, int j) const
Return element (i, j).
Definition gsl_wrapper.cc:542
friend class matrix
Definition gsl_wrapper.h:303
const gsl_matrix * gsl_internal() const
Return a read-only pointer to the underlying gsl_matrix.
Definition gsl_wrapper.cc:550
int size2() const
Return the number of columns.
Definition gsl_wrapper.cc:538
RAII wrapper around a heap-allocated gsl_matrix.
Definition gsl_wrapper.h:149
vector operator*(const vector &src) const
Matrix–vector product.
Definition gsl_wrapper.cc:376
gsl_matrix * gsl_internal()
Return a pointer to the underlying gsl_matrix (mutable).
Definition gsl_wrapper.cc:296
vector svd() const
Compute and return only the singular values.
Definition gsl_wrapper.cc:447
matrix & operator+=(const matrix &src)
Definition gsl_wrapper.cc:351
matrix & operator=(const matrix &src)
Copy-assign from another matrix.
Definition gsl_wrapper.cc:330
matrix_view submatrix(int k1, int k2, int n1, int n2)
Return a view of the n1 × n2 sub-matrix starting at (k1, k2).
Definition gsl_wrapper.cc:459
matrix & operator*=(double d)
Scale all elements by d in place.
Definition gsl_wrapper.cc:397
vector linsolve(const vector &b) const
Solve the linear system A*x = b and return x.
Definition gsl_wrapper.cc:428
matrix operator+(const matrix &src) const
Definition gsl_wrapper.cc:342
matrix operator-() const
Unary negation — returns -(*this).
Definition gsl_wrapper.cc:370
double get(int i, int j) const
Return element (i, j).
Definition gsl_wrapper.cc:316
matrix(int n1, int n2, bool id=false, const double *diag=nullptr)
Allocate an n1 × n2 matrix.
Definition gsl_wrapper.cc:264
gsl_matrix * m
Definition gsl_wrapper.h:150
matrix & operator-=(const matrix &src)
Definition gsl_wrapper.cc:365
int size2() const
Return the number of columns.
Definition gsl_wrapper.cc:308
void set(int i, int j, double val)
Set element (i, j) to val.
Definition gsl_wrapper.cc:312
matrix transpose() const
Return the transpose.
Definition gsl_wrapper.cc:402
int size1() const
Return the number of rows.
Definition gsl_wrapper.cc:304
~matrix()
Destructor — frees the underlying GSL allocation.
Definition gsl_wrapper.cc:292
vector_view operator[](int i)
Return a mutable view of row i.
Definition gsl_wrapper.cc:320
matrix inverse() const
Return the inverse (via LU decomposition).
Definition gsl_wrapper.cc:418
Non-owning view into a contiguous slice of a vector or matrix row/column.
Definition gsl_wrapper.h:113
gsl_vector_view vv
Definition gsl_wrapper.h:114
vector_view & operator=(const vector &src)
Copy values from src into the viewed memory.
Definition gsl_wrapper.cc:244
const gsl_vector * gsl_internal() const
Return a read-only pointer to the underlying gsl_vector.
Definition gsl_wrapper.cc:240
void set(int i, double val)
Set element i to val (modifies the underlying data).
Definition gsl_wrapper.cc:236
int size() const
Return the number of elements.
Definition gsl_wrapper.cc:228
double get(int i) const
Return element i.
Definition gsl_wrapper.cc:232
friend class vector
Definition gsl_wrapper.h:137
RAII wrapper around a heap-allocated gsl_vector.
Definition gsl_wrapper.h:39
vector & operator=(const vector &src)
Copy-assign from another vector.
Definition gsl_wrapper.cc:108
vector operator*(double d) const
Return a copy scaled by d.
Definition gsl_wrapper.cc:153
double get(int i) const
Return element i.
Definition gsl_wrapper.cc:100
gsl_vector * gsl_internal()
Return a pointer to the underlying gsl_vector (mutable).
Definition gsl_wrapper.cc:84
void set(int i, double val)
Set element i to val.
Definition gsl_wrapper.cc:96
~vector()
Destructor — frees the underlying GSL allocation.
Definition gsl_wrapper.cc:80
vector & operator+=(const vector &src)
Definition gsl_wrapper.cc:120
vector operator+(const vector &src) const
Definition gsl_wrapper.cc:125
vector & operator-=(const vector &src)
Definition gsl_wrapper.cc:131
vector_view subvector(int k, int n)
Return a view of n elements starting at index k.
Definition gsl_wrapper.cc:159
vector operator-() const
Unary negation — returns -(*this).
Definition gsl_wrapper.cc:142
vector & operator*=(double d)
Scale all elements by d in place.
Definition gsl_wrapper.cc:148
double norm1() const
Return the L1 norm (sum of absolute values).
Definition gsl_wrapper.cc:173
gsl_vector * v
Definition gsl_wrapper.h:40
double operator[](int i) const
Return element i (read-only subscript).
Definition gsl_wrapper.cc:104
double norm2() const
Return the L2 (Euclidean) norm.
Definition gsl_wrapper.cc:177
int size() const
Return the number of elements.
Definition gsl_wrapper.cc:92
#define dvr_assert(cond)
Definition dvr_assert.h:18
Definition dvr_assert.h:7
std::ostream & operator<<(std::ostream &out, const vector &vec)
Write a vector to an output stream.
Definition gsl_wrapper.cc:209
vector operator*(double d, const vector &src)
Scalar multiplication d*src (commutative with vector::operator*).
Definition gsl_wrapper.cc:169
void gsl_enable_exceptions()
Install a GSL error handler that throws gsl_exception instead of aborting.
Definition gsl_wrapper.cc:19
void set_vdi_print_format(bool enable)
Switch between standard and VDI 2048 pretty-print format for vectors and matrices written to std::ost...
Definition gsl_wrapper.cc:25
Exception type thrown by GSL when gsl_enable_exceptions() is active.
Definition gsl_wrapper.h:13
const char * file
Source file where the error occurred.
Definition gsl_wrapper.h:15
const char * reason
Human-readable error description.
Definition gsl_wrapper.h:14
int gsl_errno
GSL error code (see gsl_errno.h)
Definition gsl_wrapper.h:17
int line
Line number where the error occurred.
Definition gsl_wrapper.h:16