19#ifndef CCGSL_SPMATRIX_HPP
20#define CCGSL_SPMATRIX_HPP
23#include<gsl/gsl_spmatrix.h>
44 COO = GSL_SPMATRIX_COO,
46 CSC = GSL_SPMATRIX_CSC,
48 CSR = GSL_SPMATRIX_CSR,
52 CCS = GSL_SPMATRIX_CCS,
54 CRS = GSL_SPMATRIX_CRS
71 if( n1 > 0 and n2 > 0 )
ccgsl_pointer = gsl_spmatrix_int_alloc( n1, n2 );
75 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
77 if( n1 > 0 and n2 > 0 ) gsl_spmatrix_int_free(
ccgsl_pointer );
92 if( n1 > 0 and n2 > 0 )
97 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
99 if( n1 > 0 and n2 > 0 ) gsl_spmatrix_int_free(
ccgsl_pointer );
116#ifdef __GXX_EXPERIMENTAL_CXX0X__
121 spmatrix_int( std::initializer_list<std::initializer_list<int> > initializer_list ){
122 size_t const n1 = initializer_list.size();
123 size_t const n2 = initializer_list.begin()->size();
124 for(
auto l : initializer_list ){
125 if( l.size() != n2 ){
126 gsl::exception e(
"matrix_int rows have unequal sizes", __FILE__, __LINE__,
133 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
135 if( n1 > 0 and n2 > 0 ) gsl_spmatrix_int_free(
ccgsl_pointer );
142 for(
auto row : initializer_list ){
144 for(
auto x : row ){
set( r, c, x ); ++c; }
185 gsl_spmatrix_int_memcpy( copy.
get(),
get() );
228#ifdef __GXX_EXPERIMENTAL_CXX0X__
234 std::swap(
count, v.count );
235 v.ccgsl_pointer =
nullptr;
274 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector_int", __FILE__, __LINE__, GSL_EFAULT );
281 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector_int", __FILE__, __LINE__, GSL_EFAULT );
302 size_t nnz()
const {
return gsl_spmatrix_int_nnz(
get() ); }
307 char const*
type()
const {
return gsl_spmatrix_int_type(
get() ); }
325 gsl_spmatrix_int_csc( dest.get(),
get() );
335 gsl_spmatrix_int_csr( dest.get(),
get() );
379 int fprintf( FILE* stream,
char const* format )
const {
380 return gsl_spmatrix_int_fprintf( stream,
get(), format ); }
387 return gsl_spmatrix_int_fwrite( stream,
get() ); }
394 return gsl_spmatrix_int_fread( stream,
get() ); }
401 int get(
size_t const i,
size_t const j )
const {
402 return gsl_spmatrix_int_get(
get(), i, j ); }
410 int set(
size_t const i,
size_t const j,
int const x ){
411 return gsl_spmatrix_int_set(
get(), i, j, x ); }
418 int*
ptr(
size_t const i,
size_t const j )
const {
419 return gsl_spmatrix_int_ptr(
get(), i, j ); }
427 int minmax(
int& min_out,
int& max_out )
const {
428 return gsl_spmatrix_int_minmax(
get(), &min_out, &max_out ); }
435 int min_index(
size_t& imin_out,
size_t& jmin_out )
const {
436 return gsl_spmatrix_int_min_index(
get(), &imin_out, &jmin_out ); }
443 int scale(
int const x ){
return gsl_spmatrix_int_scale(
get(), x ); }
450 return gsl_spmatrix_int_scale_columns(
get(), x.
get() ); }
457 return gsl_spmatrix_int_scale_rows(
get(), x.
get() ); }
483 return gsl_spmatrix_int_realloc(
nzmax, spMatrix.
get() ); }
490 return gsl_spmatrix_int_nnz( spMatrix.
get() ); }
497 return gsl_spmatrix_int_type( spMatrix.
get() ); }
504 return gsl_spmatrix_int_set_zero( spMatrix.
get() ); }
511 return gsl_spmatrix_int_tree_rebuild( spMatrix.
get() ); }
520 gsl_spmatrix_int_csc( dest.get(), spMatrix.
get() );
530 gsl_spmatrix_int_csr( dest.get(), spMatrix.
get() );
572 return gsl_spmatrix_int_memcpy( dest.
get(), src.
get() ); }
581 return gsl_spmatrix_int_fprintf( stream, spMatrix.
get(), format ); }
588 return spmatrix_int { gsl_spmatrix_int_fscanf( stream ) }; }
596 return gsl_spmatrix_int_fwrite( stream, spMatrix.
get() ); }
604 return gsl_spmatrix_int_fread( stream, spMatrix.
get() ); }
613 return gsl_spmatrix_int_add( c.
get(),
a.get(),
b.get() ); }
622 gsl_spmatrix_int_add( c.get(),
a.get(),
b.get() );
625#ifndef GSL_DISABLE_DEPRECATED
633 return gsl_spmatrix_int_add_to_dense(
a.get(),
b.get() ); }
642 return gsl_spmatrix_int_dense_add(
a.get(),
b.get() ); }
650 return gsl_spmatrix_int_dense_sub(
a.get(),
b.get() ); }
657 return gsl_spmatrix_int_norm1(
a.get() ); }
665 return gsl_spmatrix_int_d2sp( S.
get(), A.
get() ); }
673 return gsl_spmatrix_int_sp2d( A.
get(), S.
get() ); }
681 return gsl_spmatrix_int_equal(
a.get(),
b.get() ); }
701 return gsl_spmatrix_int_transpose_memcpy( dest.
get(), src.
get() ); }
739#ifdef __GXX_EXPERIMENTAL_CXX0X__
This class is used to handle gsl exceptions so that gsl can use these rather than the GSL error handl...
@ GSL_EBADLEN
matrix, vector lengths are not conformant
This class handles matrix_int objects as shared handles.
gsl_matrix_int * get()
Get the gsl_matrix_int.
This class handles sparse matrix_int objects as shared handles.
static spmatrix_int compress(spmatrix_int const &spMatrix, int const sptype)
C++ version of gsl_spmatrix_int_compress().
static spmatrix_int csc(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_csc().
size_t size2() const
The number of columns of the matrix_int.
spmatrix_int csc() const
C++ version of gsl_spmatrix_int_csc().
gsl_spmatrix_int * ccgsl_pointer
The shared pointer.
static int tree_rebuild(spmatrix_int &spMatrix)
C++ version of gsl_spmatrix_int_tree_rebuild().
bool unique() const
Find if this is the only object sharing the gsl_spmatrix_int.
gsl_spmatrix_int const * get() const
Get the gsl_spmatrix_int.
size_t size1() const
The number of rows of the matrix_int.
char const * type() const
C++ version of gsl_spmatrix_int_type().
int scale(int const x)
C++ version of gsl_spmatrix_int_scale().
size_t use_count() const
Find how many spmatrix_int objects share this pointer.
static int dense_sub(gsl::matrix_int &a, spmatrix_int const &b)
C++ version of gsl_spmatrix_dense_sub().
int const * data() const
Give access to the data block.
spmatrix_int(spmatrix_int const &v)
The copy constructor.
static spmatrix_int compcol(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_compcol().
int equal(spmatrix_int const &b) const
C++ version of gsl_spmatrix_int_equal().
static int set_zero(spmatrix_int &spMatrix)
C++ version of gsl_spmatrix_int_set_zero().
spmatrix_int & operator=(spmatrix_int &&v)
Move operator.
size_t nzmax() const
The maximum number of nonzero elements.
spmatrix_int crs() const
C++ version of gsl_spmatrix_int_crs().
spmatrix_int()
The default constructor is only really useful for assigning to.
static int fwrite(FILE *stream, spmatrix_int &spMatrix)
C++ version of gsl_spmatrix_int_fwrite().
spmatrix_int compcol() const
C++ version of gsl_spmatrix_int_compcol().
static spmatrix_int fscanf(FILE *stream)
C++ version of gsl_spmatrix_int_fscanf().
int fwrite(FILE *stream) const
C++ version of gsl_spmatrix_int_fwrite().
static int memcpy(spmatrix_int &dest, spmatrix_int const &src)
C++ version of gsl_spmatrix_int_memcpy().
spmatrix_int compress(int const sptype) const
C++ version of gsl_spmatrix_int_compress().
static spmatrix_int csr(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_csr().
spmatrix_int(spmatrix_int &&v)
Move constructor.
static int fread(FILE *stream, spmatrix_int &spMatrix)
C++ version of gsl_spmatrix_int_fread().
int fread(FILE *stream)
C++ version of gsl_spmatrix_int_fread().
static int add(spmatrix_int &c, spmatrix_int const &a, spmatrix_int const &b)
C++ version of gsl_spmatrix_int_add().
int transpose()
C++ version of gsl_spmatrix_int_transpose().
spmatrix_int csr() const
C++ version of gsl_spmatrix_int_csr().
static int sp2d(gsl::matrix_int &A, spmatrix_int const &S)
C++ version of gsl_spmatrix_int_sp2d().
int scale_rows(gsl::vector_int const &x)
C++ version of gsl_spmatrix_int_scale_rows().
static int transpose_memcpy(spmatrix_int &dest, spmatrix_int const &src)
C++ version of gsl_spmatrix_int_transpose_memcpy().
int * data()
Give access to the data block.
static int equal(spmatrix_int const &a, spmatrix_int const &b)
C++ version of gsl_spmatrix_int_equal().
int sptype() const
The type of the spmatrix_int.
static int realloc(size_t const nzmax, gsl::spmatrix_int &spMatrix)
C++ version of gsl_spmatrix_int_realloc(): matches a function in gsl that is intended for internal us...
int realloc(size_t const nzmax)
C++ version of gsl_spmatrix_int_realloc().
void wrap_gsl_spmatrix_int_without_ownership(gsl_spmatrix_int *v)
This function is intended mainly for internal use.
spmatrix_int(size_t const n1, size_t const n2, size_t nzmax, size_t sptype)
This constructor creates a new matrix_int with n1 rows and n2 columns.
spmatrix_int(std::initializer_list< std::initializer_list< int > > initializer_list)
Could construct from a std::initializer_list in C++11 and later.
int tree_rebuild()
C++ version of gsl_spmatrix_int_tree_rebuild().
int memcpy(spmatrix_int &dest) const
C++ version of gsl_spmatrix_int_memcpy().
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_spmatrix_int_fprintf().
static spmatrix_int crs(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_crs().
~spmatrix_int()
The destructor only deletes the pointers if count reaches zero.
size_t * count
The shared reference count.
int set_zero()
C++ version of gsl_spmatrix_int_set_zero().
static int dense_add(gsl::matrix_int &a, spmatrix_int const &b)
C++ version of gsl_spmatrix_dense_add().
static size_t nnz(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_nnz().
static int d2sp(gsl::spmatrix_int &S, gsl::matrix_int const &A)
C++ version of gsl_spmatrix_int_d2sp().
void reset()
Stop sharing ownership of the shared pointer.
int transpose2()
C++ version of gsl_spmatrix_int_transpose2().
static int transpose2(spmatrix_int &a)
C++ version of gsl_spmatrix_int_transpose2().
int minmax(int &min_out, int &max_out) const
C++ version of gsl_spmatrix_int_minmax().
spmatrix_int & operator=(spmatrix_int const &v)
The assignment operator.
spmatrix_int clone() const
The clone function.
int get(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_int_get().
int min_index(size_t &imin_out, size_t &jmin_out) const
C++ version of gsl_spmatrix_int_min_index().
spmatrix_int(size_t const n1, size_t const n2)
This constructor creates a new matrix_int with n1 rows and n2 columns.
spmatrix_int ccs() const
C++ version of gsl_spmatrix_int_ccs().
int set(size_t const i, size_t const j, int const x)
C++ version of gsl_spmatrix_int_set().
void swap(spmatrix_int &m)
Swap two spmatrix_int objects.
static spmatrix_int add(spmatrix_int const &a, spmatrix_int const &b)
C++ version of gsl_spmatrix_int_add().
int scale_columns(gsl::vector_int const &x)
C++ version of gsl_spmatrix_int_scale_columns().
static int add_to_dense(gsl::matrix_int &a, spmatrix_int const &b)
C++ version of gsl_spmatrix_add_to_dense().
int * ptr(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_int_ptr().
static int norm1(gsl::spmatrix_int const &a)
C++ version of gsl_spmatrix_int_norm1().
static char const * type(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_type().
static int transpose(spmatrix_int &a)
C++ version of gsl_spmatrix_int_transpose().
@ TRIPLET
GSL_SPMATRIX_TRIPLET.
static spmatrix_int ccs(spmatrix_int const &spMatrix)
C++ version of gsl_spmatrix_int_ccs().
size_t nnz() const
C++ version of gsl_spmatrix_int_nnz().
static int fprintf(FILE *stream, spmatrix_int const &spMatrix, char const *format)
C++ version of gsl_spmatrix_int_fprintf().
spmatrix_int(gsl_spmatrix_int *v)
Could construct from a gsl_spmatrix_int.
gsl_spmatrix_int * get()
Get the gsl_spmatrix_int.
This class handles vector_int objects as shared handles.
gsl_vector_int * get()
Get the gsl_vector_int.
double b(int order, double qq)
C++ version of gsl_sf_mathieu_b().
double a(int order, double qq)
C++ version of gsl_sf_mathieu_a().
The gsl package creates an interface to the GNU Scientific Library for C++.