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_uchar_alloc( n1, n2 );
75 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
77 if( n1 > 0 and n2 > 0 ) gsl_spmatrix_uchar_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_uchar_free(
ccgsl_pointer );
116#ifdef __GXX_EXPERIMENTAL_CXX0X__
121 spmatrix_uchar( std::initializer_list<std::initializer_list<unsigned char> > 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_uchar 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_uchar_free(
ccgsl_pointer );
142 for(
auto row : initializer_list ){
144 for(
auto x : row ){
set( r, c, x ); ++c; }
185 gsl_spmatrix_uchar_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_uchar", __FILE__, __LINE__, GSL_EFAULT );
280 unsigned char const*
data()
const {
281 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector_uchar", __FILE__, __LINE__, GSL_EFAULT );
302 size_t nnz()
const {
return gsl_spmatrix_uchar_nnz(
get() ); }
307 char const*
type()
const {
return gsl_spmatrix_uchar_type(
get() ); }
325 gsl_spmatrix_uchar_csc( dest.get(),
get() );
335 gsl_spmatrix_uchar_csr( dest.get(),
get() );
379 int fprintf( FILE* stream,
char const* format )
const {
380 return gsl_spmatrix_uchar_fprintf( stream,
get(), format ); }
387 return gsl_spmatrix_uchar_fwrite( stream,
get() ); }
394 return gsl_spmatrix_uchar_fread( stream,
get() ); }
401 unsigned char get(
size_t const i,
size_t const j )
const {
402 return gsl_spmatrix_uchar_get(
get(), i, j ); }
410 int set(
size_t const i,
size_t const j,
unsigned char const x ){
411 return gsl_spmatrix_uchar_set(
get(), i, j, x ); }
418 unsigned char*
ptr(
size_t const i,
size_t const j )
const {
419 return gsl_spmatrix_uchar_ptr(
get(), i, j ); }
426 int minmax(
unsigned char& min_out,
unsigned char& max_out )
const {
427 return gsl_spmatrix_uchar_minmax(
get(), &min_out, &max_out ); }
434 int min_index(
size_t& imin_out,
size_t& jmin_out )
const {
435 return gsl_spmatrix_uchar_min_index(
get(), &imin_out, &jmin_out ); }
441 int scale(
unsigned char const x ){
return gsl_spmatrix_uchar_scale(
get(), x ); }
448 return gsl_spmatrix_uchar_scale_columns(
get(), x.
get() ); }
455 return gsl_spmatrix_uchar_scale_rows(
get(), x.
get() ); }
481 return gsl_spmatrix_uchar_realloc(
nzmax, spMatrix.
get() ); }
488 return gsl_spmatrix_uchar_nnz( spMatrix.
get() ); }
495 return gsl_spmatrix_uchar_type( spMatrix.
get() ); }
502 return gsl_spmatrix_uchar_set_zero( spMatrix.
get() ); }
509 return gsl_spmatrix_uchar_tree_rebuild( spMatrix.
get() ); }
518 gsl_spmatrix_uchar_csc( dest.get(), spMatrix.
get() );
528 gsl_spmatrix_uchar_csr( dest.get(), spMatrix.
get() );
570 return gsl_spmatrix_uchar_memcpy( dest.
get(), src.
get() ); }
579 return gsl_spmatrix_uchar_fprintf( stream, spMatrix.
get(), format ); }
594 return gsl_spmatrix_uchar_fwrite( stream, spMatrix.
get() ); }
602 return gsl_spmatrix_uchar_fread( stream, spMatrix.
get() ); }
611 return gsl_spmatrix_uchar_add( c.
get(),
a.get(),
b.get() ); }
620 gsl_spmatrix_uchar_add( c.get(),
a.get(),
b.get() );
623#ifndef GSL_DISABLE_DEPRECATED
631 return gsl_spmatrix_uchar_add_to_dense(
a.get(),
b.get() ); }
640 return gsl_spmatrix_uchar_dense_add(
a.get(),
b.get() ); }
648 return gsl_spmatrix_uchar_dense_sub(
a.get(),
b.get() ); }
655 return gsl_spmatrix_uchar_norm1(
a.get() ); }
663 return gsl_spmatrix_uchar_d2sp( S.
get(), A.
get() ); }
671 return gsl_spmatrix_uchar_sp2d( A.
get(), S.
get() ); }
679 return gsl_spmatrix_uchar_equal(
a.get(),
b.get() ); }
699 return gsl_spmatrix_uchar_transpose_memcpy( dest.
get(), src.
get() ); }
737#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_uchar objects as shared handles.
gsl_matrix_uchar * get()
Get the gsl_matrix_uchar.
This class handles sparse matrix_uchar objects as shared handles.
spmatrix_uchar ccs() const
C++ version of gsl_spmatrix_uchar_ccs().
static spmatrix_uchar crs(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_crs().
int sptype() const
The type of the spmatrix_uchar.
static int fprintf(FILE *stream, spmatrix_uchar const &spMatrix, char const *format)
C++ version of gsl_spmatrix_uchar_fprintf().
static spmatrix_uchar csc(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_csc().
spmatrix_uchar csc() const
C++ version of gsl_spmatrix_uchar_csc().
int realloc(size_t const nzmax)
C++ version of gsl_spmatrix_uchar_realloc().
@ TRIPLET
GSL_SPMATRIX_TRIPLET.
static spmatrix_uchar fscanf(FILE *stream)
C++ version of gsl_spmatrix_uchar_fscanf().
spmatrix_uchar(gsl_spmatrix_uchar *v)
Could construct from a gsl_spmatrix_uchar.
spmatrix_uchar(std::initializer_list< std::initializer_list< unsigned char > > initializer_list)
Could construct from a std::initializer_list in C++11 and later.
static int memcpy(spmatrix_uchar &dest, spmatrix_uchar const &src)
C++ version of gsl_spmatrix_uchar_memcpy().
int scale_rows(gsl::vector_uchar const &x)
C++ version of gsl_spmatrix_uchar_scale_rows().
static int fwrite(FILE *stream, spmatrix_uchar &spMatrix)
C++ version of gsl_spmatrix_uchar_fwrite().
spmatrix_uchar compress(int const sptype) const
C++ version of gsl_spmatrix_uchar_compress().
int scale(unsigned char const x)
C++ version of gsl_spmatrix_uchar_scale().
int fwrite(FILE *stream) const
C++ version of gsl_spmatrix_uchar_fwrite().
static spmatrix_uchar csr(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_csr().
int transpose()
C++ version of gsl_spmatrix_uchar_transpose().
static int realloc(size_t const nzmax, gsl::spmatrix_uchar &spMatrix)
C++ version of gsl_spmatrix_uchar_realloc(): matches a function in gsl that is intended for internal ...
int fread(FILE *stream)
C++ version of gsl_spmatrix_uchar_fread().
int scale_columns(gsl::vector_uchar const &x)
C++ version of gsl_spmatrix_uchar_scale_columns().
static int add(spmatrix_uchar &c, spmatrix_uchar const &a, spmatrix_uchar const &b)
C++ version of gsl_spmatrix_uchar_add().
static int fread(FILE *stream, spmatrix_uchar &spMatrix)
C++ version of gsl_spmatrix_uchar_fread().
spmatrix_uchar & operator=(spmatrix_uchar const &v)
The assignment operator.
static int d2sp(gsl::spmatrix_uchar &S, gsl::matrix_uchar const &A)
C++ version of gsl_spmatrix_uchar_d2sp().
int set(size_t const i, size_t const j, unsigned char const x)
C++ version of gsl_spmatrix_uchar_set().
static int tree_rebuild(spmatrix_uchar &spMatrix)
C++ version of gsl_spmatrix_uchar_tree_rebuild().
int min_index(size_t &imin_out, size_t &jmin_out) const
C++ version of gsl_spmatrix_uchar_min_index().
~spmatrix_uchar()
The destructor only deletes the pointers if count reaches zero.
unsigned char * ptr(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_uchar_ptr().
gsl_spmatrix_uchar * ccgsl_pointer
The shared pointer.
static int set_zero(spmatrix_uchar &spMatrix)
C++ version of gsl_spmatrix_uchar_set_zero().
char const * type() const
C++ version of gsl_spmatrix_uchar_type().
size_t nnz() const
C++ version of gsl_spmatrix_uchar_nnz().
static spmatrix_uchar compcol(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_compcol().
int transpose2()
C++ version of gsl_spmatrix_uchar_transpose2().
static spmatrix_uchar compress(spmatrix_uchar const &spMatrix, int const sptype)
C++ version of gsl_spmatrix_uchar_compress().
size_t size2() const
The number of columns of the matrix_uchar.
size_t nzmax() const
The maximum number of nonzero elements.
static char const * type(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_type().
size_t use_count() const
Find how many spmatrix_uchar objects share this pointer.
unsigned char get(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_uchar_get().
static int dense_add(gsl::matrix_uchar &a, spmatrix_uchar const &b)
C++ version of gsl_spmatrix_dense_add().
size_t size1() const
The number of rows of the matrix_uchar.
int memcpy(spmatrix_uchar &dest) const
C++ version of gsl_spmatrix_uchar_memcpy().
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_spmatrix_uchar_fprintf().
static int dense_sub(gsl::matrix_uchar &a, spmatrix_uchar const &b)
C++ version of gsl_spmatrix_dense_sub().
spmatrix_uchar csr() const
C++ version of gsl_spmatrix_uchar_csr().
static spmatrix_uchar ccs(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_ccs().
int minmax(unsigned char &min_out, unsigned char &max_out) const
C++ version of gsl_spmatrix_uchar_minmax().
static int transpose(spmatrix_uchar &a)
C++ version of gsl_spmatrix_uchar_transpose().
gsl_spmatrix_uchar const * get() const
Get the gsl_spmatrix_uchar.
static int transpose2(spmatrix_uchar &a)
C++ version of gsl_spmatrix_uchar_transpose2().
spmatrix_uchar compcol() const
C++ version of gsl_spmatrix_uchar_compcol().
void reset()
Stop sharing ownership of the shared pointer.
int set_zero()
C++ version of gsl_spmatrix_uchar_set_zero().
spmatrix_uchar crs() const
C++ version of gsl_spmatrix_uchar_crs().
spmatrix_uchar(size_t const n1, size_t const n2, size_t nzmax, size_t sptype)
This constructor creates a new matrix_uchar with n1 rows and n2 columns.
static int add_to_dense(gsl::matrix_uchar &a, spmatrix_uchar const &b)
C++ version of gsl_spmatrix_add_to_dense().
static uchar norm1(gsl::spmatrix_uchar const &a)
C++ version of gsl_spmatrix_uchar_norm1().
int tree_rebuild()
C++ version of gsl_spmatrix_uchar_tree_rebuild().
unsigned char const * data() const
Give access to the data block.
unsigned char * data()
Give access to the data block.
spmatrix_uchar()
The default constructor is only really useful for assigning to.
spmatrix_uchar clone() const
The clone function.
bool unique() const
Find if this is the only object sharing the gsl_spmatrix_uchar.
size_t * count
The shared reference count.
gsl_spmatrix_uchar * get()
Get the gsl_spmatrix_uchar.
static size_t nnz(spmatrix_uchar const &spMatrix)
C++ version of gsl_spmatrix_uchar_nnz().
spmatrix_uchar(spmatrix_uchar const &v)
The copy constructor.
static int transpose_memcpy(spmatrix_uchar &dest, spmatrix_uchar const &src)
C++ version of gsl_spmatrix_uchar_transpose_memcpy().
static spmatrix_uchar add(spmatrix_uchar const &a, spmatrix_uchar const &b)
C++ version of gsl_spmatrix_uchar_add().
static int equal(spmatrix_uchar const &a, spmatrix_uchar const &b)
C++ version of gsl_spmatrix_uchar_equal().
spmatrix_uchar(spmatrix_uchar &&v)
Move constructor.
void swap(spmatrix_uchar &m)
Swap two spmatrix_uchar objects.
void wrap_gsl_spmatrix_uchar_without_ownership(gsl_spmatrix_uchar *v)
This function is intended mainly for internal use.
spmatrix_uchar(size_t const n1, size_t const n2)
This constructor creates a new matrix_uchar with n1 rows and n2 columns.
spmatrix_uchar & operator=(spmatrix_uchar &&v)
Move operator.
int equal(spmatrix_uchar const &b) const
C++ version of gsl_spmatrix_uchar_equal().
static int sp2d(gsl::matrix_uchar &A, spmatrix_uchar const &S)
C++ version of gsl_spmatrix_uchar_sp2d().
This class handles vector_uchar objects as shared handles.
gsl_vector_uchar * get()
Get the gsl_vector_uchar.
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++.