GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Sparse.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2018 David Bateman
4 Copyright (C) 1998-2004 Andy Adler
5 Copyright (C) 2010 VZLU Prague
6 
7 This file is part of Octave.
8 
9 Octave is free software: you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Octave is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Octave; see the file COPYING. If not, see
21 <https://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if ! defined (octave_Sparse_h)
26 #define octave_Sparse_h 1
27 
28 #include "octave-config.h"
29 
30 #include <cassert>
31 #include <cstddef>
32 
33 #include <algorithm>
34 #include <iosfwd>
35 #include <string>
36 
37 #include "Array.h"
38 
39 class idx_vector;
40 class PermMatrix;
41 
42 // Two dimensional sparse class. Handles the reference counting for
43 // all the derived classes.
44 
45 template <typename T>
46 class
47 Sparse
48 {
49 public:
50 
51  typedef T element_type;
52 
53 protected:
54  //--------------------------------------------------------------------
55  // The real representation of all Sparse arrays.
56  //--------------------------------------------------------------------
57 
58  class OCTAVE_API SparseRep
59  {
60  public:
61 
62  T *d;
69 
70  SparseRep (void)
71  : d (nullptr), r (nullptr), c (new octave_idx_type [1] {}),
72  nzmx (0), nrows (0), ncols (0), count (1)
73  { }
74 
76  : d (nullptr), r (nullptr), c (new octave_idx_type [n+1] {}),
77  nzmx (0), nrows (n), ncols (n), count (1)
78  { }
79 
81  : d (nz > 0 ? new T [nz] : nullptr),
82  r (nz > 0 ? new octave_idx_type [nz] {} : nullptr),
83  c (new octave_idx_type [nc+1] {}), nzmx (nz), nrows (nr),
84  ncols (nc), count (1)
85  { }
86 
88  : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]),
89  c (new octave_idx_type [a.ncols + 1]),
90  nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1)
91  {
92  octave_idx_type nz = a.nnz ();
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);
96  }
97 
98  ~SparseRep (void) { delete [] d; delete [] r; delete [] c; }
99 
100  octave_idx_type length (void) const { return nzmx; }
101 
102  octave_idx_type nnz (void) const { return c[ncols]; }
103 
105 
106  T celem (octave_idx_type _r, octave_idx_type _c) const;
107 
108  T& data (octave_idx_type i) { return d[i]; }
109 
110  T cdata (octave_idx_type i) const { return d[i]; }
111 
113 
114  octave_idx_type cridx (octave_idx_type i) const { return r[i]; }
115 
117 
118  octave_idx_type ccidx (octave_idx_type i) const { return c[i]; }
119 
120  void maybe_compress (bool remove_zeros);
121 
122  void change_length (octave_idx_type nz);
123 
124  bool indices_ok (void) const;
125 
126  bool any_element_is_nan (void) const;
127 
128  private:
129 
130  // No assignment!
131 
132  SparseRep& operator = (const SparseRep& a);
133  };
134 
135  //--------------------------------------------------------------------
136 
137  void make_unique (void)
138  {
139  if (rep->count > 1)
140  {
141  SparseRep *r = new SparseRep (*rep);
142 
143  if (--rep->count == 0)
144  delete rep;
145 
146  rep = r;
147  }
148  }
149 
150 public:
151 
152  // !!! WARNING !!! -- these should be protected, not public. You
153  // should not access these data members directly!
154 
156 
158 
159 private:
160 
161  static typename Sparse<T>::SparseRep *nil_rep (void);
162 
163 public:
164 
165  Sparse (void)
166  : rep (nil_rep ()), dimensions (dim_vector (0,0))
167  {
168  rep->count++;
169  }
170 
171  explicit Sparse (octave_idx_type n)
172  : rep (new typename Sparse<T>::SparseRep (n)),
173  dimensions (dim_vector (n, n)) { }
174 
176  : rep (new typename Sparse<T>::SparseRep (nr, nc)),
177  dimensions (dim_vector (nr, nc)) { }
178 
179  explicit Sparse (octave_idx_type nr, octave_idx_type nc, T val);
180 
182  : rep (new typename Sparse<T>::SparseRep (dv(0), dv(1), nz)),
183  dimensions (dv) { }
184 
186  : rep (new typename Sparse<T>::SparseRep (nr, nc, nz)),
187  dimensions (dim_vector (nr, nc)) { }
188 
189  // Both SparseMatrix and SparseBoolMatrix need this ctor, and this
190  // is their only common ancestor.
191  explicit Sparse (const PermMatrix& a);
192 
193  // Type conversion case. Preserves nzmax.
194  template <typename U>
195  Sparse (const Sparse<U>& a)
196  : rep (new typename Sparse<T>::SparseRep (a.rep->nrows, a.rep->ncols,
197  a.rep->nzmx)),
198  dimensions (a.dimensions)
199  {
200  octave_idx_type nz = a.nnz ();
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);
204  }
205 
206  // No type conversion case.
207  Sparse (const Sparse<T>& a)
208  : rep (a.rep), dimensions (a.dimensions)
209  {
210  rep->count++;
211  }
212 
213 public:
214 
215  Sparse (const dim_vector& dv);
216 
217  Sparse (const Sparse<T>& a, const dim_vector& dv);
218 
219  Sparse (const Array<T>& a, const idx_vector& r, const idx_vector& c,
220  octave_idx_type nr = -1, octave_idx_type nc = -1,
221  bool sum_terms = true, octave_idx_type nzm = -1);
222 
223  // Sparsify a normal matrix
224  Sparse (const Array<T>& a);
225 
226  virtual ~Sparse (void);
227 
228  Sparse<T>& operator = (const Sparse<T>& a);
229 
230  //! Amount of storage for nonzero elements.
231  //! This may differ from the actual number of elements, see nnz().
232  octave_idx_type nzmax (void) const { return rep->length (); }
233 
234  //! Amount of storage for nonzero elements.
235  //! Synonymous with nzmax().
236  OCTAVE_DEPRECATED (4.4, "use 'nzmax' instead")
237  octave_idx_type capacity (void) const { return nzmax (); }
238 
239  //! Actual number of nonzero terms.
240  octave_idx_type nnz (void) const { return rep->nnz (); }
241 
242  // Querying the number of elements (incl. zeros) may overflow the index type,
243  // so don't do it unless you really need it.
244  octave_idx_type numel (void) const
245  {
246  return dimensions.safe_numel ();
247  }
248 
249  OCTAVE_DEPRECATED (4.4, "use 'nzmax' instead")
250  octave_idx_type nelem (void) const { return nzmax (); }
251 
252  OCTAVE_DEPRECATED (4.4, "use 'numel' instead")
253  octave_idx_type length (void) const { return numel (); }
254 
255  octave_idx_type dim1 (void) const { return dimensions(0); }
256  octave_idx_type dim2 (void) const { return dimensions(1); }
257 
258  octave_idx_type rows (void) const { return dim1 (); }
259  octave_idx_type cols (void) const { return dim2 (); }
260  octave_idx_type columns (void) const { return dim2 (); }
261 
264  {
265  octave_idx_type ret = 0;
266  while (cidx (ret+1) < k)
267  ret++;
268  return ret;
269  }
270 
271  size_t byte_size (void) const
272  {
273  return (static_cast<size_t> (cols () + 1) * sizeof (octave_idx_type)
274  + static_cast<size_t> (nzmax ())
275  * (sizeof (T) + sizeof (octave_idx_type)));
276  }
277 
278  dim_vector dims (void) const { return dimensions; }
279 
280  Sparse<T> squeeze (void) const { return *this; }
281 
283 
284  // FIXME: Functions are marked as NORETURN, but they are used with
285  // a return statement in following code. Shouldn't that be fixed?
286  OCTAVE_NORETURN T range_error (const char *fcn, octave_idx_type n) const;
287  OCTAVE_NORETURN T& range_error (const char *fcn, octave_idx_type n);
288 
289  OCTAVE_NORETURN T range_error (const char *fcn,
291  OCTAVE_NORETURN T& range_error (const char *fcn,
293 
294  OCTAVE_NORETURN T range_error (const char *fcn,
295  const Array<octave_idx_type>& ra_idx) const;
296  OCTAVE_NORETURN T& range_error (const char *fcn,
298 
299  // No checking, even for multiple references, ever.
300 
302  {
303  octave_idx_type i = n % rows ();
304  octave_idx_type j = n / rows ();
305  return xelem (i, j);
306  }
307 
308  T xelem (octave_idx_type n) const
309  {
310  octave_idx_type i = n % rows ();
311  octave_idx_type j = n / rows ();
312  return xelem (i, j);
313  }
314 
315  T& xelem (octave_idx_type i, octave_idx_type j) { return rep->elem (i, j); }
317  {
318  return rep->celem (i, j);
319  }
320 
322  { return xelem (compute_index (ra_idx)); }
323 
325  { return xelem (compute_index (ra_idx)); }
326 
327  // FIXME: would be nice to fix this so that we don't unnecessarily force a
328  // copy, but that is not so easy, and I see no clean way to do it.
329 
331  {
332  if (n < 0 || n >= numel ())
333  // FIXME: Why should we "return" when range_error is OCTAVE_NORETURN?
334  return range_error ("T& Sparse<T>::checkelem", n);
335  else
336  {
337  make_unique ();
338  return xelem (n);
339  }
340  }
341 
343  {
344  if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
345  return range_error ("T& Sparse<T>::checkelem", i, j);
346  else
347  {
348  make_unique ();
349  return xelem (i, j);
350  }
351  }
352 
354  {
356 
357  if (i < 0)
358  return range_error ("T& Sparse<T>::checkelem", ra_idx);
359  else
360  return elem (i);
361  }
362 
364  {
365  make_unique ();
366  return xelem (n);
367  }
368 
370  {
371  make_unique ();
372  return xelem (i, j);
373  }
374 
376  { return Sparse<T>::elem (compute_index (ra_idx)); }
377 
378  T& operator () (octave_idx_type n)
379  {
380  return elem (n);
381  }
382 
383  T& operator () (octave_idx_type i, octave_idx_type j)
384  {
385  return elem (i, j);
386  }
387 
388  T& operator () (const Array<octave_idx_type>& ra_idx)
389  {
390  return elem (ra_idx);
391  }
392 
394  {
395  if (n < 0 || n >= numel ())
396  return range_error ("T Sparse<T>::checkelem", n);
397  else
398  return xelem (n);
399  }
400 
402  {
403  if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
404  return range_error ("T Sparse<T>::checkelem", i, j);
405  else
406  return xelem (i, j);
407  }
408 
410  {
412 
413  if (i < 0)
414  return range_error ("T Sparse<T>::checkelem", ra_idx);
415  else
416  return Sparse<T>::elem (i);
417  }
418 
419  T elem (octave_idx_type n) const { return xelem (n); }
420 
421  T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
422 
424  { return Sparse<T>::elem (compute_index (ra_idx)); }
425 
426  T operator () (octave_idx_type n) const { return elem (n); }
427 
428  T operator () (octave_idx_type i, octave_idx_type j) const
429  {
430  return elem (i, j);
431  }
432 
433  T operator () (const Array<octave_idx_type>& ra_idx) const
434  {
435  return elem (ra_idx);
436  }
437 
438  Sparse<T> maybe_compress (bool remove_zeros = false)
439  {
440  if (remove_zeros)
441  make_unique (); // Need to unshare because elements are removed.
442 
443  rep->maybe_compress (remove_zeros);
444  return (*this);
445  }
446 
447  Sparse<T> reshape (const dim_vector& new_dims) const;
448 
449  Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
450 
452  {
453  return permute (vec, true);
454  }
455 
456  void resize1 (octave_idx_type n);
457 
458  void resize (octave_idx_type r, octave_idx_type c);
459 
460  void resize (const dim_vector& dv);
461 
463  {
464  if (nz < nnz ())
465  make_unique (); // Unshare now because elements will be truncated.
466  rep->change_length (nz);
467  }
468 
469  Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c);
470  Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx);
471 
472  bool issquare (void) const { return (dim1 () == dim2 ()); }
473 
474  OCTAVE_DEPRECATED (4.4, "use 'issquare' instead")
475  bool is_square (void) const
476  { return issquare (); }
477 
478  bool isempty (void) const { return (rows () < 1 || cols () < 1); }
479 
480  OCTAVE_DEPRECATED (4.4, "use 'isempty' instead")
481  bool is_empty (void) const
482  { return isempty (); }
483 
484  Sparse<T> transpose (void) const;
485 
486  T * data (void) { make_unique (); return rep->d; }
487  T& data (octave_idx_type i) { make_unique (); return rep->data (i); }
488  T * xdata (void) { return rep->d; }
489  T& xdata (octave_idx_type i) { return rep->data (i); }
490 
491  T data (octave_idx_type i) const { return rep->data (i); }
492  // FIXME: shouldn't this be returning const T*?
493  T * data (void) const { return rep->d; }
494 
495  octave_idx_type * ridx (void) { make_unique (); return rep->r; }
497  {
498  make_unique (); return rep->ridx (i);
499  }
500 
501  octave_idx_type * xridx (void) { return rep->r; }
502  octave_idx_type& xridx (octave_idx_type i) { return rep->ridx (i); }
503 
504  octave_idx_type ridx (octave_idx_type i) const { return rep->cridx (i); }
505  // FIXME: shouldn't this be returning const octave_idx_type*?
506  octave_idx_type * ridx (void) const { return rep->r; }
507 
508  octave_idx_type * cidx (void) { make_unique (); return rep->c; }
510  {
511  make_unique (); return rep->cidx (i);
512  }
513 
514  octave_idx_type * xcidx (void) { return rep->c; }
515  octave_idx_type& xcidx (octave_idx_type i) { return rep->cidx (i); }
516 
517  octave_idx_type cidx (octave_idx_type i) const { return rep->ccidx (i); }
518  // FIXME: shouldn't this be returning const octave_idx_type*?
519  octave_idx_type * cidx (void) const { return rep->c; }
520 
521  octave_idx_type ndims (void) const { return dimensions.ndims (); }
522 
523  void delete_elements (const idx_vector& i);
524 
525  void delete_elements (int dim, const idx_vector& i);
526 
527  void delete_elements (const idx_vector& i, const idx_vector& j);
528 
529  Sparse<T> index (const idx_vector& i, bool resize_ok = false) const;
530 
531  Sparse<T> index (const idx_vector& i, const idx_vector& j,
532  bool resize_ok = false) const;
533 
534  void assign (const idx_vector& i, const Sparse<T>& rhs);
535 
536  void assign (const idx_vector& i, const idx_vector& j, const Sparse<T>& rhs);
537 
538  void print_info (std::ostream& os, const std::string& prefix) const;
539 
540  // Unsafe. These functions exist to support the MEX interface.
541  // You should not use them anywhere else.
542  void * mex_get_data (void) const { return const_cast<T *> (data ()); }
543 
545  {
546  return const_cast<octave_idx_type *> (ridx ());
547  }
548 
550  {
551  return const_cast<octave_idx_type *> (cidx ());
552  }
553 
554  Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
555  Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
556  sortmode mode = ASCENDING) const;
557 
558  Sparse<T> diag (octave_idx_type k = 0) const;
559 
560  // dim = -1 and dim = -2 are special; see Array<T>::cat description.
561  static Sparse<T>
562  cat (int dim, octave_idx_type n, const Sparse<T> *sparse_list);
563 
564  Array<T> array_value (void) const;
565 
566  // Generic any/all test functionality with arbitrary predicate.
567  template <typename F, bool zero>
568  bool test (F fcn) const
569  {
570  return any_all_test<F, T, zero> (fcn, data (), nnz ());
571  }
572 
573  // Simpler calls.
574  template <typename F>
575  bool test_any (F fcn) const
576  { return test<F, false> (fcn); }
577 
578  template <typename F>
579  bool test_all (F fcn) const
580  { return test<F, true> (fcn); }
581 
582  // Overloads for function references.
583  bool test_any (bool (&fcn) (T)) const
584  { return test<bool (&) (T), false> (fcn); }
585 
586  bool test_any (bool (&fcn) (const T&)) const
587  { return test<bool (&) (const T&), false> (fcn); }
588 
589  bool test_all (bool (&fcn) (T)) const
590  { return test<bool (&) (T), true> (fcn); }
591 
592  bool test_all (bool (&fcn) (const T&)) const
593  { return test<bool (&) (const T&), true> (fcn); }
594 
595  template <typename U, typename F>
596  Sparse<U>
597  map (F fcn) const
598  {
600  U f_zero = fcn (0.0);
601 
602  if (f_zero != 0.0)
603  {
604  octave_idx_type nr = rows ();
605  octave_idx_type nc = cols ();
606 
607  result = Sparse<U> (nr, nc, f_zero);
608 
609  for (octave_idx_type j = 0; j < nc; j++)
610  for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
611  {
612  octave_quit ();
613  /* Use data instead of elem for better performance. */
614  result.data (ridx (i) + j * nr) = fcn (data (i));
615  }
616 
617  result.maybe_compress (true);
618  }
619  else
620  {
621  octave_idx_type nz = nnz ();
622  octave_idx_type nr = rows ();
623  octave_idx_type nc = cols ();
624 
625  result = Sparse<U> (nr, nc, nz);
626  octave_idx_type ii = 0;
627  result.cidx (ii) = 0;
628 
629  for (octave_idx_type j = 0; j < nc; j++)
630  {
631  for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
632  {
633  U val = fcn (data (i));
634  if (val != 0.0)
635  {
636  result.data (ii) = val;
637  result.ridx (ii++) = ridx (i);
638  }
639  octave_quit ();
640  }
641  result.cidx (j+1) = ii;
642  }
643 
644  result.maybe_compress (false);
645  }
646 
647  return result;
648  }
649 
650  // Overloads for function references.
651  template <typename U>
652  Sparse<U>
653  map (U (&fcn) (T)) const
654  { return map<U, U (&) (T)> (fcn); }
655 
656  template <typename U>
657  Sparse<U>
658  map (U (&fcn) (const T&)) const
659  { return map<U, U (&) (const T&)> (fcn); }
660 
661  bool indices_ok (void) const { return rep->indices_ok (); }
662 
663  bool any_element_is_nan (void) const
664  { return rep->any_element_is_nan (); }
665 };
666 
667 template <typename T>
668 std::istream&
669 read_sparse_matrix (std::istream& is, Sparse<T>& a,
670  T (*read_fcn) (std::istream&));
671 
672 #endif
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:175
T & elem(octave_idx_type _r, octave_idx_type _c)
Definition: Sparse.cc:64
Sparse(const dim_vector &dv, octave_idx_type nz)
Definition: Sparse.h:181
T elem(const Array< octave_idx_type > &ra_idx) const
Definition: Sparse.h:423
void make_unique(void)
Definition: Sparse.h:137
~SparseRep(void)
Definition: Sparse.h:98
T * data(void)
Definition: Sparse.h:486
T & checkelem(octave_idx_type i, octave_idx_type j)
Definition: Sparse.h:342
void change_length(octave_idx_type nz)
Definition: Sparse.cc:140
const octave_base_value const Array< octave_idx_type > & ra_idx
dim_vector dimensions
Definition: Sparse.h:157
T elem(octave_idx_type n) const
Definition: Sparse.h:419
Sparse< U > map(U(&fcn)(T)) const
Definition: Sparse.h:653
octave_idx_type * mex_get_ir(void) const
Definition: Sparse.h:544
T checkelem(octave_idx_type n) const
Definition: Sparse.h:393
std::istream & read_sparse_matrix(std::istream &is, Sparse< T > &a, T(*read_fcn)(std::istream &))
Definition: Sparse.cc:2699
sortmode
Definition: oct-sort.h:105
octave_idx_type & ridx(octave_idx_type i)
Definition: Sparse.h:112
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
bool test_any(bool(&fcn)(T)) const
Definition: Sparse.h:583
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz=0)
Definition: Sparse.h:80
octave_idx_type safe_numel(void) const
The following function will throw a std::bad_alloc () exception if the requested size is larger than ...
Definition: dim-vector.cc:103
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
Definition: data.cc:6348
octave_idx_type columns(void) const
Definition: Sparse.h:260
octave_idx_type length(void) const
Definition: Sparse.h:100
T xelem(octave_idx_type i, octave_idx_type j) const
Definition: Sparse.h:316
octave_idx_type * ridx(void) const
Definition: Sparse.h:506
octave_idx_type nzmx
Definition: Sparse.h:65
octave_idx_type * cidx(void)
Definition: Sparse.h:508
T & elem(octave_idx_type i, octave_idx_type j)
Definition: Sparse.h:369
for large enough k
Definition: lu.cc:617
T & xelem(octave_idx_type n)
Definition: Sparse.h:301
bool test_all(bool(&fcn)(const T &)) const
Definition: Sparse.h:592
T & data(octave_idx_type i)
Definition: Sparse.h:108
octave_idx_type cidx(octave_idx_type i) const
Definition: Sparse.h:517
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)
Definition: symrcm.cc:386
Sparse(void)
Definition: Sparse.h:165
cat(2, A, B) esult
Definition: data.cc:2278
octave_idx_type cridx(octave_idx_type i) const
Definition: Sparse.h:114
octave_idx_type & cidx(octave_idx_type i)
Definition: Sparse.h:116
Sparse< T >::SparseRep * rep
Definition: Sparse.h:155
bool test_any(F fcn) const
Definition: Sparse.h:575
T checkelem(octave_idx_type i, octave_idx_type j) const
Definition: Sparse.h:401
octave_idx_type nrows
Definition: Sparse.h:66
octave_idx_type * r
Definition: Sparse.h:63
octave_idx_type & xcidx(octave_idx_type i)
Definition: Sparse.h:515
T & data(octave_idx_type i)
Definition: Sparse.h:487
octave::refcount< int > count
Definition: Sparse.h:68
octave_idx_type * mex_get_jc(void) const
Definition: Sparse.h:549
Sparse< U > map(F fcn) const
Definition: Sparse.h:597
octave_idx_type * cidx(void) const
Definition: Sparse.h:519
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
Definition: file-io.cc:587
octave_idx_type * c
Definition: Sparse.h:64
bool issquare(void) const
Definition: Sparse.h:472
T data(octave_idx_type i) const
Definition: Sparse.h:491
Sparse(octave_idx_type nr, octave_idx_type nc)
Definition: Sparse.h:175
octave_function * fcn
Definition: ov-class.cc:1754
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
Definition: Sparse.h:421
octave_idx_type & ridx(octave_idx_type i)
Definition: Sparse.h:496
SparseRep(const SparseRep &a)
Definition: Sparse.h:87
T & elem(const Array< octave_idx_type > &ra_idx)
Definition: Sparse.h:375
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
Definition: cellfun.cc:400
void maybe_compress(bool remove_zeros)
Definition: Sparse.cc:116
octave_idx_type nnz(void) const
Actual number of nonzero terms.
Definition: Sparse.h:240
Compressed Column Sparse(rows=3, cols=4, nnz=2 [17%])(1
octave_idx_type numel(void) const
Definition: Sparse.h:244
octave_idx_type & xridx(octave_idx_type i)
Definition: Sparse.h:502
void change_capacity(octave_idx_type nz)
Definition: Sparse.h:462
octave_idx_type ridx(octave_idx_type i) const
Definition: Sparse.h:504
T & elem(octave_idx_type n)
Definition: Sparse.h:363
Sparse(const Sparse< U > &a)
Definition: Sparse.h:195
octave_idx_type nzmax(void) const
Amount of storage for nonzero elements.
Definition: Sparse.h:232
octave_idx_type ncols
Definition: Sparse.h:67
Sparse< U > map(U(&fcn)(const T &)) const
Definition: Sparse.h:658
static int elem
Definition: __contourc__.cc:47
T cdata(octave_idx_type i) const
Definition: Sparse.h:110
T element_type
Definition: Sparse.h:51
octave_idx_type ndims(void) const
Definition: Sparse.h:521
octave_idx_type * ridx(void)
Definition: Sparse.h:495
octave_idx_type * xridx(void)
Definition: Sparse.h:501
T & xelem(const Array< octave_idx_type > &ra_idx)
Definition: Sparse.h:321
Sparse(const Sparse< T > &a)
Definition: Sparse.h:207
octave_idx_type nnz(void) const
Definition: Sparse.h:102
bool test(F fcn) const
Definition: Sparse.h:568
bool test_any(bool(&fcn)(const T &)) const
Definition: Sparse.h:586
With real return the complex result
Definition: data.cc:3260
bool any_element_is_nan(void) const
Definition: Sparse.cc:177
T checkelem(const Array< octave_idx_type > &ra_idx) const
Definition: Sparse.h:409
octave_idx_type cols(void) const
Definition: Sparse.h:259
T * data(void) const
Definition: Sparse.h:493
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
T celem(octave_idx_type _r, octave_idx_type _c) const
Definition: Sparse.cc:105
bool any_element_is_nan(void) const
Definition: Sparse.h:663
octave_idx_type ccidx(octave_idx_type i) const
Definition: Sparse.h:118
octave_idx_type dim1(void) const
Definition: Sparse.h:255
octave_idx_type get_row_index(octave_idx_type k)
Definition: Sparse.h:262
T xelem(octave_idx_type n) const
Definition: Sparse.h:308
SparseRep(void)
Definition: Sparse.h:70
T::size_type numel(const T &str)
Definition: oct-string.cc:61
T & checkelem(const Array< octave_idx_type > &ra_idx)
Definition: Sparse.h:353
T & xelem(octave_idx_type i, octave_idx_type j)
Definition: Sparse.h:315
Sparse< T > squeeze(void) const
Definition: Sparse.h:280
T xelem(const Array< octave_idx_type > &ra_idx) const
Definition: Sparse.h:324
bool test_all(bool(&fcn)(T)) const
Definition: Sparse.h:589
bool indices_ok(void) const
Definition: Sparse.h:661
T * xdata(void)
Definition: Sparse.h:488
Sparse< T > ipermute(const Array< octave_idx_type > &vec) const
Definition: Sparse.h:451
octave_idx_type get_col_index(octave_idx_type k)
Definition: Sparse.h:263
Sparse< T > maybe_compress(bool remove_zeros=false)
Definition: Sparse.h:438
dim_vector dims(void) const
Definition: Sparse.h:278
for i
Definition: data.cc:5264
Sparse(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
Definition: Sparse.h:185
bool isempty(void) const
Definition: Sparse.h:478
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:295
T & xdata(octave_idx_type i)
Definition: Sparse.h:489
size_t byte_size(void) const
Definition: Sparse.h:271
octave_idx_type * xcidx(void)
Definition: Sparse.h:514
void * mex_get_data(void) const
Definition: Sparse.h:542
T & checkelem(octave_idx_type n)
Definition: Sparse.h:330
Sparse(octave_idx_type n)
Definition: Sparse.h:171
write the output to stdout if nargout is
Definition: load-save.cc:1612
bool indices_ok(void) const
Definition: Sparse.cc:170
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
bool test_all(F fcn) const
Definition: Sparse.h:579
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
Definition: utils.cc:888
dim_vector dv
Definition: sub2ind.cc:263
octave_idx_type dim2(void) const
Definition: Sparse.h:256
octave::stream os
Definition: file-io.cc:627
octave_idx_type rows(void) const
Definition: Sparse.h:258
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)
Definition: mx-inlines.cc:756
SparseRep(octave_idx_type n)
Definition: Sparse.h:75
octave_idx_type & cidx(octave_idx_type i)
Definition: Sparse.h:509