25 #if ! defined (octave_Sparse_h) 26 #define octave_Sparse_h 1 28 #include "octave-config.h" 72 nzmx (0), nrows (0), ncols (0), count (1)
77 nzmx (0), nrows (n), ncols (n), count (1)
81 :
d (nz > 0 ? new T [nz] : nullptr),
90 nzmx (
a.nzmx), nrows (
a.nrows), ncols (
a.ncols), count (1)
93 std::copy_n (
a.d, nz,
d);
94 std::copy_n (
a.r, nz, r);
95 std::copy_n (
a.c, ncols + 1,
c);
120 void maybe_compress (
bool remove_zeros);
124 bool indices_ok (
void)
const;
126 bool any_element_is_nan (
void)
const;
141 SparseRep *r =
new SparseRep (*rep);
143 if (--rep->count == 0)
166 : rep (nil_rep ()), dimensions (
dim_vector (0,0))
172 : rep (new typename
Sparse<T>::SparseRep (n)),
176 : rep (new typename
Sparse<T>::SparseRep (nr, nc)),
182 : rep (new typename
Sparse<T>::SparseRep (
dv(0),
dv(1), nz)),
186 : rep (new typename
Sparse<T>::SparseRep (nr, nc, nz)),
194 template <
typename U>
196 : rep (new typename
Sparse<T>::SparseRep (
a.rep->nrows,
a.rep->ncols,
198 dimensions (
a.dimensions)
201 std::copy_n (
a.rep->d, nz, rep->
d);
202 std::copy_n (
a.rep->r, nz, rep->
r);
203 std::copy_n (
a.rep->c, rep->
ncols + 1, rep->
c);
208 : rep (
a.rep), dimensions (
a.dimensions)
236 OCTAVE_DEPRECATED (4.4,
"use 'nzmax' instead")
249 OCTAVE_DEPRECATED (4.4,
"use 'nzmax' instead")
252 OCTAVE_DEPRECATED (4.4,
"use 'numel' instead")
266 while (cidx (ret+1) <
k)
274 + static_cast<size_t> (nzmax ())
289 OCTAVE_NORETURN T range_error (
const char *
fcn,
291 OCTAVE_NORETURN T& range_error (
const char *
fcn,
294 OCTAVE_NORETURN T range_error (
const char *
fcn,
296 OCTAVE_NORETURN T& range_error (
const char *
fcn,
332 if (n < 0 || n >=
numel ())
334 return range_error (
"T& Sparse<T>::checkelem", n);
344 if (
i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
345 return range_error (
"T& Sparse<T>::checkelem",
i, j);
358 return range_error (
"T& Sparse<T>::checkelem",
ra_idx);
395 if (n < 0 || n >=
numel ())
396 return range_error (
"T Sparse<T>::checkelem", n);
403 if (
i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
404 return range_error (
"T Sparse<T>::checkelem",
i, j);
414 return range_error (
"T Sparse<T>::checkelem",
ra_idx);
453 return permute (vec,
true);
472 bool issquare (
void)
const {
return (dim1 () == dim2 ()); }
474 OCTAVE_DEPRECATED (4.4,
"use 'issquare' instead")
476 {
return issquare (); }
478 bool isempty (
void)
const {
return (rows () < 1 || cols () < 1); }
480 OCTAVE_DEPRECATED (4.4,
"use 'isempty' instead")
482 {
return isempty (); }
486 T *
data (
void) { make_unique ();
return rep->
d; }
493 T *
data (
void)
const {
return rep->
d; }
498 make_unique ();
return rep->
ridx (
i);
511 make_unique ();
return rep->
cidx (
i);
525 void delete_elements (
int dim,
const idx_vector&
i);
532 bool resize_ok =
false)
const;
538 void print_info (std::ostream&
os,
const std::string& prefix)
const;
567 template <
typename F,
bool zero>
570 return any_all_test<F, T, zero> (
fcn, data (), nnz ());
574 template <
typename F>
576 {
return test<F, false> (
fcn); }
578 template <
typename F>
580 {
return test<F, true> (
fcn); }
584 {
return test<bool (&) (T), false> (
fcn); }
587 {
return test<bool (&) (const T&), false> (
fcn); }
590 {
return test<bool (&) (T), true> (
fcn); }
593 {
return test<bool (&) (const T&), true> (
fcn); }
595 template <
typename U,
typename F>
600 U f_zero =
fcn (0.0);
617 result.maybe_compress (
true);
644 result.maybe_compress (
false);
651 template <
typename U>
654 {
return map<U, U (&) (T)> (
fcn); }
656 template <
typename U>
659 {
return map<U, U (&) (const T&)> (
fcn); }
667 template <
typename T>
670 T (*read_fcn) (std::istream&));
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
T & elem(octave_idx_type _r, octave_idx_type _c)
Sparse(const dim_vector &dv, octave_idx_type nz)
T elem(const Array< octave_idx_type > &ra_idx) const
T & checkelem(octave_idx_type i, octave_idx_type j)
void change_length(octave_idx_type nz)
const octave_base_value const Array< octave_idx_type > & ra_idx
T elem(octave_idx_type n) const
Sparse< U > map(U(&fcn)(T)) const
octave_idx_type * mex_get_ir(void) const
T checkelem(octave_idx_type n) 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
bool test_any(bool(&fcn)(T)) const
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz=0)
octave_idx_type safe_numel(void) const
The following function will throw a std::bad_alloc () exception if the requested size is larger than ...
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
octave_idx_type columns(void) const
octave_idx_type length(void) const
T xelem(octave_idx_type i, octave_idx_type j) const
octave_idx_type * ridx(void) const
octave_idx_type * cidx(void)
T & elem(octave_idx_type i, octave_idx_type j)
T & xelem(octave_idx_type n)
bool test_all(bool(&fcn)(const T &)) const
T & data(octave_idx_type i)
octave_idx_type cidx(octave_idx_type i) 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 cridx(octave_idx_type i) const
octave_idx_type & cidx(octave_idx_type i)
Sparse< T >::SparseRep * rep
bool test_any(F fcn) const
T checkelem(octave_idx_type i, octave_idx_type j) const
octave_idx_type & xcidx(octave_idx_type i)
T & data(octave_idx_type i)
octave::refcount< int > count
octave_idx_type * mex_get_jc(void) const
Sparse< U > map(F fcn) const
octave_idx_type * cidx(void) const
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
bool issquare(void) const
T data(octave_idx_type i) const
Sparse(octave_idx_type nr, octave_idx_type nc)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
T elem(octave_idx_type i, octave_idx_type j) const
octave_idx_type & ridx(octave_idx_type i)
SparseRep(const SparseRep &a)
T & elem(const Array< octave_idx_type > &ra_idx)
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
void maybe_compress(bool remove_zeros)
octave_idx_type nnz(void) const
Actual number of nonzero terms.
Compressed Column Sparse(rows=3, cols=4, nnz=2 [17%])(1
octave_idx_type numel(void) const
octave_idx_type & xridx(octave_idx_type i)
void change_capacity(octave_idx_type nz)
octave_idx_type ridx(octave_idx_type i) const
T & elem(octave_idx_type n)
Sparse(const Sparse< U > &a)
octave_idx_type nzmax(void) const
Amount of storage for nonzero elements.
Sparse< U > map(U(&fcn)(const T &)) const
T cdata(octave_idx_type i) const
octave_idx_type ndims(void) const
octave_idx_type * ridx(void)
octave_idx_type * xridx(void)
T & xelem(const Array< octave_idx_type > &ra_idx)
Sparse(const Sparse< T > &a)
octave_idx_type nnz(void) const
bool test_any(bool(&fcn)(const T &)) const
With real return the complex result
bool any_element_is_nan(void) const
T checkelem(const Array< octave_idx_type > &ra_idx) const
octave_idx_type cols(void) const
N Dimensional Array with copy-on-write semantics.
T celem(octave_idx_type _r, octave_idx_type _c) const
bool any_element_is_nan(void) const
octave_idx_type ccidx(octave_idx_type i) const
octave_idx_type dim1(void) const
octave_idx_type get_row_index(octave_idx_type k)
T xelem(octave_idx_type n) const
T::size_type numel(const T &str)
T & checkelem(const Array< octave_idx_type > &ra_idx)
T & xelem(octave_idx_type i, octave_idx_type j)
Sparse< T > squeeze(void) const
T xelem(const Array< octave_idx_type > &ra_idx) const
bool test_all(bool(&fcn)(T)) const
bool indices_ok(void) const
Sparse< T > ipermute(const Array< octave_idx_type > &vec) const
octave_idx_type get_col_index(octave_idx_type k)
Sparse< T > maybe_compress(bool remove_zeros=false)
dim_vector dims(void) const
Sparse(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
octave_idx_type ndims(void) const
Number of dimensions.
T & xdata(octave_idx_type i)
size_t byte_size(void) const
octave_idx_type * xcidx(void)
void * mex_get_data(void) const
T & checkelem(octave_idx_type n)
Sparse(octave_idx_type n)
write the output to stdout if nargout is
bool indices_ok(void) const
Vector representing the dimensions (size) of an Array.
bool test_all(F fcn) 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
octave_idx_type dim2(void) const
octave_idx_type rows(void) const
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)
SparseRep(octave_idx_type n)
octave_idx_type & cidx(octave_idx_type i)