RsbLib
rsb.hpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2017-2021 Michele Martone
3 
4 This file is part of librsb.
5 
6 librsb is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10 
11 librsb is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with librsb; see the file COPYING.
18 If not, see <http://www.gnu.org/licenses/>.
19 
20 */
49 #ifndef RSB_RSB_HPP_INCLUDED
50 #define RSB_RSB_HPP_INCLUDED
51 
52 #include <iostream> // cout
53 #include <rsb.h> // rsb_*
54 #include <cstdlib> // std::exit
55 #include <vector> // std::vector
56 #include <tuple> // std::tuple
57 #include <limits> // std::limits
58 #include <exception> // std::exception
59 #include <memory> // std::unique_ptr
60 #if defined(RSB_LIBRSB_VER) && ( RSB_LIBRSB_VER >= 10300 )
61 #include <complex> /* if std::complex supported, <complex> included by rsb.h */
62 #endif
63 
64 #if __cplusplus >= 201709L
65 #define RSBP_WANT_CPP20 1
66 #endif
67 
68 #if RSBP_WANT_CPP20
69 #include <span> // std::span
70 #endif /* RSBP_WANT_CPP20 */
71 
72 /* ****** librsb C++ interface: INTERNALS SECTION BEGIN (SCROLL DOWN FOR PUBLIC SECTION) ****** */
73 /* @cond INNERDOC */
74 /* option and debug flags */
75 
76 #define RSBP_WANT_DBG_LWCP 0 /* want librsb wrappers call printout */
77 #ifndef RSBP_WANT_CXX11
78 # if defined(__cplusplus) && (__cplusplus>=201103L)
79 # define RSBP_WANT_CXX11 1
80 # else
81 # define RSBP_WANT_CXX11 0
82 # endif
83 #endif /* RSBP_WANT_CXX11 */
84 
85 /* macros */
86 
87 /* Disable exceptions by defining RSBP_NOTHROW */
88 // #define RSBP_NOTHROW 1
89 
90 #define RSBP_ALWAYS_THROW(E) throw(std::exception{}) /* e.g. constructors */
91 #ifndef RSBP_NOTHROW
92 #define RSBP_THROW(E) throw(std::exception{})
93 #else
94 #define RSBP_THROW(E)
95 #endif /* RSBP_NOTHROW */
96 #define RSBP_PERRORA(E) rsb_perror(stdout, E)
97 #define RSBP_PERROR(ERRVAL) if ( (ERRVAL) != RSB_ERR_NO_ERROR ) { rsb_perror(stdout,(ERRVAL));RSBP_THROW(E);}
98 #define RSBP_PERROR_ALWAYS_THROW(ERRVAL) if ( (ERRVAL) != RSB_ERR_NO_ERROR ) { rsb_perror(stdout,(ERRVAL));RSBP_ALWAYS_THROW(E);}
99 
100 #if RSBP_WANT_CXX11
101 #define RSBP_NULL nullptr
102 #define RSBP_CONSTEXPR constexpr
103 #else /* RSBP_WANT_CXX11 */
104 #define RSBP_NULL NULL
105 #define RSBP_CONSTEXPR /* nothing */
106 #endif /* RSBP_WANT_CXX11 */
107 
108 #define RSBP_STOPP(EC) {std::exit(EC);} /* stop program */
109 #define RSBP_CRERR() RSBP_STOPP(-1) /* critical error */
110 #define RSBP_MFRV(RETVAL) RSBP_PERROR(errval_); return (RETVAL); /* member function return value */
111 #define RSBP_PLOC(OS) OS << __func__ << " in " <<__FILE__ << ":" << __LINE__ /* print location */
112 #define RSBP_PFLOC(OS) OS << "at " <<__FILE__ << "@" << __LINE__<< ":" << __func__ /* print location */
113 #define RSBP_LWCP() if (RSBP_WANT_DBG_LWCP) RSBP_PLOC(RSBP_EOS) << "\n" /* librsb wrappers call printout */
114 #define RSBP_EOS std::cout /* error output stream */
115 #define RSBP_WANT_VFMC() getenv("RSBP_VERBOSE_CALLS") /* want verbose function member call */
116 #define RSBP_VWARNM(MSG) if ( RSBP_WANT_VFMC() ) RSBP_PLOC(RSBP_EOS) << "\n" /* verbose warning message */
117 #define RSBP_ERRORM(MSG) RSBP_PLOC(RSBP_EOS) << ": error: " << MSG << "\n" /* print error message */
118 
119 #define RSBP_EFE(ERRVAL,EXP) ERRVAL = EXP; RSBP_PERROR(ERRVAL); /* error value of function evaluate, followed by error handling */
120 #define RSBP_NFE(EXP) RSBP_EFE(errval_,EXP) /* non const function evaluate */
121 
122 #define RSBP_MFR(ERRVAL) return return_output<Err_t>(ERRVAL); /* non-void member function return */
123 #define RSBP_DFE(EXP) RSBP_EFE(errval,EXP) /* const derived function evaluate*/
124 #define RSBP_CFE(EXP) RSBP_EFE(errval,EXP) /* const function evaluate*/
125 
126 #define RSBP_MDR() RSBP_MFR(errval_); /* default member function return */
127 #define RSBP_STCHK() RSBP_VWARNM(""); if( this->state_ != Valid ) { RSBP_ERRORM("Invalid matrix state (did you initialize it in the proper sequence ?) !\n"); RSBP_ALWAYS_THROW(); } /* status check */
128 
129 // #define RSBP_MSC() RSBP_VWARNM(""); if( this->errval_ != RSB_ERR_NO_ERROR ) { RSBP_ERRORM("Invalid library state !\n"); } /* matrix state check */ // NOTE: may use this in RSBP_CWMFHO, RSBP_NWMFHO, RSBP_CDMFHO ...
130 #define RSBP_LFMH() RSBP_STCHK() /* librsb function member header */
131 #define RSBP_CFMH(DC) rsb_err_t errval = RSB_ERR_NO_ERROR; if (DC) { RSBP_STCHK() ;} /* librsb const function member header */
132 #define RSBP_CNMH(DC) if (DC) { RSBP_STCHK() ;} /* librsb const no-error function member header */
133 
134 #define RSBP_NWMFHO() RSBP_LWCP(); RSBP_LFMH( ) /* non constant wrapper member function heading opening */
135 #define RSBP_CWMFHO() RSBP_LWCP(); RSBP_CFMH(1) /* constant wrapper member function heading opening */
136 #define RSBP_CDMFHO() RSBP_LWCP(); RSBP_CFMH(1) /* constant derived member function heading opening */
137 #define RSBP_CNMFHO() RSBP_CNMH(1) /* constant no-err. member function heading opening */
138 #define RSBP_KWMFHO() RSBP_LWCP(); RSBP_CFMH(0) /* construction wrapper member function heading opening */
139 #define RSBP_LWMFHO() RSBP_LWCP(); /* construction wrapper member function heading opening */ \
140  rsb_err_t errval = RSB_ERR_NO_ERROR; \
141  RSBP_VWARNM(""); if( this->state_ != Begin ) { errval = RSB_ERR_BADARGS; RSBP_ERRORM("Invalid matrix state (did you initialize it in the proper sequence ?) !\n"); RSBP_THROW(errval); RSBP_MFR(errval); } /* status check */
142 
143 #define RSBP_CWMFRE() RSBP_MFR(errval) /* constant wrapper member function return error value */
144 
145 #define RSBP_CFMO() RSBP_RMCI(); RSBP_VWARNM(""); { /* constructor function member heading opening */
146 #define RSBP_CFMC() } /* constructor function member closing */
147 
148 #define RSBP_WANT_IMPLICIT_ORDER 0 // pertains spmm overloads with implicit order
149 #define RSBP_WANT_INLINE_INIT 0 // Putting this to 1 is for debug mode only.
150 #define RSBP_ERRGOTO(ERRVAL,ERRLABEL) { if ( (ERRVAL) != RSB_ERR_NO_ERROR ) { goto ERRLABEL; } };
151 #define RSBP_CANNOT_HONOUR_CSR(NNZ,ROWS,FLAGSA) ( NNZ < 2*((ROWS)+1) && ! RSB_DO_FLAG_HAS(FLAGSA,RSB_FLAG_DEFAULT_RSB_MATRIX_FLAGS) )
152 #ifdef RSB_TRANSPOSITION_INVALID
153 #define RSBP_INVALID_TRANS_CHAR RSB_TRANSPOSITION_INVALID /* since librsb-1.2.0.10 */
154 #else /* RSB_TRANSPOSITION_INVALID */
155 #define RSBP_INVALID_TRANS_CHAR '?'
156 #endif /* RSB_TRANSPOSITION_INVALID */
157 /* ****** librsb C++ interface: INTERNALS SECTION END (SCROLL DOWN FOR PUBLIC SECTION) ****** */
158 
159 #ifndef RSBP_NO_NAMESPACE
160 namespace rsb {
161 #endif /* RSBP_NO_NAMESPACE */
162 
163 using rsb_string_t = std::string; // string type
164 
165 #ifdef RSBP_WANT_CPP20
166 template<typename S>
167 concept RSBP_Scalar_t =
168 #ifdef RSB_NUMERICAL_TYPE_FLOAT
169  std::is_same_v<S, float>
170 #endif
171 #ifdef RSB_NUMERICAL_TYPE_LONG_DOUBLE
172  || std::is_same_v<S, long double>
173 #endif
174 #ifdef RSB_NUMERICAL_TYPE_DOUBLE
175  || std::is_same_v<S, double>
176 #endif
177 #ifdef RSB_NUMERICAL_TYPE_FLOAT_COMPLEX
178  || std::is_same_v<S, std::complex<float>>
179 #endif
180 #ifdef RSB_NUMERICAL_TYPE_DOUBLE_COMPLEX
181  || std::is_same_v<S, std::complex<double>>
182 #endif
183 #ifdef RSB_NUMERICAL_TYPE_LONG_DOUBLE_COMPLEX
184  || std::is_same_v<S, std::complex<long double>>
185 #endif
186 #ifdef RSB_NUMERICAL_TYPE_INT
187  || std::is_same_v<S, int>
188 #endif
189  ;
190 #else
191 #define RSBP_Scalar_t typename
192 #endif
193 
194 #ifdef RSBP_WANT_CPP20
195 template<typename out>
196 concept RSBP_Err_t =
197  std::is_same_v<out, void> ||
198  std::is_same_v<out, rsb_err_t>;
199 #else
200 #define RSBP_Err_t typename
201 #endif
202 
203 #ifdef RSBP_WANT_CPP20
204 template<RSBP_Err_t Err_t>
205 Err_t return_output(rsb_err_t errval) {
206  if constexpr (std::is_same_v<Err_t, void>){
207  } else {
208  return errval;
209  }
210 }
211 #else
212 template<typename Err_t>
213 Err_t return_output(rsb_err_t ) {
214  RSBP_PERROR(RSB_ERR_BADARGS);
215 }
216 template<>
217 void return_output<void>(rsb_err_t errval) {
218  RSBP_PERROR(errval);
219 }
220 template<>
221 rsb_err_t return_output<rsb_err_t>(rsb_err_t errval) {
222  return errval;
223 }
224 #endif
225 /* @endcond */
226 
228 #if __cplusplus >= 201709
229 #define RSBP_DEPRECATED [[deprecated]]
230 #else
231 #define RSBP_DEPRECATED
232 #endif
233 
235 #if __cplusplus >= 201709
236 #define RSBP_NODISCARD [[nodiscard]]
237 #else
238 #define RSBP_NODISCARD
239 #endif
240 
241 #ifndef RSBP_WANT_REV
242 
243 #define RSBP_WANT_REV 0
244 #endif
245 
246 #if RSBP_WANT_REV
247 
248 #define RSBP_RVT template <typename Err_t=rsb_err_t> RSBP_NODISCARD
249 #else /* RSBP_WANT_REV */
250 
251 #define RSBP_RVT template <typename Err_t=void>
252 #endif /* RSBP_WANT_REV */
253 
254 #define RSBP_MSLVRV 10201
255 
269 class RsbLib
270 {
271 private:
272  bool rsb_cpp_initialized_ {false};
273 
274  void initialize(struct rsb_initopts * iop = RSBP_NULL)
275  {
276  if( ! rsb_cpp_initialized_ )
277  {
278  rsb_err_t errval = RSB_ERR_NO_ERROR;
279 #ifdef RSB_LIBRSB_VER
280  if( RSB_LIBRSB_VER < RSBP_MSLVRV )
281  {
282  errval = RSB_ERR_UNSUPPORTED_FEATURE;
283  RSBP_ERRORM("This librsb version (see RSB_LIBRSB_VER) is " << RSB_LIBRSB_VER << " -- and is too old: need at least " << RSBP_MSLVRV );
284  RSBP_ALWAYS_THROW();
285  }
286 #endif /* RSB_LIBRSB_VER */
287  errval = rsb_lib_init( iop ? iop : RSB_NULL_INIT_OPTIONS );
288  if( errval != RSB_ERR_NO_ERROR )
289  {
290  RSBP_ALWAYS_THROW();
291  }
292  rsb_cpp_initialized_ = true;
293  }
294  }
295 public:
296 
297  RSBP_RVT Err_t set_opt_str(const rsb_char_t* opnp, const rsb_char_t* opvp)
298  {
302  rsb_err_t errval = RSB_ERR_NO_ERROR;
303  errval = rsb_lib_set_opt_str(opnp,opvp);
304  RSBP_MFR(errval);
305  }
306 
307  RSBP_RVT Err_t set_opt(enum rsb_opt_t iof, const void*iop)
308  {
312  rsb_err_t errval = RSB_ERR_NO_ERROR;
313  errval = rsb_lib_set_opt(iof,iop);
314  RSBP_MFR(errval);
315  }
316 
317  RSBP_RVT Err_t get_opt(enum rsb_opt_t iof, void*iop) const
318  {
322  rsb_err_t errval = RSB_ERR_NO_ERROR;
323  errval = rsb_lib_get_opt(iof, iop);
324  RSBP_MFR(errval);
325  }
326 
327  rsb_string_t get_opt(enum rsb_opt_t iof) const
328  {
332  rsb_err_t errval = RSB_ERR_NO_ERROR;
333  const char * sp {nullptr};
334  RSB_REINIT_SINGLE_VALUE_GET(RSB_IO_WANT_MEMORY_HIERARCHY_INFO_STRING,&sp,errval);
335  RSBP_PERROR(errval);
336  return rsb_string_t(sp?sp:"");
337  }
338 
339  RSBP_RVT Err_t set_num_threads(rsb_int_t nt)
340  {
344  rsb_err_t errval = RSB_ERR_NO_ERROR;
345  errval = set_opt<rsb_err_t>(RSB_IO_WANT_EXECUTING_THREADS, &nt);
346  RSBP_MFR(errval);
347  }
348 
349  rsb_int_t get_num_threads(void) const
350  {
354  rsb_err_t errval = RSB_ERR_NO_ERROR;
355  rsb_int_t nt{};
356  errval = get_opt<rsb_err_t>(RSB_IO_WANT_EXECUTING_THREADS, &nt);
357  RSBP_PERROR(errval);
358  return nt;
359  }
360 
361  RSBP_RVT Err_t reinit(struct rsb_initopts * iop)
362  {
366  rsb_err_t errval = RSB_ERR_NO_ERROR;
367  errval = rsb_lib_reinit(iop);
368  RSBP_MFR(errval);
369  }
370 
371  RSBP_DEPRECATED RsbLib ( bool verbose ):
372  rsb_cpp_initialized_(false)
373  {
377  struct rsb_initopts tio;
378  auto of { stdout };
379  std::pair<enum rsb_opt_t,void*> vio { RSB_IO_WANT_VERBOSE_INIT, &of };
380  tio.keys = & vio.first;
381  tio.values = & vio.second;
382  tio.n_pairs = 1;
383  tio.action = RSB_IO_SPECIFIER_SET;
384  initialize(verbose ? &tio : RSBP_NULL);
385  }
386 
387  RsbLib (void):
388  rsb_cpp_initialized_(false)
389  {
393  initialize();
394  }
395 
396  size_t meminfo(void)
397  {
404  rsb_err_t errval = RSB_ERR_NO_ERROR;
405  size_t totmem = 0, totall = 0;
406  RSB_REINIT_SINGLE_VALUE_GET(RSB_IO_WANT_MEM_ALLOC_CNT,&totall,errval);
407  if(errval==RSB_ERR_UNSUPPORTED_FEATURE)
408  return 0;
409  RSBP_PERROR(errval);
410  RSB_REINIT_SINGLE_VALUE_GET(RSB_IO_WANT_MEM_ALLOC_TOT,&totmem,errval);
411  RSBP_PERROR(errval);
412  if(totmem || totall)
413  RSBP_EOS << "librsb has allocated " << totmem << " bytes in " << totall << " chunks.\n";
414  return totmem;
415  }
416 
417  ~RsbLib (void)
418  {
425  rsb_err_t errval = RSB_ERR_NO_ERROR;
426 
427  RSB_REINIT_SINGLE_VALUE_SET(RSB_IO_WANT_VERBOSE_EXIT,&stdout,errval);
428  errval |= rsb_lib_exit(RSB_NULL_EXIT_OPTIONS);
429  if( errval != RSB_ERR_NO_ERROR )
430  RSBP_CRERR();
431  }
432 }; /* RsbLib */
433 
434 /* @cond INNERDOC */
435 #if RSBP_WANT_INLINE_INIT
436 static RsbLib rsb_lib;
437 #define RSBP_RMCI() rsb_lib.initialize();
438 #else /* RSBP_WANT_INLINE_INIT */
439 #define RSBP_RMCI()
440 #endif /* RSBP_WANT_INLINE_INIT */
441 
442 namespace rsb_internal
443 {
444 template<typename NT> constexpr rsb_type_t rsb_type_t_for(void) { return RSB_NUMERICAL_TYPE_INVALID_TYPE; }
445 #ifdef RSB_NUMERICAL_TYPE_LONG_DOUBLE
446 template<> constexpr rsb_type_t rsb_type_t_for<long double> (void) { return RSB_NUMERICAL_TYPE_LONG_DOUBLE; }
447 #endif
448 #ifdef RSB_NUMERICAL_TYPE_DOUBLE
449 template<> constexpr rsb_type_t rsb_type_t_for<double> (void) { return RSB_NUMERICAL_TYPE_DOUBLE; }
450 #endif
451 #ifdef RSB_NUMERICAL_TYPE_LONG_DOUBLE_COMPLEX
452 template<> constexpr rsb_type_t rsb_type_t_for<std::complex<long double>> (void) { return RSB_NUMERICAL_TYPE_LONG_DOUBLE_COMPLEX; }
453 #endif
454 #ifdef RSB_NUMERICAL_TYPE_DOUBLE_COMPLEX
455 template<> constexpr rsb_type_t rsb_type_t_for<std::complex<double>> (void) { return RSB_NUMERICAL_TYPE_DOUBLE_COMPLEX; }
456 #endif
457 #ifdef RSB_NUMERICAL_TYPE_FLOAT_COMPLEX
458 template<> constexpr rsb_type_t rsb_type_t_for<std::complex<float>> (void) { return RSB_NUMERICAL_TYPE_FLOAT_COMPLEX; }
459 #endif
460 #ifdef RSB_NUMERICAL_TYPE_FLOAT
461 template<> constexpr rsb_type_t rsb_type_t_for<float> (void) { return RSB_NUMERICAL_TYPE_FLOAT; }
462 #endif
463 #ifdef RSB_NUMERICAL_TYPE_INT
464 template<> constexpr rsb_type_t rsb_type_t_for<int> (void) { return RSB_NUMERICAL_TYPE_INT; }
465 #endif
466 }
467 /* @endcond */
468 
518 template<RSBP_Scalar_t NT>
520 {
521 private:
522 #ifdef RSBP_TESTING_ONLY
523  friend class MatrixConstructors_Test;
524  FRIEND_TEST(MatrixConstructors_Test,MoveAssignment);
525  FRIEND_TEST(MatrixConstructors_Test,Move);
526  FRIEND_TEST(MatrixConstructors_Test,InternalsMoveBadType);
527  FRIEND_TEST(MatrixConstructors_Test,InternalsCtorBadType);
528  FRIEND_TEST(MatrixConstructors_Test,InternalsCtorTypeOk);
529  FRIEND_TEST(MatrixConstructors_Test,InternalsCtorTypeBad);
530  FRIEND_TEST(MatrixConstructors_Test,clone);
531  FRIEND_TEST(LowerTest,compare_same);
532  FRIEND_TEST(LowerTest,compare_different);
533 #endif /* RSBP_TESTING_ONLY */
534  rsb_mtx_t * mtxAp_ {RSBP_NULL};
535 private:
536  rsb_err_t errval_ { RSB_ERR_NO_ERROR };
537  enum State { Invalid, Begin, Valid };
538  enum State state_ { Invalid };
539  const static rsb_type_t typecode_ = rsb_internal::rsb_type_t_for<NT>();
540  RSBP_CONSTEXPR static const NT one = 1.0;
541  RSBP_CONSTEXPR static const NT zero = 0.0;
542  RSBP_CONSTEXPR static const NT defmultbeta = 0.0;
543  RSBP_CONSTEXPR static const NT defmultalpha = 1.0;
544  RSBP_CONSTEXPR static const NT RSBP_NUMT_INVALID = std::numeric_limits<const NT>::max(); // aka DBL_MAX
545 
546 public:
547 
549  enum RsbSym { IsGen = RSB_FLAG_NOFLAGS , IsHer = RSB_FLAG_HERMITIAN , IsSym = RSB_FLAG_SYMMETRIC , IsTri = RSB_FLAG_TRIANGULAR };
550 
551 private:
552  rsb_flags_t _adjustSym( const RsbSym sym = IsGen ) const
553  {
554  rsb_flags_t flags = RSB_FLAG_NOFLAGS;
555 
556  if ( sym == IsGen )
557  ;
558  if ( sym == IsHer )
559  RSB_DO_FLAG_ADD( flags, RSB_FLAG_HERMITIAN);
560  if ( sym == IsSym )
561  RSB_DO_FLAG_ADD( flags, RSB_FLAG_SYMMETRIC);
562  if ( sym == IsTri )
563  RSB_DO_FLAG_ADD( flags, RSB_FLAG_TRIANGULAR);
564  return flags;
565  }
566 
567  bool _is_integer(void) const
568  {
569  return std::numeric_limits<const NT>::is_integer;
570  }
571 
572  RSBP_RVT Err_t perror (const rsb_err_t errval) const
573  {
574  RSBP_MFR(errval);
575  }
576 
577  RSBP_RVT Err_t perror(void) const
578  {
579  this->perror(errval_);
580  return errval_;
581  }
582 
583 public:
584 
585  RsbMatrix(rsb_coo_idx_t nrA, rsb_coo_idx_t ncA, const RsbSym sym = IsGen ):
586  mtxAp_ (RSBP_NULL),
587  errval_ (RSB_ERR_NO_ERROR),
588  state_ ( Invalid )
589  {
602  RSBP_CFMO();
603  const rsb_nnz_idx_t nnzA = 0;
604 
605  this->mtxAp_ = rsb_mtx_alloc_from_coo_begin(nnzA, typecode_, nrA, ncA, _adjustSym( sym ), &errval_);
606  if( errval_ == RSB_ERR_NO_ERROR )
607  state_ = Begin;
608  RSBP_PERROR_ALWAYS_THROW(errval_);
609  RSBP_CFMC();
610  }
611 
612  RsbMatrix( rsb_coo_idx_t nrA, const rsb_coo_idx_t * RP, const rsb_coo_idx_t * JA, const NT * VA, const RsbSym sym = IsGen ):
613  mtxAp_ (RSBP_NULL),
614  errval_ (RSB_ERR_NO_ERROR),
615  state_ ( Invalid )
616  {
622  RSBP_CFMO();
623  const rsb_coo_idx_t ncA = 0;
624  const rsb_blk_idx_t brA = 0, bcA = 0;
625 
626  if ( RP )
627  this->mtxAp_ = rsb_mtx_alloc_from_csr_const(VA, RP, JA, RP[nrA], typecode_, nrA, ncA, brA, bcA, _adjustSym( sym ), &errval_);
628  else
629  this->mtxAp_ = RSBP_NULL,
630  errval_ = RSB_ERR_GENERIC_ERROR;
631 
632  if( errval_ == RSB_ERR_NO_ERROR )
633  state_ = Valid;
634 
635  RSBP_PERROR_ALWAYS_THROW(errval_);
636  RSBP_CFMC();
637  }
638 
639 #if RSBP_WANT_CPP20
640  RsbMatrix( const std::span<const rsb_coo_idx_t> IA, const std::span<const rsb_coo_idx_t> JA, const std::span<const NT> VA, rsb_nnz_idx_t nnzA = RSB_INVALID_NNZ_IDX_VAL, const rsb_flags_t flagsA = RSB_FLAG_NOFLAGS ):
641  mtxAp_ (RSBP_NULL),
642  errval_ (RSB_ERR_NO_ERROR),
643  state_ ( Invalid )
644  {
652  RSBP_CFMO();
653  const rsb_coo_idx_t nrA = 0, ncA = 0;
654  const rsb_blk_idx_t brA = 0, bcA = 0;
655  if ( nnzA == RSB_INVALID_NNZ_IDX_VAL )
656  nnzA = VA.size();
657  this->mtxAp_ = rsb_mtx_alloc_from_coo_const(VA.data(), IA.data(), JA.data(), nnzA, typecode_, nrA, ncA, brA, bcA, flagsA, &errval_);
658 
659  if( errval_ == RSB_ERR_NO_ERROR )
660  state_ = Valid;
661 
662  RSBP_PERROR_ALWAYS_THROW(errval_);
663  RSBP_CFMC();
664  }
665 #endif /* RSBP_WANT_CPP20 */
666 
667  RsbMatrix( const rsb_coo_idx_t * IA, const rsb_coo_idx_t * JA, const NT * VA, rsb_nnz_idx_t nnzA, const rsb_flags_t flagsA = RSB_FLAG_NOFLAGS ):
668  mtxAp_ (RSBP_NULL),
669  errval_ (RSB_ERR_NO_ERROR),
670  state_ ( Invalid )
671  {
679  RSBP_CFMO();
680  const rsb_coo_idx_t nrA = 0, ncA = 0;
681  const rsb_blk_idx_t brA = 0, bcA = 0;
682 
683  if ( ( IA && JA && VA ) || nnzA == 0 )
684  this->mtxAp_ = rsb_mtx_alloc_from_coo_const(VA, IA, JA, nnzA, typecode_, nrA, ncA, brA, bcA, flagsA, &errval_);
685  else
686  this->mtxAp_ = RSBP_NULL,
687  errval_ = RSB_ERR_GENERIC_ERROR;
688 
689  if( errval_ == RSB_ERR_NO_ERROR )
690  state_ = Valid;
691 
692  RSBP_PERROR_ALWAYS_THROW(errval_);
693  RSBP_CFMC();
694  }
695 
696  RsbMatrix( const rsb_char_t * filename, const RsbSym sym = IsGen ):
697  mtxAp_ (RSBP_NULL),
698  errval_ (RSB_ERR_NO_ERROR),
699  state_ ( Invalid )
700  {
706  RSBP_CFMO();
707 
708  this->mtxAp_ = rsb_file_mtx_load(filename, _adjustSym( sym ), typecode_, &errval_);
709  if( errval_ == RSB_ERR_NO_ERROR )
710  state_ = Valid;
711  RSBP_PERROR_ALWAYS_THROW(errval_);
712  RSBP_CFMC();
713  }
714 
715  RsbMatrix( const RsbMatrix & A_Rsb, bool do_trans = false, rsb_flags_t flagsA = RSB_FLAG_NOFLAGS ):
716  mtxAp_ (RSBP_NULL),
717  errval_ (RSB_ERR_NO_ERROR),
718  state_ ( Invalid )
719  {
725  RSBP_CFMO();
726  const rsb_trans_t transA = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
727 
728  if ( RSBP_CANNOT_HONOUR_CSR(A_Rsb.nnz(), A_Rsb.rows(), flagsA) )
729  RSB_DO_FLAG_ADD( flagsA, RSB_FLAG_DEFAULT_COO_MATRIX_FLAGS ); // Note: this is parachute code.
730  errval_ = A_Rsb.clone<rsb_err_t>(&this->mtxAp_/*, rsb_type_t typecode*/, transA, RSBP_NULL, flagsA);
731 
732  if( errval_ == RSB_ERR_NO_ERROR )
733  state_ = Valid;
734  RSBP_PERROR_ALWAYS_THROW(errval_);
735  RSBP_CFMC();
736  }
737 
738 #if defined(RSBP_TESTING_ONLY) || defined(RSBT_TESTING_ONLY) /* it's an users's option to define this */
739  RsbMatrix( rsb_mtx_t*mtxAp ):
740  mtxAp_ (mtxAp),
741  errval_ (RSB_ERR_NO_ERROR),
742  state_ ( mtxAp ? Valid : Invalid )
743  {
748  RSBP_CFMO();
749  errval_ = type_check<rsb_err_t>();
750  RSBP_PERROR_ALWAYS_THROW(errval_);
751  RSBP_CFMC();
752  }
753 #endif /* */
754 
755 private:
756  RsbMatrix(void) = default; // ugly, isn't it ? only here for the move ctor
757 public:
759  {
767  {
768  RsbMatrix swappable;
769  this->swap(swappable);
770  }
771  this->swap(other);
772  }
773 
775  {
783  this->mtxAp_ = rsb_mtx_free (this->mtxAp_);
784  state_ = Invalid;
785  }
786 
787  RSBP_RVT RSBP_DEPRECATED Err_t _add(rsb_coo_idx_t i, rsb_coo_idx_t j, NT val)
788  {
792  RSBP_KWMFHO();
793  RSBP_NFE(set_val<rsb_err_t> (val, i, j, RSB_FLAG_NOFLAGS));
794  RSBP_MDR();
795  }
796 
797  RSBP_RVT Err_t close(void)
798  {
809  RSBP_LWMFHO();
810  RSBP_NFE(rsb_mtx_alloc_from_coo_end (&this->mtxAp_));
811  if( errval_ == RSB_ERR_NO_ERROR )
812  state_ = Valid;
813  RSBP_MDR();
814  }
815 
817  {
821  RSBP_LWMFHO();
822  RSBP_NFE(close<rsb_err_t>());
823  RSBP_MDR();
824  }
825 
826  RSBP_RVT RSBP_DEPRECATED Err_t spmv(rsb_trans_t transA, const NT *alphap, const NT * Xp, rsb_coo_idx_t incX, const NT * betap, NT * Yp, rsb_coo_idx_t incY) const
827  {
832  RSBP_CWMFHO();
833  RSBP_CFE( rsb_spmv(transA, alphap, this->mtxAp_, Xp, incX, betap, Yp, incY) );
834  RSBP_CWMFRE();
835  }
836 
837  RSBP_RVT Err_t spmv(rsb_trans_t transA, const NT alpha, const NT * Xp, rsb_coo_idx_t incX, const NT beta, NT * Yp, rsb_coo_idx_t incY) const
838  {
844  RSBP_CDMFHO();
845  RSBP_DFE( spmv<rsb_err_t>(transA, &alpha, Xp, incX, &beta, Yp, incY) );
846  RSBP_CWMFRE();
847  }
848 
849  RSBP_RVT Err_t spmv(rsb_trans_t transA, const NT alpha, const NT * Xp, const NT beta, NT * Yp) const
850  {
856  RSBP_CDMFHO();
857  const rsb_coo_idx_t incX = 1, incY = 1;
858  RSBP_DFE( spmv<rsb_err_t>(transA, &alpha, Xp, incX, &beta, Yp, incY) );
859  RSBP_CWMFRE();
860  }
861 
862 private:
863  std::pair<rsb_nnz_idx_t,rsb_nnz_idx_t> _get_ldX_ldY(rsb_trans_t transA, rsb_flags_t order = RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, rsb_coo_idx_t nrhs = 1) const
864  {
865  if (order != RSB_FLAG_WANT_COLUMN_MAJOR_ORDER)
866  return {nrhs,nrhs};
867  const auto ldX = ( transA == RSB_TRANSPOSITION_N ) ? this->cols() : this->rows();
868  const auto ldY = ( transA == RSB_TRANSPOSITION_N ) ? this->rows() : this->cols();
869  return {ldX,ldY};
870  }
871 public:
872 
873 #if RSBP_WANT_CPP20
874  RSBP_RVT Err_t spmv(rsb_trans_t transA, const NT alpha, const std::span<const NT> X, const NT beta, std::span<NT> Y) const
875  {
881  RSBP_CWMFHO();
882  const rsb_coo_idx_t incX = 1, incY = 1;
883  const auto [ldX, ldY] = _get_ldX_ldY(transA);
884 
885  if ( static_cast<rsb_nnz_idx_t>(X.size()) < ldX || static_cast<rsb_nnz_idx_t>(Y.size()) < ldY )
886  {
887  errval = RSB_ERR_BADARGS;
888  RSBP_PERROR(errval);
889  RSBP_MFR(errval);
890  }
891  RSBP_CFE( rsb_spmv(transA, &alpha, this->mtxAp_, X.data(), incX, &beta, Y.data(), incY) );
892  RSBP_CWMFRE();
893  }
894 #endif /* RSBP_WANT_CPP20 */
895 
896  RSBP_RVT Err_t spmv(NT * y, const NT * x, bool do_trans = false) const
897  {
903  RSBP_CDMFHO();
904  const rsb_trans_t transA = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
905  const NT alpha = defmultalpha;
906  const NT beta = defmultbeta;
907  const rsb_coo_idx_t incX = 1, incY = 1;
908  RSBP_DFE( spmv<rsb_err_t>(transA, &alpha, x, incX, &beta, y, incY) );
909  RSBP_CWMFRE();
910  }
911 
912  RSBP_RVT RSBP_DEPRECATED Err_t spmm(rsb_trans_t transA, const NT * alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, rsb_nnz_idx_t ldB, const NT * betap, NT * Cp, rsb_nnz_idx_t ldC) const
913  {
918  RSBP_CWMFHO();
919  RSBP_CFE ( rsb_spmm (transA,alphap,this->mtxAp_,nrhs,order,Bp,ldB,betap,Cp,ldC) );
920  RSBP_CWMFRE();
921  }
922 
923  RSBP_RVT Err_t spmm(rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, rsb_nnz_idx_t ldB, const NT beta, NT * Cp, rsb_nnz_idx_t ldC) const
924  {
930  RSBP_CDMFHO();
931  RSBP_DFE ( spmm<rsb_err_t> (transA,&alpha,nrhs,order,Bp,ldB,&beta,Cp,ldC) );
932  RSBP_CWMFRE();
933  }
934 
935  RSBP_RVT Err_t spmm(rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, const NT beta, NT * Cp) const
936  {
940  const rsb_nnz_idx_t ldC {}, ldB {};
941  RSBP_CDMFHO();
942  RSBP_DFE ( spmm<rsb_err_t> (transA,&alpha,nrhs,order,Bp,ldB,&beta,Cp,ldC) );
943  RSBP_CWMFRE();
944  }
945 
946 #if RSBP_WANT_IMPLICIT_ORDER
947  RSBP_RVT RSBP_DEPRECATED Err_t spmm(rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, const NT * Bp, const NT beta, NT * Cp) const
948  {
952  RSBP_CDMFHO();
953  bool do_trans = ( transA == RSB_TRANSPOSITION_N ? false : true );
954  const rsb_coo_idx_t ldC = do_trans ? cols():rows(), ldB = do_trans ? rows():cols();
955  const rsb_flags_t order = RSB_FLAG_WANT_COLUMN_MAJOR_ORDER;
956  RSBP_DFE ( spmm<rsb_err_t> (transA,&alpha,nrhs,order,Bp,ldB,&beta,Cp,ldC) );
957  RSBP_CWMFRE();
958  }
959 #endif /* RSBP_WANT_IMPLICIT_ORDER */
960 
961 #if RSBP_WANT_IMPLICIT_ORDER
962  RSBP_RVT RSBP_DEPRECATED Err_t spmm(rsb_trans_t transA, const NT * alphap, rsb_coo_idx_t nrhs, const NT * Bp, const NT * betap, NT * Cp) const
963  {
969  RSBP_CDMFHO();
970  RSBP_DFE ( spmm<rsb_err_t> (transA,*alphap,nrhs,Bp,*betap,Cp) );
971  RSBP_CWMFRE();
972  }
973 #endif /* RSBP_WANT_IMPLICIT_ORDER */
974 
975 #if RSBP_WANT_IMPLICIT_ORDER
976  RSBP_RVT RSBP_DEPRECATED Err_t spmm(NT * y, const NT * x, rsb_coo_idx_t nrhs, bool do_trans = false) const
977  {
981  RSBP_CDMFHO();
982  const rsb_trans_t transA = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
983  const NT alpha = defmultalpha;
984  const NT beta = defmultbeta;
985  const rsb_coo_idx_t ldC = do_trans ? cols():rows(), ldB = do_trans ? rows():cols();
986  const rsb_flags_t order = RSB_FLAG_WANT_COLUMN_MAJOR_ORDER;
987  RSBP_DFE( spmm<rsb_err_t>(transA, &alpha, nrhs, order, x, ldB, &beta, y, ldC) );
988  RSBP_CWMFRE();
989  }
990 #endif /* RSBP_WANT_IMPLICIT_ORDER */
991 
992 #if RSBP_WANT_CPP20
993  RSBP_RVT Err_t spmm(rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const std::span<const NT> x, const NT beta, std::span<NT> y) const
994  {
998  RSBP_CWMFHO();
999  const auto [ldB, ldC] = _get_ldX_ldY(transA,order,nrhs);
1000  RSBP_CFE ( rsb_spmm (transA,&alpha,this->mtxAp_,nrhs,order,x.data(),ldB,&beta,y.data(),ldC) );
1001  RSBP_CWMFRE();
1002  }
1003 #endif /* RSBP_WANT_CPP20 */
1004 
1005  RSBP_RVT RSBP_DEPRECATED Err_t spsm(rsb_trans_t transT, const NT * alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * betap, const NT * Bp, rsb_nnz_idx_t ldB, NT * Cp, rsb_nnz_idx_t ldC) const
1006  {
1011  RSBP_CWMFHO();
1012  RSBP_CFE( rsb_spsm (transT,alphap,this->mtxAp_,nrhs,order,betap,Bp,ldB,Cp,ldC) );
1013  RSBP_CWMFRE();
1014  }
1015 
1016  RSBP_RVT Err_t spsm(rsb_trans_t transT, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT beta, const NT * Bp, rsb_nnz_idx_t ldB, NT * Cp, rsb_nnz_idx_t ldC) const
1017  {
1021  RSBP_CDMFHO();
1022  RSBP_DFE( spsm<rsb_err_t> (transT,&alpha,nrhs,order,&beta,Bp,ldB,Cp,ldC) );
1023  RSBP_CWMFRE();
1024  }
1025 
1026  RSBP_RVT Err_t spsm(rsb_trans_t transT, const NT alpha, rsb_coo_idx_t nrhs, const NT * Bp, NT * Cp) const
1027  {
1031  RSBP_CDMFHO();
1032  const rsb_coo_idx_t ldC = rows(), ldB = ldC;
1033  const rsb_flags_t order = RSB_FLAG_WANT_COLUMN_MAJOR_ORDER;
1034  const NT beta = defmultbeta;
1035  RSBP_DFE( spsm<rsb_err_t> (transT,&alpha,nrhs,order,&beta,Bp,ldB,Cp,ldC) );
1036  RSBP_CWMFRE();
1037  }
1038 
1039  RSBP_RVT Err_t spsm(NT * y, const NT * x, rsb_coo_idx_t nrhs, bool do_trans = false) const
1040  {
1044  RSBP_CDMFHO();
1045  const rsb_trans_t transA = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
1046  const NT alpha = one;
1047  const NT beta = zero;
1048  const rsb_coo_idx_t ldC = rows(), ldB = ldC;
1049  RSBP_DFE( spsm<rsb_err_t> (transA,&alpha,nrhs,RSB_FLAG_WANT_COLUMN_MAJOR_ORDER,&beta,x,ldB,y,ldC));
1050  RSBP_CWMFRE();
1051  }
1052 
1053  RSBP_RVT Err_t spsm(NT * y, rsb_coo_idx_t nrhs, bool do_trans = false) const
1054  {
1058  RSBP_CDMFHO();
1059  RSBP_DFE( spsm<rsb_err_t> (y,y,nrhs,do_trans ));
1060  RSBP_CWMFRE();
1061  }
1062 
1063  RSBP_RVT RSBP_DEPRECATED Err_t spsv(rsb_trans_t transT, const NT * alphap, const NT * Xp, rsb_coo_idx_t incX, NT * Yp, rsb_coo_idx_t incY) const
1064  {
1069  RSBP_CWMFHO();
1070  RSBP_CFE( rsb_spsv(transT,alphap,this->mtxAp_,Xp,incX,Yp,incY) );
1071  RSBP_CWMFRE();
1072  }
1073 
1074  RSBP_RVT Err_t spsv(rsb_trans_t transT, const NT alpha, const NT * Xp, NT * Yp) const
1075  {
1079  RSBP_CWMFHO();
1080  const rsb_coo_idx_t incX = 1, incY = 1;
1081  RSBP_CFE( spsv<rsb_err_t>(transT,&alpha,Xp,incX,Yp,incY) );
1082  RSBP_CWMFRE();
1083  }
1084 
1085  RSBP_RVT Err_t spsv(NT * y, const NT * x, bool do_trans = false) const
1086  {
1090  RSBP_CDMFHO();
1091  const rsb_trans_t transA = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
1092  const NT alpha = one;
1093  const rsb_coo_idx_t incX = 1, incY = 1;
1094  RSBP_DFE( spsv<rsb_err_t>(transA,&alpha,x,incX,y,incY) );
1095  RSBP_CWMFRE();
1096  }
1097 
1098  RSBP_RVT Err_t spsv(NT * y, bool do_trans = false) const
1099  {
1103  RSBP_CDMFHO();
1104  const rsb_trans_t transA = do_trans ? RSB_TRANSPOSITION_T : RSB_TRANSPOSITION_N;
1105  const NT alpha = one;
1106  const rsb_coo_idx_t incY = 1;
1107  RSBP_DFE( spsv<rsb_err_t>(transA,&alpha,y,incY,y,incY) );
1108  RSBP_CWMFRE();
1109  }
1110 
1111  size_t get_info_size_t(enum rsb_mif_t mif) const
1112  {
1116  RSBP_CWMFHO();
1117  size_t val = 0;
1118  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1119  RSBP_MFRV(val);
1120  }
1121 
1122  rsb_flags_t get_info_rsb_flags_t(enum rsb_mif_t mif) const
1123  {
1127  RSBP_CWMFHO();
1128  rsb_flags_t val = 0;
1129  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1130  RSBP_MFRV(val);
1131  }
1132 
1133  rsb_blk_idx_t get_info_blk_t(enum rsb_mif_t mif) const
1134  {
1138  RSBP_CWMFHO();
1139  rsb_blk_idx_t val = 0;
1140  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1141  RSBP_MFRV(val);
1142  }
1143 
1144  rsb_nnz_idx_t get_info_nnz_t(enum rsb_mif_t mif) const
1145  {
1149  RSBP_CWMFHO();
1150  rsb_nnz_idx_t val = 0;
1151  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1152  RSBP_MFRV(val);
1153  }
1154 
1155  rsb_flags_t get_flags_t(enum rsb_mif_t mif) const
1156  {
1160  RSBP_CWMFHO();
1161  rsb_flags_t val = 0;
1162  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1163  RSBP_MFRV(val);
1164  }
1165 
1166  rsb_type_t get_type_t(enum rsb_mif_t mif) const
1167  {
1171  RSBP_CWMFHO();
1172  rsb_type_t val = 0;
1173  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1174  RSBP_MFRV(val);
1175  }
1176 
1177  rsb_coo_idx_t get_info_coo_t(enum rsb_mif_t mif) const
1178  {
1182  RSBP_CWMFHO();
1183  rsb_coo_idx_t val = 0;
1184  RSBP_DFE( rsb_mtx_get_info(this->mtxAp_,mif,&val));
1185  RSBP_MFRV(val);
1186  }
1187 
1188  size_t _get_index_storage_bytes(void) const
1189  {
1193  return get_info_size_t(RSB_MIF_INDEX_STORAGE_IN_BYTES__TO__SIZE_T);
1194  }
1195 
1196  size_t _get_storage_bytes(void) const
1197  {
1201  return _get_index_storage_bytes() + 2 * sizeof(NT) * nnz();
1202  }
1203 
1204 private:
1205  void swap(RsbMatrix & other)
1206  {
1207  std::swap(this->mtxAp_,other.mtxAp_);
1208  std::swap(this->state_,other.state_);
1209  }
1210 
1211  RSBP_RVT Err_t type_check(void)
1212  {
1213  RSBP_KWMFHO();
1214  if ( rsbtype() != get_type_t(RSB_MIF_MATRIX_TYPECODE__TO__RSB_TYPE_T) )
1215  {
1216  errval_ = RSB_ERR_BADARGS;
1217  RSBP_PERROR(RSB_ERR_BADARGS);
1218  }
1219  RSBP_MDR();
1220  }
1221 
1222  RSBP_RVT Err_t use_mtx_ptr(struct rsb_mtx_t * mtxBp)
1223  {
1224  RSBP_KWMFHO();
1225  if( mtxBp != RSBP_NULL && mtxBp != this->mtxAp_ )
1226  {
1227  rsb_mtx_free (this->mtxAp_);
1228  this->mtxAp_ = mtxBp;
1229  }
1230  errval_ = type_check<rsb_err_t>();
1231  RSBP_MDR();
1232  }
1233 public:
1234 
1235  rsb_nnz_idx_t nnz(void) const
1236  {
1239  RSBP_CNMFHO();
1240  RSBP_MFRV(get_info_nnz_t(RSB_MIF_MATRIX_NNZ__TO__RSB_NNZ_INDEX_T));
1241  }
1242 
1243  rsb_blk_idx_t blocks(void) const
1244  {
1247  RSBP_CNMFHO();
1248  RSBP_MFRV(get_info_blk_t(RSB_MIF_LEAVES_COUNT__TO__RSB_BLK_INDEX_T));
1249  }
1250 
1251  rsb_coo_idx_t rows(void) const
1252  {
1256  RSBP_CNMFHO();
1257  RSBP_MFRV(get_info_coo_t(RSB_MIF_MATRIX_ROWS__TO__RSB_COO_INDEX_T));
1258  }
1259 
1260  rsb_coo_idx_t cols(void) const
1261  {
1265  RSBP_CNMFHO();
1266  RSBP_MFRV(get_info_coo_t(RSB_MIF_MATRIX_COLS__TO__RSB_COO_INDEX_T));
1267  }
1268 
1269  RSBP_RVT Err_t get_vals(NT* VA, const rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA, rsb_nnz_idx_t nnz, rsb_flags_t flags) const
1270  {
1274  RSBP_CWMFHO();
1275  RSBP_CFE(rsb_mtx_get_vals(this->mtxAp_, VA, IA, JA, nnz, flags));
1276  RSBP_MDR();
1277  }
1278 
1279  NT get_val(const rsb_coo_idx_t i, const rsb_coo_idx_t j, rsb_flags_t flags = RSB_FLAG_NOFLAGS) const
1280  {
1284  NT val {};
1285  rsb_mtx_get_vals(this->mtxAp_, &val, &i, &j, 1, flags);
1286  return val;
1287  }
1288 
1289  RSBP_RVT Err_t set_val(const NT val, const rsb_coo_idx_t i, const rsb_coo_idx_t j, rsb_flags_t flags = RSB_FLAG_NOFLAGS)
1290  {
1298  RSBP_KWMFHO();
1299  RSBP_NFE(rsb_mtx_set_vals (this->mtxAp_, &val, &i, &j, 1, flags));
1300  RSBP_MDR();
1301  }
1302 
1303  RSBP_RVT Err_t set_vals(const NT * VA, const rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA, rsb_nnz_idx_t nnz, rsb_flags_t flags)
1304  {
1314  RSBP_KWMFHO();
1315  RSBP_NFE(rsb_mtx_set_vals (this->mtxAp_, VA, IA, JA, nnz, flags));
1316  RSBP_MDR();
1317  }
1318 
1319  RSBP_RVT Err_t get_vec(NT * Dp, enum rsb_extff_t flags) const
1320  {
1324  RSBP_CWMFHO();
1325  RSBP_CFE(rsb_mtx_get_vec(this->mtxAp_, Dp, flags));
1326  RSBP_MDR();
1327  }
1328 
1329  RSBP_RVT RSBP_DEPRECATED Err_t get_coo(rsb_trans_t transA, NT * VA, rsb_coo_idx_t * IA, rsb_coo_idx_t * JA, rsb_flags_t flags ) const
1330  {
1336  RSBP_CWMFHO();
1337 
1338  RSBP_CFE(rsb_mtx_get_coo(this->mtxAp_, VA, IA, JA, flags));
1339  RSBP_CWMFRE();
1340  }
1341 
1342  RSBP_RVT RSBP_DEPRECATED Err_t get_csr(rsb_trans_t transA, NT * VA, rsb_coo_idx_t * RP, rsb_coo_idx_t * JA, rsb_flags_t flags ) const
1343  {
1349  RSBP_CWMFHO();
1350 
1351  RSBP_CFE(rsb_mtx_get_csr(RSB_NUMERICAL_TYPE_SAME_TYPE, this->mtxAp_, VA, RP, JA, flags));
1352  RSBP_CWMFRE();
1353  }
1354 
1355  RSBP_RVT RSBP_DEPRECATED Err_t get_rows_sparse(rsb_trans_t transA, const NT * alphap, NT * VA, rsb_coo_idx_t * IA, rsb_coo_idx_t * JA, rsb_coo_idx_t frA, rsb_coo_idx_t lrA, rsb_nnz_idx_t *rnzp, rsb_flags_t flags ) const
1356  {
1362  RSBP_CWMFHO();
1363  RSBP_CFE(rsb_mtx_get_rows_sparse(transA, alphap, this->mtxAp_, VA, IA, JA, frA, lrA, rnzp, flags));
1364  RSBP_CWMFRE();
1365  }
1366 
1367  RSBP_RVT Err_t upd_vals(enum rsb_elopf_t elop_flags, const NT & omega)
1368  {
1374  RSBP_NWMFHO();
1375  RSBP_NFE(rsb_mtx_upd_vals(this->mtxAp_, elop_flags, &omega));
1376  RSBP_MDR();
1377  }
1378 
1379  RSBP_RVT Err_t upd_vals(enum rsb_elopf_t elop_flags, const NT * omegap)
1380  {
1386  RSBP_NWMFHO();
1387  RSBP_NFE(rsb_mtx_upd_vals(this->mtxAp_, elop_flags, omegap));
1388  RSBP_MDR();
1389  }
1390 
1391  RSBP_RVT Err_t get_nrm(NT * Np, enum rsb_extff_t flags) const
1392  {
1396  RSBP_CWMFHO();
1397  RSBP_CFE(rsb_mtx_get_nrm(this->mtxAp_, Np, flags));
1398  RSBP_MDR();
1399  }
1400 
1401  rsb_type_t rsbtype(void) const
1402  {
1406  RSBP_CNMFHO();
1407  RSBP_MFRV(typecode_);
1408  }
1409 
1410  rsb_flags_t rsbflags(void) const
1411  {
1414  RSBP_CNMFHO();
1415  RSBP_MFRV(get_flags_t(RSB_MIF_MATRIX_FLAGS__TO__RSB_FLAGS_T));
1416  }
1417 
1418  rsb_string_t get_info_str(const char * key) const
1419  {
1423  RSBP_CDMFHO();
1424  const auto RSBP_INFOBUF { 256 };
1425  char ss[RSBP_INFOBUF];
1426  RSBP_CFE(rsb_mtx_get_info_str(this->mtxAp_,key,ss,RSBP_INFOBUF));
1427  RSBP_MFRV(rsb_string_t(ss));
1428  }
1429 
1430  RSBP_RVT Err_t get_info(enum rsb_mif_t miflags, void* minfop)const
1431  {
1435  RSBP_CWMFHO();
1436  RSBP_CFE(rsb_mtx_get_info(this->mtxAp_, miflags, minfop));
1437  RSBP_MDR();
1438  }
1439 
1440  rsb_string_t _info(void) const
1441  {
1445  RSBP_CNMFHO();
1446  RSBP_MFRV(get_info_str("RSB_MIF_MATRIX_INFO__TO__CHAR_P"));
1447  }
1448 
1449  RSBP_RVT RSBP_DEPRECATED Err_t tune_spsm_threads(/*RsbMatrix * mtxp,*/ rsb_real_t *sfp=RSBP_NULL, rsb_int_t *tnp=RSBP_NULL, rsb_int_t maxr=0, rsb_time_t maxt=0, rsb_trans_t transA=RSB_TRANSPOSITION_N, const NT * alphap=RSBP_NULL, rsb_coo_idx_t nrhs=1, rsb_flags_t order=RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, const NT * Bp=RSBP_NULL, rsb_nnz_idx_t ldB=0, const NT * betap=RSBP_NULL, NT * Cp=RSBP_NULL, rsb_nnz_idx_t ldC=0) const
1450  {
1456  RSBP_CWMFHO();
1457 
1458  RSBP_CFE(rsb_tune_spsm(RSBP_NULL, sfp, tnp, maxr, maxt, transA, alphap, this->mtxAp_, nrhs, order, Bp, ldB, betap, Cp, ldC));
1459  RSBP_MDR();
1460  }
1461 
1462  RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm_threads(/*RsbMatrix * mtxp,*/ rsb_real_t *sfp=RSBP_NULL, rsb_int_t *tnp=RSBP_NULL, rsb_int_t maxr=0, rsb_time_t maxt=0, rsb_trans_t transA=RSB_TRANSPOSITION_N, const NT * alphap=RSBP_NULL, rsb_coo_idx_t nrhs=1, rsb_flags_t order=RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, const NT * Bp=RSBP_NULL, rsb_nnz_idx_t ldB=0, const NT * betap=RSBP_NULL, NT * Cp=RSBP_NULL, rsb_nnz_idx_t ldC=0) const
1463  {
1470  RSBP_CWMFHO();
1471 
1472  RSBP_CFE(rsb_tune_spmm(RSBP_NULL, sfp, tnp, maxr, maxt, transA, alphap, this->mtxAp_, nrhs, order, Bp, ldB, betap, Cp, ldC));
1473  RSBP_MDR();
1474  }
1475 
1476  RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm(/*RsbMatrix * mtxp,*/ rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT * alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, rsb_nnz_idx_t ldB, const NT * betap, NT * Cp, rsb_nnz_idx_t ldC)
1477  {
1485  RSBP_NWMFHO();
1486 
1487  if(true)
1488  {
1489  struct rsb_mtx_t * mtxBp {};
1490  RSBP_NFE(rsb_tune_spmm(&mtxBp, sfp, tnp, maxr, maxt, transA, alphap, this->mtxAp_, nrhs, order, Bp, ldB, betap, Cp, ldC));
1491  errval_ = use_mtx_ptr<rsb_err_t>(mtxBp);
1492  }
1493  else
1494  {
1495  // Note: case not ready yet; may want a new member function for this.
1496  RSBP_NFE(rsb_tune_spmm(&(this->mtxAp_), sfp, tnp, maxr, maxt, transA, alphap, RSBP_NULL, nrhs, order, Bp, ldB, betap, Cp, ldC));
1497  }
1498  RSBP_MDR();
1499  }
1500 
1501  RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm(/*RsbMatrix * mtxp,*/ rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, rsb_nnz_idx_t ldB, const NT beta, NT * Cp, rsb_nnz_idx_t ldC)
1502  {
1509  RSBP_CWMFHO();
1510  RSBP_CFE( tune_spmm<rsb_err_t>(/*RsbMatrix * mtxp,*/ sfp, tnp, maxr, maxt, transA, &alpha, nrhs, order, Bp, ldB, &beta, Cp, ldC) );
1511  RSBP_CWMFRE();
1512  }
1513 
1514  RSBP_RVT Err_t tune_spmm(rsb_real_t & sf, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, const NT beta, NT * Cp)
1515  {
1521  rsb_int_t *tnp {nullptr};
1522  const rsb_int_t maxr {0};
1523  const rsb_time_t maxt {0.0};
1524  const std::pair<rsb_nnz_idx_t,rsb_nnz_idx_t> ldX = _get_ldX_ldY(transA,order,nrhs);
1525 # if defined(__cplusplus) && (__cplusplus>=201709L)
1526  const auto [ldB, ldC] = ldX;
1527 #else
1528  const rsb_nnz_idx_t ldB = ldX.first, ldC = ldX.second;
1529 #endif
1530 
1531  RSBP_CWMFHO();
1532  RSBP_CFE( tune_spmm<rsb_err_t>(/*RsbMatrix * mtxp,*/ &sf, tnp, maxr, maxt, transA, &alpha, nrhs, order, Bp, ldB, &beta, Cp, ldC) );
1533  RSBP_CWMFRE();
1534  }
1535 
1536 #if RSBP_WANT_CPP20
1537  RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm(rsb_real_t & sf, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const std::span<const NT> B, rsb_nnz_idx_t ldB, const NT beta, std::span<NT> C, rsb_nnz_idx_t ldC)
1538  {
1544  rsb_int_t *tnp {nullptr};
1545  const rsb_int_t maxr {0};
1546  const rsb_time_t maxt {0.0};
1547  RSBP_CWMFHO();
1548  RSBP_CFE( tune_spmm<rsb_err_t>(/*RsbMatrix * mtxp,*/ &sf, tnp, maxr, maxt, transA, &alpha, nrhs, order, B.data(), ldB, &beta, C.data(), ldC) );
1549  RSBP_CWMFRE();
1550  }
1551 
1552  RSBP_RVT Err_t tune_spmm(rsb_real_t & sf, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const std::span<const NT> B, const NT beta, std::span<NT> C)
1553  {
1559  rsb_int_t *tnp {nullptr};
1560  const rsb_int_t maxr {0};
1561  const rsb_time_t maxt {0.0};
1562  const auto [ldB, ldC] = _get_ldX_ldY(transA,order,nrhs);
1563  RSBP_NWMFHO();
1564  struct rsb_mtx_t * mtxBp {};
1565  RSBP_NFE(rsb_tune_spmm(&mtxBp, &sf, tnp, maxr, maxt, transA, &alpha, this->mtxAp_, nrhs, order, B.data(), ldB, &beta, C.data(), ldC));
1566  errval_ = use_mtx_ptr<rsb_err_t>(mtxBp);
1567  RSBP_MDR();
1568  }
1569 
1570  RSBP_RVT RSBP_DEPRECATED Err_t tune_spmm(/*RsbMatrix * mtxp,*/ rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const std::span<const NT> B, rsb_nnz_idx_t ldB, const NT beta, std::span<NT> C, rsb_nnz_idx_t ldC)
1571  {
1578  RSBP_CWMFHO();
1579  RSBP_CFE( tune_spmm<rsb_err_t>(/*RsbMatrix * mtxp,*/ sfp, tnp, maxr, maxt, transA, &alpha, nrhs, order, B.data(), ldB, &beta, C.data(), ldC) );
1580  RSBP_CWMFRE();
1581  }
1582 #endif /* RSBP_WANT_CPP20 */
1583 
1584  RSBP_RVT RSBP_DEPRECATED Err_t tune_spsm(/*RsbMatrix * mtxp,*/ rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT * alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT * Bp, rsb_nnz_idx_t ldB, const NT * betap, NT * Cp, rsb_nnz_idx_t ldC)
1585  {
1591  RSBP_NWMFHO();
1592 
1593  if(true)
1594  {
1595  struct rsb_mtx_t * mtxBp {};
1596  RSBP_NFE(rsb_tune_spsm(&mtxBp, sfp, tnp, maxr, maxt, transA, alphap, this->mtxAp_, nrhs, order, Bp, ldB, betap, Cp, ldC));
1597  use_mtx_ptr(mtxBp);
1598  }
1599  else
1600  {
1601  // Note: case not ready yet; may want a new member function for this.
1602  RSBP_NFE(rsb_tune_spsm(&(this->mtxAp_), sfp, tnp, maxr, maxt, transA, alphap, RSBP_NULL, nrhs, order, Bp, ldB, betap, Cp, ldC));
1603  }
1604  RSBP_MDR();
1605  }
1606 
1607  RSBP_RVT Err_t file_save(const rsb_char_t * filename=RSBP_NULL) const
1608  {
1614  RSBP_CWMFHO();
1615  RSBP_CFE(rsb_file_mtx_save(this->mtxAp_, filename));
1616  RSBP_MDR();
1617  }
1618 
1619 private:
1620  RSBP_RVT RSBP_DEPRECATED Err_t clone(struct rsb_mtx_t ** mtxBpp/*, rsb_type_t typecode*/, rsb_trans_t transA = RSB_TRANSPOSITION_N, const NT *alphap = RSBP_NULL, rsb_flags_t flags = RSB_FLAG_NOFLAGS) const
1621  {
1627  // Note: ignoring typecode argument for now.
1628  RSBP_CWMFHO();
1629  if(!mtxBpp)
1630  RSBP_PERROR(RSB_ERR_BADARGS);
1631  RSBP_CFE(rsb_mtx_clone(mtxBpp, this->typecode_, transA, alphap, this->mtxAp_, flags));
1632  RSBP_MDR();
1633  }
1634 public:
1635 
1636  RsbMatrix & operator=(const RsbMatrix & A_Rsb)
1637  {
1642  RSBP_NWMFHO();
1643  errval_ = A_Rsb.clone<rsb_err_t>(&this->mtxAp_/*, rsb_type_t typecode*/);
1644  RSBP_MFRV(*this);
1645  }
1646 
1647  bool _is_complex(void) const
1648  {
1652  return !std::is_scalar<NT>();
1653  }
1654 
1655 private:
1656  bool _equal_to(const RsbMatrix & B_Rsb) const
1657  {
1661  // Note: space-inefficient.
1662  // An iterator or a submatrices-descent based method would be more space efficient.
1663  RSBP_CNMFHO();
1664  bool retval = false;
1665  const rsb_coo_idx_t invalid_coo_ = RSB_INVALID_COO_IDX_VAL;
1666  const rsb_nnz_idx_t nnzA = nnz();
1667 
1668  if( nnzA != B_Rsb.nnz() )
1669  goto ret;
1670  if( this->rows() != B_Rsb.rows() )
1671  goto ret;
1672  if( this->cols() != B_Rsb.cols() )
1673  goto ret;
1674 
1675  if( ! _is_integer() )
1676  {
1677  if( this->normOne() != B_Rsb.normOne() )
1678  goto ret;
1679  if( this->normInf() != B_Rsb.normInf() )
1680  goto ret;
1681  }
1682 
1683  {
1684  std::vector<rsb_coo_idx_t > AIA(nnzA,invalid_coo_),AJA(nnzA,invalid_coo_);
1685  std::vector<rsb_coo_idx_t > BIA(nnzA,invalid_coo_),BJA(nnzA,invalid_coo_);
1686  std::vector<NT > AVA(nnzA,invalid_coo_);
1687  std::vector<NT > BVA(nnzA,invalid_coo_);
1688  rsb_err_t errval;
1689 
1690  errval = rsb_mtx_get_coo(this->mtxAp_, &AVA[0], &AIA[0], &AJA[0], RSB_FLAG_SORTED_INPUT);
1691  RSBP_ERRGOTO(errval,ret)
1692  errval = rsb_mtx_get_coo(B_Rsb.mtxAp_, &BVA[0], &BIA[0], &BJA[0], RSB_FLAG_SORTED_INPUT);
1693  RSBP_ERRGOTO(errval,ret)
1694  retval = (
1695  std::equal(AIA.begin(),AIA.end(),BIA.begin()) &&
1696  std::equal(AJA.begin(),AJA.end(),BJA.begin()) &&
1697  std::equal(AVA.begin(),AVA.end(),BVA.begin()) );
1698  }
1699 ret:
1700  RSBP_MFRV(retval);
1701  } /* _equal_to */
1702 
1703 public:
1704  bool operator==(const RsbMatrix & B_Rsb) const
1705  {
1713  RSBP_CNMFHO();
1714  const bool retval = _equal_to(B_Rsb);
1715  RSBP_MFRV(retval);
1716  }
1717 
1718  bool operator!=(const RsbMatrix & B_Rsb) const
1719  {
1725  return ! ( (*this) == B_Rsb );
1726  }
1727 
1728  NT normOne(void) const
1729  {
1732  NT nrm = RSBP_NUMT_INVALID;
1733  this->get_nrm(&nrm, RSB_EXTF_NORM_ONE);
1734  return nrm;
1735  }
1736 
1737  NT normInf(void) const
1738  {
1741  NT nrm = RSBP_NUMT_INVALID;
1742  this->get_nrm(&nrm, RSB_EXTF_NORM_INF);
1743  return nrm;
1744  }
1745 
1746  RSBP_RVT Err_t rndr(const rsb_char_t * filename=RSBP_NULL, rsb_coo_idx_t pmWidth=512, rsb_coo_idx_t pmHeight=512, rsb_marf_t rflags=RSB_MARF_EPS) const
1747  {
1753  RSBP_CWMFHO();
1754  RSBP_CFE(rsb_mtx_rndr(filename, mtxAp_, pmWidth, pmHeight, rflags));
1755  RSBP_MDR();
1756  }
1757 
1758 }; /* class RsbMatrix */
1759 #ifndef RSBP_NO_NAMESPACE
1760 } // namespace rsb
1761 #endif /* RSBP_NO_NAMESPACE */
1762 
1763 #endif /* RSB_RSB_HPP_INCLUDED */
Err_t set_num_threads(rsb_int_t nt)
Definition: rsb.hpp:339
rsb_type_t get_type_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1166
Err_t spmv(rsb_trans_t transA, const NT *alphap, const NT *Xp, rsb_coo_idx_t incX, const NT *betap, NT *Yp, rsb_coo_idx_t incY) const
Definition: rsb.hpp:826
Err_t tune_spmm_threads(rsb_real_t *sfp=RSBP_NULL, rsb_int_t *tnp=RSBP_NULL, rsb_int_t maxr=0, rsb_time_t maxt=0, rsb_trans_t transA=RSB_TRANSPOSITION_N, const NT *alphap=RSBP_NULL, rsb_coo_idx_t nrhs=1, rsb_flags_t order=RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, const NT *Bp=RSBP_NULL, rsb_nnz_idx_t ldB=0, const NT *betap=RSBP_NULL, NT *Cp=RSBP_NULL, rsb_nnz_idx_t ldC=0) const
Definition: rsb.hpp:1462
bool operator!=(const RsbMatrix &B_Rsb) const
Definition: rsb.hpp:1718
#define RSBP_MSLVRV
Minimal supported librsb version (value of RSB_LIBRSB_VER, defined via rsb.h)
Definition: rsb.hpp:254
Err_t spsv(NT *y, const NT *x, bool do_trans=false) const
Definition: rsb.hpp:1085
RsbMatrix(const rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA, const NT *VA, rsb_nnz_idx_t nnzA, const rsb_flags_t flagsA=RSB_FLAG_NOFLAGS)
Definition: rsb.hpp:667
rsb_string_t get_info_str(const char *key) const
Definition: rsb.hpp:1418
rsb_coo_idx_t rows(void) const
Definition: rsb.hpp:1251
Err_t get_nrm(NT *Np, enum rsb_extff_t flags) const
Definition: rsb.hpp:1391
Class initializing/finalizing librsb state.
Definition: rsb.hpp:269
rsb_flags_t get_info_rsb_flags_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1122
rsb_coo_idx_t cols(void) const
Definition: rsb.hpp:1260
Err_t tune_spsm_threads(rsb_real_t *sfp=RSBP_NULL, rsb_int_t *tnp=RSBP_NULL, rsb_int_t maxr=0, rsb_time_t maxt=0, rsb_trans_t transA=RSB_TRANSPOSITION_N, const NT *alphap=RSBP_NULL, rsb_coo_idx_t nrhs=1, rsb_flags_t order=RSB_FLAG_WANT_COLUMN_MAJOR_ORDER, const NT *Bp=RSBP_NULL, rsb_nnz_idx_t ldB=0, const NT *betap=RSBP_NULL, NT *Cp=RSBP_NULL, rsb_nnz_idx_t ldC=0) const
Definition: rsb.hpp:1449
RsbMatrix(RsbMatrix &&other)
Definition: rsb.hpp:758
Err_t upd_vals(enum rsb_elopf_t elop_flags, const NT *omegap)
Definition: rsb.hpp:1379
rsb_int_t get_num_threads(void) const
Definition: rsb.hpp:349
rsb_type_t rsbtype(void) const
Definition: rsb.hpp:1401
#define RSBP_RVT
No return type.
Definition: rsb.hpp:251
NT get_val(const rsb_coo_idx_t i, const rsb_coo_idx_t j, rsb_flags_t flags=RSB_FLAG_NOFLAGS) const
Definition: rsb.hpp:1279
Err_t set_opt(enum rsb_opt_t iof, const void *iop)
Definition: rsb.hpp:307
~RsbMatrix(void)
Definition: rsb.hpp:774
Err_t rndr(const rsb_char_t *filename=RSBP_NULL, rsb_coo_idx_t pmWidth=512, rsb_coo_idx_t pmHeight=512, rsb_marf_t rflags=RSB_MARF_EPS) const
Definition: rsb.hpp:1746
RsbSym
Definition: rsb.hpp:549
size_t _get_storage_bytes(void) const
Definition: rsb.hpp:1196
Err_t get_csr(rsb_trans_t transA, NT *VA, rsb_coo_idx_t *RP, rsb_coo_idx_t *JA, rsb_flags_t flags) const
Definition: rsb.hpp:1342
RsbMatrix(rsb_coo_idx_t nrA, const rsb_coo_idx_t *RP, const rsb_coo_idx_t *JA, const NT *VA, const RsbSym sym=IsGen)
Definition: rsb.hpp:612
size_t meminfo(void)
Definition: rsb.hpp:396
Err_t set_opt_str(const rsb_char_t *opnp, const rsb_char_t *opvp)
Definition: rsb.hpp:297
Err_t _add(rsb_coo_idx_t i, rsb_coo_idx_t j, NT val)
Definition: rsb.hpp:787
Err_t spmv(rsb_trans_t transA, const NT alpha, const NT *Xp, rsb_coo_idx_t incX, const NT beta, NT *Yp, rsb_coo_idx_t incY) const
Definition: rsb.hpp:837
Err_t spsm(rsb_trans_t transT, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT beta, const NT *Bp, rsb_nnz_idx_t ldB, NT *Cp, rsb_nnz_idx_t ldC) const
Definition: rsb.hpp:1016
Err_t spsv(rsb_trans_t transT, const NT *alphap, const NT *Xp, rsb_coo_idx_t incX, NT *Yp, rsb_coo_idx_t incY) const
Definition: rsb.hpp:1063
RsbMatrix(rsb_coo_idx_t nrA, rsb_coo_idx_t ncA, const RsbSym sym=IsGen)
Definition: rsb.hpp:585
Err_t get_vec(NT *Dp, enum rsb_extff_t flags) const
Definition: rsb.hpp:1319
bool operator==(const RsbMatrix &B_Rsb) const
Definition: rsb.hpp:1704
size_t _get_index_storage_bytes(void) const
Definition: rsb.hpp:1188
Err_t spmv(rsb_trans_t transA, const NT alpha, const NT *Xp, const NT beta, NT *Yp) const
Definition: rsb.hpp:849
Err_t spsv(rsb_trans_t transT, const NT alpha, const NT *Xp, NT *Yp) const
Definition: rsb.hpp:1074
Err_t get_opt(enum rsb_opt_t iof, void *iop) const
Definition: rsb.hpp:317
Err_t spsm(NT *y, rsb_coo_idx_t nrhs, bool do_trans=false) const
Definition: rsb.hpp:1053
~RsbLib(void)
Definition: rsb.hpp:417
Err_t set_vals(const NT *VA, const rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA, rsb_nnz_idx_t nnz, rsb_flags_t flags)
Definition: rsb.hpp:1303
Err_t tune_spmm(rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, rsb_nnz_idx_t ldB, const NT beta, NT *Cp, rsb_nnz_idx_t ldC)
Definition: rsb.hpp:1501
Err_t get_info(enum rsb_mif_t miflags, void *minfop) const
Definition: rsb.hpp:1430
rsb_nnz_idx_t get_info_nnz_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1144
RsbMatrix(const rsb_char_t *filename, const RsbSym sym=IsGen)
Definition: rsb.hpp:696
size_t get_info_size_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1111
NT normOne(void) const
Definition: rsb.hpp:1728
Err_t get_rows_sparse(rsb_trans_t transA, const NT *alphap, NT *VA, rsb_coo_idx_t *IA, rsb_coo_idx_t *JA, rsb_coo_idx_t frA, rsb_coo_idx_t lrA, rsb_nnz_idx_t *rnzp, rsb_flags_t flags) const
Definition: rsb.hpp:1355
Err_t spsm(rsb_trans_t transT, const NT *alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *betap, const NT *Bp, rsb_nnz_idx_t ldB, NT *Cp, rsb_nnz_idx_t ldC) const
Definition: rsb.hpp:1005
Err_t close(void)
Definition: rsb.hpp:797
Err_t tune_spmm(rsb_real_t &sf, rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, const NT beta, NT *Cp)
Definition: rsb.hpp:1514
Err_t tune_spmm(rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT *alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, rsb_nnz_idx_t ldB, const NT *betap, NT *Cp, rsb_nnz_idx_t ldC)
Definition: rsb.hpp:1476
rsb_blk_idx_t get_info_blk_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1133
Err_t file_save(const rsb_char_t *filename=RSBP_NULL) const
Definition: rsb.hpp:1607
rsb_flags_t get_flags_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1155
Err_t spsm(NT *y, const NT *x, rsb_coo_idx_t nrhs, bool do_trans=false) const
Definition: rsb.hpp:1039
Err_t set_val(const NT val, const rsb_coo_idx_t i, const rsb_coo_idx_t j, rsb_flags_t flags=RSB_FLAG_NOFLAGS)
Definition: rsb.hpp:1289
Err_t get_vals(NT *VA, const rsb_coo_idx_t *IA, const rsb_coo_idx_t *JA, rsb_nnz_idx_t nnz, rsb_flags_t flags) const
Definition: rsb.hpp:1269
rsb_string_t get_opt(enum rsb_opt_t iof) const
Definition: rsb.hpp:327
rsb_nnz_idx_t nnz(void) const
Definition: rsb.hpp:1235
Err_t get_coo(rsb_trans_t transA, NT *VA, rsb_coo_idx_t *IA, rsb_coo_idx_t *JA, rsb_flags_t flags) const
Definition: rsb.hpp:1329
bool _is_complex(void) const
Definition: rsb.hpp:1647
NT normInf(void) const
Definition: rsb.hpp:1737
rsb_flags_t rsbflags(void) const
Definition: rsb.hpp:1410
RsbMatrix & operator=(const RsbMatrix &A_Rsb)
Definition: rsb.hpp:1636
Err_t spmm(rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, const NT beta, NT *Cp) const
Definition: rsb.hpp:935
RsbLib(void)
Definition: rsb.hpp:387
RsbLib(bool verbose)
Definition: rsb.hpp:371
Err_t spmv(NT *y, const NT *x, bool do_trans=false) const
Definition: rsb.hpp:896
Err_t spsv(NT *y, bool do_trans=false) const
Definition: rsb.hpp:1098
Err_t spmm(rsb_trans_t transA, const NT alpha, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, rsb_nnz_idx_t ldB, const NT beta, NT *Cp, rsb_nnz_idx_t ldC) const
Definition: rsb.hpp:923
Err_t upd_vals(enum rsb_elopf_t elop_flags, const NT &omega)
Definition: rsb.hpp:1367
Err_t spsm(rsb_trans_t transT, const NT alpha, rsb_coo_idx_t nrhs, const NT *Bp, NT *Cp) const
Definition: rsb.hpp:1026
RsbMatrix(const RsbMatrix &A_Rsb, bool do_trans=false, rsb_flags_t flagsA=RSB_FLAG_NOFLAGS)
Definition: rsb.hpp:715
rsb_string_t _info(void) const
Definition: rsb.hpp:1440
Err_t spmm(rsb_trans_t transA, const NT *alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, rsb_nnz_idx_t ldB, const NT *betap, NT *Cp, rsb_nnz_idx_t ldC) const
Definition: rsb.hpp:912
#define RSBP_DEPRECATED
Internal attribute specifier for deprecated member functions.
Definition: rsb.hpp:231
rsb_blk_idx_t blocks(void) const
Definition: rsb.hpp:1243
Err_t _close(void)
Definition: rsb.hpp:816
rsb_coo_idx_t get_info_coo_t(enum rsb_mif_t mif) const
Definition: rsb.hpp:1177
Err_t reinit(struct rsb_initopts *iop)
Definition: rsb.hpp:361
Represent a sparse matrix in RSB format by means of librsb.
Definition: rsb.hpp:519
Err_t tune_spsm(rsb_real_t *sfp, rsb_int_t *tnp, rsb_int_t maxr, rsb_time_t maxt, rsb_trans_t transA, const NT *alphap, rsb_coo_idx_t nrhs, rsb_flags_t order, const NT *Bp, rsb_nnz_idx_t ldB, const NT *betap, NT *Cp, rsb_nnz_idx_t ldC)
Definition: rsb.hpp:1584