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_short_alloc( n1, n2 );
75 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
77 if( n1 > 0 and n2 > 0 ) gsl_spmatrix_short_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_short_free(
ccgsl_pointer );
116#ifdef __GXX_EXPERIMENTAL_CXX0X__
121 spmatrix_short( std::initializer_list<std::initializer_list<short> > 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_short 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_short_free(
ccgsl_pointer );
142 for(
auto row : initializer_list ){
144 for(
auto x : row ){
set( r, c, x ); ++c; }
185 gsl_spmatrix_short_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_short", __FILE__, __LINE__, GSL_EFAULT );
281 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector_short", __FILE__, __LINE__, GSL_EFAULT );
302 size_t nnz()
const {
return gsl_spmatrix_short_nnz(
get() ); }
307 char const*
type()
const {
return gsl_spmatrix_short_type(
get() ); }
325 gsl_spmatrix_short_csc( dest.get(),
get() );
335 gsl_spmatrix_short_csr( dest.get(),
get() );
379 int fprintf( FILE* stream,
char const* format )
const {
380 return gsl_spmatrix_short_fprintf( stream,
get(), format ); }
387 return gsl_spmatrix_short_fwrite( stream,
get() ); }
394 return gsl_spmatrix_short_fread( stream,
get() ); }
401 short get(
size_t const i,
size_t const j )
const {
402 return gsl_spmatrix_short_get(
get(), i, j ); }
410 int set(
size_t const i,
size_t const j,
short const x ){
411 return gsl_spmatrix_short_set(
get(), i, j, x ); }
418 short*
ptr(
size_t const i,
size_t const j )
const {
419 return gsl_spmatrix_short_ptr(
get(), i, j ); }
427 int minmax(
short& min_out,
short& max_out )
const {
428 return gsl_spmatrix_short_minmax(
get(), &min_out, &max_out ); }
435 int min_index(
size_t& imin_out,
size_t& jmin_out )
const {
436 return gsl_spmatrix_short_min_index(
get(), &imin_out, &jmin_out ); }
443 int scale(
short const x ){
return gsl_spmatrix_short_scale(
get(), x ); }
450 return gsl_spmatrix_short_scale_columns(
get(), x.
get() ); }
457 return gsl_spmatrix_short_scale_rows(
get(), x.
get() ); }
483 return gsl_spmatrix_short_realloc(
nzmax, spMatrix.
get() ); }
490 return gsl_spmatrix_short_nnz( spMatrix.
get() ); }
497 return gsl_spmatrix_short_type( spMatrix.
get() ); }
504 return gsl_spmatrix_short_set_zero( spMatrix.
get() ); }
511 return gsl_spmatrix_short_tree_rebuild( spMatrix.
get() ); }
520 gsl_spmatrix_short_csc( dest.get(), spMatrix.
get() );
530 gsl_spmatrix_short_csr( dest.get(), spMatrix.
get() );
572 return gsl_spmatrix_short_memcpy( dest.
get(), src.
get() ); }
581 return gsl_spmatrix_short_fprintf( stream, spMatrix.
get(), format ); }
596 return gsl_spmatrix_short_fwrite( stream, spMatrix.
get() ); }
604 return gsl_spmatrix_short_fread( stream, spMatrix.
get() ); }
613 return gsl_spmatrix_short_add( c.
get(),
a.get(),
b.get() ); }
622 gsl_spmatrix_short_add( c.get(),
a.get(),
b.get() );
625#ifndef GSL_DISABLE_DEPRECATED
633 return gsl_spmatrix_short_add_to_dense(
a.get(),
b.get() ); }
642 return gsl_spmatrix_short_dense_add(
a.get(),
b.get() ); }
650 return gsl_spmatrix_short_dense_sub(
a.get(),
b.get() ); }
657 return gsl_spmatrix_short_norm1(
a.get() ); }
665 return gsl_spmatrix_short_d2sp( S.
get(), A.
get() ); }
673 return gsl_spmatrix_short_sp2d( A.
get(), S.
get() ); }
681 return gsl_spmatrix_short_equal(
a.get(),
b.get() ); }
701 return gsl_spmatrix_short_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_short objects as shared handles.
gsl_matrix_short * get()
Get the gsl_matrix_short.
This class handles sparse matrix_short objects as shared handles.
int scale_rows(gsl::vector_short const &x)
C++ version of gsl_spmatrix_short_scale_rows().
char const * type() const
C++ version of gsl_spmatrix_short_type().
static int dense_sub(gsl::matrix_short &a, spmatrix_short const &b)
C++ version of gsl_spmatrix_dense_sub().
spmatrix_short(spmatrix_short const &v)
The copy constructor.
static spmatrix_short crs(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_crs().
static int fread(FILE *stream, spmatrix_short &spMatrix)
C++ version of gsl_spmatrix_short_fread().
spmatrix_short(spmatrix_short &&v)
Move constructor.
size_t size1() const
The number of rows of the matrix_short.
static spmatrix_short fscanf(FILE *stream)
C++ version of gsl_spmatrix_short_fscanf().
void swap(spmatrix_short &m)
Swap two spmatrix_short objects.
static spmatrix_short compcol(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_compcol().
static int transpose_memcpy(spmatrix_short &dest, spmatrix_short const &src)
C++ version of gsl_spmatrix_short_transpose_memcpy().
spmatrix_short(std::initializer_list< std::initializer_list< short > > initializer_list)
Could construct from a std::initializer_list in C++11 and later.
static spmatrix_short csr(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_csr().
int scale_columns(gsl::vector_short const &x)
C++ version of gsl_spmatrix_short_scale_columns().
gsl_spmatrix_short * get()
Get the gsl_spmatrix_short.
spmatrix_short crs() const
C++ version of gsl_spmatrix_short_crs().
static int memcpy(spmatrix_short &dest, spmatrix_short const &src)
C++ version of gsl_spmatrix_short_memcpy().
int tree_rebuild()
C++ version of gsl_spmatrix_short_tree_rebuild().
static spmatrix_short add(spmatrix_short const &a, spmatrix_short const &b)
C++ version of gsl_spmatrix_short_add().
~spmatrix_short()
The destructor only deletes the pointers if count reaches zero.
spmatrix_short compress(int const sptype) const
C++ version of gsl_spmatrix_short_compress().
static short norm1(gsl::spmatrix_short const &a)
C++ version of gsl_spmatrix_short_norm1().
static spmatrix_short csc(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_csc().
static int fwrite(FILE *stream, spmatrix_short &spMatrix)
C++ version of gsl_spmatrix_short_fwrite().
int minmax(short &min_out, short &max_out) const
C++ version of gsl_spmatrix_short_minmax().
int set_zero()
C++ version of gsl_spmatrix_short_set_zero().
size_t nzmax() const
The maximum number of nonzero elements.
spmatrix_short csc() const
C++ version of gsl_spmatrix_short_csc().
static spmatrix_short compress(spmatrix_short const &spMatrix, int const sptype)
C++ version of gsl_spmatrix_short_compress().
gsl_spmatrix_short * ccgsl_pointer
The shared pointer.
@ TRIPLET
GSL_SPMATRIX_TRIPLET.
int transpose2()
C++ version of gsl_spmatrix_short_transpose2().
int sptype() const
The type of the spmatrix_short.
void reset()
Stop sharing ownership of the shared pointer.
size_t * count
The shared reference count.
static int add_to_dense(gsl::matrix_short &a, spmatrix_short const &b)
C++ version of gsl_spmatrix_add_to_dense().
short get(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_short_get().
static int transpose2(spmatrix_short &a)
C++ version of gsl_spmatrix_short_transpose2().
static int dense_add(gsl::matrix_short &a, spmatrix_short const &b)
C++ version of gsl_spmatrix_dense_add().
short * ptr(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_short_ptr().
int transpose()
C++ version of gsl_spmatrix_short_transpose().
spmatrix_short & operator=(spmatrix_short &&v)
Move operator.
static int fprintf(FILE *stream, spmatrix_short const &spMatrix, char const *format)
C++ version of gsl_spmatrix_short_fprintf().
int min_index(size_t &imin_out, size_t &jmin_out) const
C++ version of gsl_spmatrix_short_min_index().
spmatrix_short ccs() const
C++ version of gsl_spmatrix_short_ccs().
bool unique() const
Find if this is the only object sharing the gsl_spmatrix_short.
static int realloc(size_t const nzmax, gsl::spmatrix_short &spMatrix)
C++ version of gsl_spmatrix_short_realloc(): matches a function in gsl that is intended for internal ...
int set(size_t const i, size_t const j, short const x)
C++ version of gsl_spmatrix_short_set().
static int add(spmatrix_short &c, spmatrix_short const &a, spmatrix_short const &b)
C++ version of gsl_spmatrix_short_add().
static size_t nnz(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_nnz().
int memcpy(spmatrix_short &dest) const
C++ version of gsl_spmatrix_short_memcpy().
spmatrix_short(size_t const n1, size_t const n2, size_t nzmax, size_t sptype)
This constructor creates a new matrix_short with n1 rows and n2 columns.
static int d2sp(gsl::spmatrix_short &S, gsl::matrix_short const &A)
C++ version of gsl_spmatrix_short_d2sp().
static char const * type(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_type().
static int sp2d(gsl::matrix_short &A, spmatrix_short const &S)
C++ version of gsl_spmatrix_short_sp2d().
static spmatrix_short ccs(spmatrix_short const &spMatrix)
C++ version of gsl_spmatrix_short_ccs().
static int tree_rebuild(spmatrix_short &spMatrix)
C++ version of gsl_spmatrix_short_tree_rebuild().
size_t size2() const
The number of columns of the matrix_short.
void wrap_gsl_spmatrix_short_without_ownership(gsl_spmatrix_short *v)
This function is intended mainly for internal use.
static int equal(spmatrix_short const &a, spmatrix_short const &b)
C++ version of gsl_spmatrix_short_equal().
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_spmatrix_short_fprintf().
spmatrix_short csr() const
C++ version of gsl_spmatrix_short_csr().
spmatrix_short(size_t const n1, size_t const n2)
This constructor creates a new matrix_short with n1 rows and n2 columns.
int equal(spmatrix_short const &b) const
C++ version of gsl_spmatrix_short_equal().
static int set_zero(spmatrix_short &spMatrix)
C++ version of gsl_spmatrix_short_set_zero().
int realloc(size_t const nzmax)
C++ version of gsl_spmatrix_short_realloc().
int fwrite(FILE *stream) const
C++ version of gsl_spmatrix_short_fwrite().
gsl_spmatrix_short const * get() const
Get the gsl_spmatrix_short.
spmatrix_short()
The default constructor is only really useful for assigning to.
short const * data() const
Give access to the data block.
int scale(short const x)
C++ version of gsl_spmatrix_short_scale().
spmatrix_short(gsl_spmatrix_short *v)
Could construct from a gsl_spmatrix_short.
short * data()
Give access to the data block.
spmatrix_short & operator=(spmatrix_short const &v)
The assignment operator.
int fread(FILE *stream)
C++ version of gsl_spmatrix_short_fread().
spmatrix_short clone() const
The clone function.
static int transpose(spmatrix_short &a)
C++ version of gsl_spmatrix_short_transpose().
size_t nnz() const
C++ version of gsl_spmatrix_short_nnz().
size_t use_count() const
Find how many spmatrix_short objects share this pointer.
spmatrix_short compcol() const
C++ version of gsl_spmatrix_short_compcol().
This class handles vector_short objects as shared handles.
gsl_vector_short * get()
Get the gsl_vector_short.
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++.