26 #if ! defined (octave_Sparse_h)
27 #define octave_Sparse_h 1
29 #include "octave-config.h"
91 : d (nz > 0 ? new T [nz] : 0),
103 nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1)
106 std::copy (a.
d, a.
d + nz, d);
107 std::copy (a.
r, a.
r + nz, r);
108 std::copy (a.
c, a.
c + ncols + 1, c);
133 void maybe_compress (
bool remove_zeros);
137 bool indices_ok (
void)
const;
139 bool any_element_is_nan (
void)
const;
154 SparseRep *r =
new SparseRep (*rep);
156 if (--rep->count == 0)
179 : rep (nil_rep ()), dimensions (
dim_vector(0,0))
185 : rep (new typename
Sparse<T>::SparseRep (n)),
189 : rep (new typename
Sparse<T>::SparseRep (nr, nc)),
195 : rep (new typename
Sparse<T>::SparseRep (dv(0), dv(1), nz)),
199 : rep (new typename
Sparse<T>::SparseRep (nr, nc, nz)),
207 template <
typename U>
209 : rep (new typename
Sparse<T>::SparseRep (a.rep->nrows, a.rep->ncols,
211 dimensions (a.dimensions)
214 std::copy (a.
rep->d, a.
rep->d + nz, rep->
d);
215 std::copy (a.
rep->r, a.
rep->r + nz, rep->
r);
216 std::copy (a.
rep->c, a.
rep->c + rep->
ncols + 1, rep->
c);
221 : rep (a.rep), dimensions (a.dimensions)
249 OCTAVE_DEPRECATED (
"use 'nzmax' instead")
262 OCTAVE_DEPRECATED (
"use 'nzmax' instead")
265 OCTAVE_DEPRECATED (
"use 'numel' instead")
279 while (cidx (ret+1) < k)
287 + static_cast<size_t> (nzmax ())
300 OCTAVE_NORETURN T range_error (
const char *
fcn,
302 OCTAVE_NORETURN T& range_error (
const char *
fcn,
305 OCTAVE_NORETURN T range_error (
const char *
fcn,
307 OCTAVE_NORETURN T& range_error (
const char *
fcn,
329 return rep->
celem (i, j);
344 if (n < 0 || n >=
numel ())
345 return range_error (
"T& Sparse<T>::checkelem", n);
355 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
356 return range_error (
"T& Sparse<T>::checkelem", i, j);
369 return range_error (
"T& Sparse<T>::checkelem", ra_idx);
389 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
392 return checkelem (n);
397 return checkelem (i, j);
402 return checkelem (ra_idx);
418 return elem (ra_idx);
425 if (n < 0 || n >=
numel ())
426 return range_error (
"T Sparse<T>::checkelem", n);
433 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
434 return range_error (
"T Sparse<T>::checkelem", i, j);
444 return range_error (
"T Sparse<T>::checkelem", ra_idx);
456 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
460 return checkelem (i, j);
465 return checkelem (ra_idx);
477 return elem (ra_idx);
496 return permute (vec,
true);
515 bool is_square (
void)
const {
return (dim1 () == dim2 ()); }
517 bool is_empty (
void)
const {
return (rows () < 1 && cols () < 1); }
521 T*
data (
void) { make_unique ();
return rep->
d; }
528 T*
data (
void)
const {
return rep->
d; }
533 make_unique ();
return rep->
ridx (i);
546 make_unique ();
return rep->
cidx (i);
560 void delete_elements (
int dim,
const idx_vector&
i);
567 bool resize_ok =
false)
const;
573 void print_info (std::ostream& os,
const std::string& prefix)
const;
602 template <
typename F,
bool zero>
605 return any_all_test<F, T, zero> (
fcn, data (), nnz ());
609 template <
typename F>
611 {
return test<F, false> (
fcn); }
613 template <
typename F>
615 {
return test<F, true> (
fcn); }
619 {
return test<bool (&) (T), false> (
fcn); }
622 {
return test<bool (&) (const T&), false> (
fcn); }
625 {
return test<bool (&) (T), true> (
fcn); }
628 {
return test<bool (&) (const T&), true> (
fcn); }
630 template <
typename U,
typename F>
649 result.
data (ridx (
i) + j * nr) =
fcn (data (
i));
662 result.
cidx (ii) = 0;
672 result.
ridx (ii++) = ridx (
i);
676 result.
cidx (j+1) = ii;
686 template <
typename U>
689 {
return map<U, U (&) (T)> (
fcn); }
691 template <
typename U>
694 {
return map<U, U (&) (const T&)> (
fcn); }
702 template <
typename T>
705 T (*read_fcn) (std::istream&));
octave_idx_type & xcidx(octave_idx_type i)
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
T & elem(octave_idx_type _r, octave_idx_type _c)
octave_idx_type * xridx(void)
Sparse< T > ipermute(const Array< octave_idx_type > &vec) const
T & elem(octave_idx_type i, octave_idx_type j)
octave_idx_type cols(void) const
T & xelem(const Array< octave_idx_type > &ra_idx)
T cdata(octave_idx_type i) const
T xelem(octave_idx_type i, octave_idx_type j) const
octave_idx_type rows(void) const
void change_length(octave_idx_type nz)
octave_idx_type * cidx(void) const
octave_idx_type numel(void) const
const octave_base_value const Array< octave_idx_type > & ra_idx
T & elem(octave_idx_type n)
octave_idx_type cridx(octave_idx_type i) const
dim_vector dims(void) const
std::istream & read_sparse_matrix(std::istream &is, Sparse< T > &a, T(*read_fcn)(std::istream &))
octave_idx_type & ridx(octave_idx_type i)
identity matrix If supplied two scalar respectively For allows like xample val
T & xelem(octave_idx_type n)
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz=0)
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
T checkelem(octave_idx_type i, octave_idx_type j) const
T & data(octave_idx_type i)
bool test_all(F fcn) const
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
octave_idx_type * xcidx(void)
octave_idx_type ridx(octave_idx_type i) const
bool test_all(bool(&fcn)(T)) const
octave_idx_type & xridx(octave_idx_type i)
octave_idx_type & cidx(octave_idx_type i)
octave_idx_type & ridx(octave_idx_type i)
octave_idx_type ccidx(octave_idx_type i) const
bool any_element_is_nan(void) const
octave_idx_type dim1(void) const
octave_idx_type * cidx(void)
T elem(octave_idx_type i, octave_idx_type j) const
octave_idx_type columns(void) const
T xelem(octave_idx_type n) const
T & checkelem(const Array< octave_idx_type > &ra_idx)
bool indices_ok(void) const
octave_idx_type get_row_index(octave_idx_type k)
bool indices_ok(void) const
T & elem(const Array< octave_idx_type > &ra_idx)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
SparseRep(const SparseRep &a)
T & data(octave_idx_type i)
octave_idx_type nnz(void) const
Actual number of nonzero terms.
Sparse< T > squeeze(void) const
bool test_any(bool(&fcn)(const T &)) const
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
octave_idx_type nzmax(void) const
Amount of storage for nonzero elements.
void maybe_compress(bool remove_zeros)
octave_idx_type get_col_index(octave_idx_type k)
Sparse< T >::SparseRep * rep
T celem(octave_idx_type _r, octave_idx_type _c) const
T xelem(const Array< octave_idx_type > &ra_idx) const
octave_idx_type safe_numel(void) const
T data(octave_idx_type i) const
void change_capacity(octave_idx_type nz)
T checkelem(const Array< octave_idx_type > &ra_idx) const
octave_idx_type ndims(void) const
octave_idx_type * mex_get_ir(void) const
Sparse< T > maybe_compress(bool remove_zeros=false)
bool test_all(bool(&fcn)(const T &)) const
octave_idx_type * mex_get_jc(void) const
Sparse< U > map(U(&fcn)(T)) const
size_t byte_size(void) const
Sparse< U > map(F fcn) const
octave_idx_type cidx(octave_idx_type i) const
Sparse(const Sparse< T > &a)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
T & xelem(octave_idx_type i, octave_idx_type j)
With real return the complex result
N Dimensional Array with copy-on-write semantics.
octave_idx_type nnz(void) const
bool test_any(bool(&fcn)(T)) const
T::size_type numel(const T &str)
octave_idx_type * ridx(void)
bool is_empty(void) const
Sparse(octave_idx_type nr, octave_idx_type nc)
Compressed Column Sparse(rows=3, cols=4, nnz=2[17%])(1
=val(i)}if ode{val(i)}occurs in table i
T & checkelem(octave_idx_type i, octave_idx_type j)
bool test_any(F fcn) const
octave_idx_type & cidx(octave_idx_type i)
Sparse< U > map(U(&fcn)(const T &)) const
T & checkelem(octave_idx_type n)
octave_idx_type ndims(void) const
Number of dimensions.
T elem(const Array< octave_idx_type > &ra_idx) const
octave_idx_type * ridx(void) const
T & xdata(octave_idx_type i)
Sparse(octave_idx_type n)
Sparse(const Sparse< U > &a)
void * mex_get_data(void) const
octave_refcount< int > count
Sparse(const dim_vector &dv, octave_idx_type nz)
octave_idx_type dim2(void) const
T checkelem(octave_idx_type n) const
write the output to stdout if nargout is
octave_idx_type length(void) const
Vector representing the dimensions (size) of an Array.
bool is_square(void) const
T elem(octave_idx_type n) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Sparse(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)
SparseRep(octave_idx_type n)
bool any_element_is_nan(void) const