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_ulong_alloc( n1, n2 );
75 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
77 if( n1 > 0 and n2 > 0 ) gsl_spmatrix_ulong_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_ulong_free(
ccgsl_pointer );
116#ifdef __GXX_EXPERIMENTAL_CXX0X__
121 spmatrix_ulong( std::initializer_list<std::initializer_list<unsigned long> > 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_ulong 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_ulong_free(
ccgsl_pointer );
142 for(
auto row : initializer_list ){
144 for(
auto x : row ){
set( r, c, x ); ++c; }
185 gsl_spmatrix_ulong_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_ulong", __FILE__, __LINE__, GSL_EFAULT );
280 unsigned long const*
data()
const {
281 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector_ulong", __FILE__, __LINE__, GSL_EFAULT );
302 size_t nnz()
const {
return gsl_spmatrix_ulong_nnz(
get() ); }
307 char const*
type()
const {
return gsl_spmatrix_ulong_type(
get() ); }
325 gsl_spmatrix_ulong_csc( dest.get(),
get() );
335 gsl_spmatrix_ulong_csr( dest.get(),
get() );
379 int fprintf( FILE* stream,
char const* format )
const {
380 return gsl_spmatrix_ulong_fprintf( stream,
get(), format ); }
387 return gsl_spmatrix_ulong_fwrite( stream,
get() ); }
394 return gsl_spmatrix_ulong_fread( stream,
get() ); }
401 unsigned long get(
size_t const i,
size_t const j )
const {
402 return gsl_spmatrix_ulong_get(
get(), i, j ); }
410 int set(
size_t const i,
size_t const j,
unsigned long const x ){
411 return gsl_spmatrix_ulong_set(
get(), i, j, x ); }
418 unsigned long*
ptr(
size_t const i,
size_t const j )
const {
419 return gsl_spmatrix_ulong_ptr(
get(), i, j ); }
427 int minmax(
unsigned long& min_out,
unsigned long& max_out )
const {
428 return gsl_spmatrix_ulong_minmax(
get(), &min_out, &max_out ); }
435 int min_index(
size_t& imin_out,
size_t& jmin_out )
const {
436 return gsl_spmatrix_ulong_min_index(
get(), &imin_out, &jmin_out ); }
443 int scale(
unsigned long const x ){
return gsl_spmatrix_ulong_scale(
get(), x ); }
450 return gsl_spmatrix_ulong_scale_columns(
get(), x.
get() ); }
457 return gsl_spmatrix_ulong_scale_rows(
get(), x.
get() ); }
483 return gsl_spmatrix_ulong_realloc(
nzmax, spMatrix.
get() ); }
490 return gsl_spmatrix_ulong_nnz( spMatrix.
get() ); }
497 return gsl_spmatrix_ulong_type( spMatrix.
get() ); }
504 return gsl_spmatrix_ulong_set_zero( spMatrix.
get() ); }
511 return gsl_spmatrix_ulong_tree_rebuild( spMatrix.
get() ); }
520 gsl_spmatrix_ulong_csc( dest.get(), spMatrix.
get() );
530 gsl_spmatrix_ulong_csr( dest.get(), spMatrix.
get() );
572 return gsl_spmatrix_ulong_memcpy( dest.
get(), src.
get() ); }
581 return gsl_spmatrix_ulong_fprintf( stream, spMatrix.
get(), format ); }
596 return gsl_spmatrix_ulong_fwrite( stream, spMatrix.
get() ); }
604 return gsl_spmatrix_ulong_fread( stream, spMatrix.
get() ); }
613 return gsl_spmatrix_ulong_add( c.
get(),
a.get(),
b.get() ); }
622 gsl_spmatrix_ulong_add( c.get(),
a.get(),
b.get() );
625#ifndef GSL_DISABLE_DEPRECATED
633 return gsl_spmatrix_ulong_add_to_dense(
a.get(),
b.get() ); }
642 return gsl_spmatrix_ulong_dense_add(
a.get(),
b.get() ); }
650 return gsl_spmatrix_ulong_dense_sub(
a.get(),
b.get() ); }
657 return gsl_spmatrix_ulong_norm1(
a.get() ); }
665 return gsl_spmatrix_ulong_d2sp( S.
get(), A.
get() ); }
673 return gsl_spmatrix_ulong_sp2d( A.
get(), S.
get() ); }
681 return gsl_spmatrix_ulong_equal(
a.get(),
b.get() ); }
701 return gsl_spmatrix_ulong_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_ulong objects as shared handles.
gsl_matrix_ulong * get()
Get the gsl_matrix_ulong.
This class handles sparse matrix_ulong objects as shared handles.
static char const * type(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_type().
spmatrix_ulong(gsl_spmatrix_ulong *v)
Could construct from a gsl_spmatrix_ulong.
spmatrix_ulong & operator=(spmatrix_ulong &&v)
Move operator.
unsigned long * data()
Give access to the data block.
static spmatrix_ulong compress(spmatrix_ulong const &spMatrix, int const sptype)
C++ version of gsl_spmatrix_ulong_compress().
unsigned long const * data() const
Give access to the data block.
spmatrix_ulong csc() const
C++ version of gsl_spmatrix_ulong_csc().
int sptype() const
The type of the spmatrix_ulong.
size_t use_count() const
Find how many spmatrix_ulong objects share this pointer.
spmatrix_ulong compress(int const sptype) const
C++ version of gsl_spmatrix_ulong_compress().
spmatrix_ulong crs() const
C++ version of gsl_spmatrix_ulong_crs().
spmatrix_ulong csr() const
C++ version of gsl_spmatrix_ulong_csr().
static int set_zero(spmatrix_ulong &spMatrix)
C++ version of gsl_spmatrix_ulong_set_zero().
spmatrix_ulong ccs() const
C++ version of gsl_spmatrix_ulong_ccs().
@ TRIPLET
GSL_SPMATRIX_TRIPLET.
static int transpose(spmatrix_ulong &a)
C++ version of gsl_spmatrix_ulong_transpose().
int transpose()
C++ version of gsl_spmatrix_ulong_transpose().
int set_zero()
C++ version of gsl_spmatrix_ulong_set_zero().
void wrap_gsl_spmatrix_ulong_without_ownership(gsl_spmatrix_ulong *v)
This function is intended mainly for internal use.
int memcpy(spmatrix_ulong &dest) const
C++ version of gsl_spmatrix_ulong_memcpy().
spmatrix_ulong(spmatrix_ulong &&v)
Move constructor.
static spmatrix_ulong crs(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_crs().
int minmax(unsigned long &min_out, unsigned long &max_out) const
C++ version of gsl_spmatrix_ulong_minmax().
static int realloc(size_t const nzmax, gsl::spmatrix_ulong &spMatrix)
C++ version of gsl_spmatrix_ulong_realloc(): matches a function in gsl that is intended for internal ...
spmatrix_ulong & operator=(spmatrix_ulong const &v)
The assignment operator.
static spmatrix_ulong compcol(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_compcol().
gsl_spmatrix_ulong * ccgsl_pointer
The shared pointer.
static int fprintf(FILE *stream, spmatrix_ulong const &spMatrix, char const *format)
C++ version of gsl_spmatrix_ulong_fprintf().
unsigned long * ptr(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_ulong_ptr().
int tree_rebuild()
C++ version of gsl_spmatrix_ulong_tree_rebuild().
void reset()
Stop sharing ownership of the shared pointer.
static spmatrix_ulong csc(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_csc().
char const * type() const
C++ version of gsl_spmatrix_ulong_type().
size_t * count
The shared reference count.
void swap(spmatrix_ulong &m)
Swap two spmatrix_ulong objects.
static int fwrite(FILE *stream, spmatrix_ulong &spMatrix)
C++ version of gsl_spmatrix_ulong_fwrite().
static size_t nnz(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_nnz().
size_t nnz() const
C++ version of gsl_spmatrix_ulong_nnz().
spmatrix_ulong(std::initializer_list< std::initializer_list< unsigned long > > initializer_list)
Could construct from a std::initializer_list in C++11 and later.
static int dense_sub(gsl::matrix_ulong &a, spmatrix_ulong const &b)
C++ version of gsl_spmatrix_dense_sub().
spmatrix_ulong()
The default constructor is only really useful for assigning to.
size_t size2() const
The number of columns of the matrix_ulong.
static int transpose_memcpy(spmatrix_ulong &dest, spmatrix_ulong const &src)
C++ version of gsl_spmatrix_ulong_transpose_memcpy().
int fwrite(FILE *stream) const
C++ version of gsl_spmatrix_ulong_fwrite().
static spmatrix_ulong ccs(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_ccs().
static int transpose2(spmatrix_ulong &a)
C++ version of gsl_spmatrix_ulong_transpose2().
int equal(spmatrix_ulong const &b) const
C++ version of gsl_spmatrix_ulong_equal().
spmatrix_ulong(size_t const n1, size_t const n2, size_t nzmax, size_t sptype)
This constructor creates a new matrix_ulong with n1 rows and n2 columns.
static spmatrix_ulong csr(spmatrix_ulong const &spMatrix)
C++ version of gsl_spmatrix_ulong_csr().
static int fread(FILE *stream, spmatrix_ulong &spMatrix)
C++ version of gsl_spmatrix_ulong_fread().
int scale_columns(gsl::vector_ulong const &x)
C++ version of gsl_spmatrix_ulong_scale_columns().
int fread(FILE *stream)
C++ version of gsl_spmatrix_ulong_fread().
static spmatrix_ulong fscanf(FILE *stream)
C++ version of gsl_spmatrix_ulong_fscanf().
int transpose2()
C++ version of gsl_spmatrix_ulong_transpose2().
int scale(unsigned long const x)
C++ version of gsl_spmatrix_ulong_scale().
static int memcpy(spmatrix_ulong &dest, spmatrix_ulong const &src)
C++ version of gsl_spmatrix_ulong_memcpy().
gsl_spmatrix_ulong * get()
Get the gsl_spmatrix_ulong.
spmatrix_ulong clone() const
The clone function.
unsigned long get(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_ulong_get().
static int d2sp(gsl::spmatrix_ulong &S, gsl::matrix_ulong const &A)
C++ version of gsl_spmatrix_ulong_d2sp().
int set(size_t const i, size_t const j, unsigned long const x)
C++ version of gsl_spmatrix_ulong_set().
size_t nzmax() const
The maximum number of nonzero elements.
static int add_to_dense(gsl::matrix_ulong &a, spmatrix_ulong const &b)
C++ version of gsl_spmatrix_add_to_dense().
int scale_rows(gsl::vector_ulong const &x)
C++ version of gsl_spmatrix_ulong_scale_rows().
~spmatrix_ulong()
The destructor only deletes the pointers if count reaches zero.
static int dense_add(gsl::matrix_ulong &a, spmatrix_ulong const &b)
C++ version of gsl_spmatrix_dense_add().
static int equal(spmatrix_ulong const &a, spmatrix_ulong const &b)
C++ version of gsl_spmatrix_ulong_equal().
int realloc(size_t const nzmax)
C++ version of gsl_spmatrix_ulong_realloc().
static spmatrix_ulong add(spmatrix_ulong const &a, spmatrix_ulong const &b)
C++ version of gsl_spmatrix_ulong_add().
static int add(spmatrix_ulong &c, spmatrix_ulong const &a, spmatrix_ulong const &b)
C++ version of gsl_spmatrix_ulong_add().
spmatrix_ulong(size_t const n1, size_t const n2)
This constructor creates a new matrix_ulong with n1 rows and n2 columns.
spmatrix_ulong(spmatrix_ulong const &v)
The copy constructor.
gsl_spmatrix_ulong const * get() const
Get the gsl_spmatrix_ulong.
static int sp2d(gsl::matrix_ulong &A, spmatrix_ulong const &S)
C++ version of gsl_spmatrix_ulong_sp2d().
static int tree_rebuild(spmatrix_ulong &spMatrix)
C++ version of gsl_spmatrix_ulong_tree_rebuild().
bool unique() const
Find if this is the only object sharing the gsl_spmatrix_ulong.
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_spmatrix_ulong_fprintf().
int min_index(size_t &imin_out, size_t &jmin_out) const
C++ version of gsl_spmatrix_ulong_min_index().
static ulong norm1(gsl::spmatrix_ulong const &a)
C++ version of gsl_spmatrix_ulong_norm1().
size_t size1() const
The number of rows of the matrix_ulong.
spmatrix_ulong compcol() const
C++ version of gsl_spmatrix_ulong_compcol().
This class handles vector_ulong objects as shared handles.
gsl_vector_ulong * get()
Get the gsl_vector_ulong.
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++.