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