GNU Octave  4.2.1
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-2017 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 "octave-config.h"
30 
31 #include <cassert>
32 #include <cstddef>
33 
34 #include <iosfwd>
35 #include <algorithm>
36 
37 #include "Array.h"
38 #include "dim-vector.h"
39 #include "lo-error.h"
40 #include "lo-utils.h"
41 
42 #include "oct-sort.h"
43 
44 class idx_vector;
45 class PermMatrix;
46 
47 // Two dimensional sparse class. Handles the reference counting for
48 // all the derived classes.
49 
50 template <typename T>
51 class
52 Sparse
53 {
54 public:
55 
56  typedef T element_type;
57 
58 protected:
59  //--------------------------------------------------------------------
60  // The real representation of all Sparse arrays.
61  //--------------------------------------------------------------------
62 
63  class OCTAVE_API SparseRep
64  {
65  public:
66 
67  T *d;
74 
75  SparseRep (void)
76  : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0),
77  ncols (0), count (1)
78  {
79  c[0] = 0;
80  }
81 
83  : d (0), r (0), c (new octave_idx_type [n+1]), nzmx (0), nrows (n),
84  ncols (n), count (1)
85  {
86  for (octave_idx_type i = 0; i < n + 1; i++)
87  c[i] = 0;
88  }
89 
91  : d (nz > 0 ? new T [nz] : 0),
92  r (nz > 0 ? new octave_idx_type [nz] : 0),
93  c (new octave_idx_type [nc+1]), nzmx (nz), nrows (nr),
94  ncols (nc), count (1)
95  {
96  for (octave_idx_type i = 0; i < nc + 1; i++)
97  c[i] = 0;
98  }
99 
101  : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]),
102  c (new octave_idx_type [a.ncols + 1]),
103  nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1)
104  {
105  octave_idx_type nz = a.nnz ();
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);
109  }
110 
111  ~SparseRep (void) { delete [] d; delete [] r; delete [] c; }
112 
113  octave_idx_type length (void) const { return nzmx; }
114 
115  octave_idx_type nnz (void) const { return c[ncols]; }
116 
118 
119  T celem (octave_idx_type _r, octave_idx_type _c) const;
120 
121  T& data (octave_idx_type i) { return d[i]; }
122 
123  T cdata (octave_idx_type i) const { return d[i]; }
124 
126 
127  octave_idx_type cridx (octave_idx_type i) const { return r[i]; }
128 
130 
131  octave_idx_type ccidx (octave_idx_type i) const { return c[i]; }
132 
133  void maybe_compress (bool remove_zeros);
134 
135  void change_length (octave_idx_type nz);
136 
137  bool indices_ok (void) const;
138 
139  bool any_element_is_nan (void) const;
140 
141  private:
142 
143  // No assignment!
144 
145  SparseRep& operator = (const SparseRep& a);
146  };
147 
148  //--------------------------------------------------------------------
149 
150  void make_unique (void)
151  {
152  if (rep->count > 1)
153  {
154  SparseRep *r = new SparseRep (*rep);
155 
156  if (--rep->count == 0)
157  delete rep;
158 
159  rep = r;
160  }
161  }
162 
163 public:
164 
165  // !!! WARNING !!! -- these should be protected, not public. You
166  // should not access these data members directly!
167 
169 
171 
172 private:
173 
174  static typename Sparse<T>::SparseRep *nil_rep (void);
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 <typename 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  //! Amount of storage for nonzero elements.
244  //! This may differ from the actual number of elements, see nnz().
245  octave_idx_type nzmax (void) const { return rep->length (); }
246 
247  //! Amount of storage for nonzero elements.
248  //! Synonymous with nzmax().
249  OCTAVE_DEPRECATED ("use 'nzmax' instead")
250  octave_idx_type capacity (void) const { return nzmax (); }
251 
252  //! Actual number of nonzero terms.
253  octave_idx_type nnz (void) const { return rep->nnz (); }
254 
255  // Querying the number of elements (incl. zeros) may overflow the index type,
256  // so don't do it unless you really need it.
257  octave_idx_type numel (void) const
258  {
259  return dimensions.safe_numel ();
260  }
261 
262  OCTAVE_DEPRECATED ("use 'nzmax' instead")
263  octave_idx_type nelem (void) const { return nzmax (); }
264 
265  OCTAVE_DEPRECATED ("use 'numel' instead")
266  octave_idx_type length (void) const { return numel (); }
267 
268  octave_idx_type dim1 (void) const { return dimensions(0); }
269  octave_idx_type dim2 (void) const { return dimensions(1); }
270 
271  octave_idx_type rows (void) const { return dim1 (); }
272  octave_idx_type cols (void) const { return dim2 (); }
273  octave_idx_type columns (void) const { return dim2 (); }
274 
277  {
278  octave_idx_type ret = 0;
279  while (cidx (ret+1) < k)
280  ret++;
281  return ret;
282  }
283 
284  size_t byte_size (void) const
285  {
286  return (static_cast<size_t>(cols () + 1) * sizeof (octave_idx_type)
287  + static_cast<size_t> (nzmax ())
288  * (sizeof (T) + sizeof (octave_idx_type)));
289  }
290 
291  dim_vector dims (void) const { return dimensions; }
292 
293  Sparse<T> squeeze (void) const { return *this; }
294 
296 
297  OCTAVE_NORETURN T range_error (const char *fcn, octave_idx_type n) const;
298  OCTAVE_NORETURN T& range_error (const char *fcn, octave_idx_type n);
299 
300  OCTAVE_NORETURN T range_error (const char *fcn,
302  OCTAVE_NORETURN T& range_error (const char *fcn,
304 
305  OCTAVE_NORETURN T range_error (const char *fcn,
306  const Array<octave_idx_type>& ra_idx) const;
307  OCTAVE_NORETURN T& range_error (const char *fcn,
309 
310  // No checking, even for multiple references, ever.
311 
313  {
314  octave_idx_type i = n % rows ();
315  octave_idx_type j = n / rows ();
316  return xelem (i, j);
317  }
318 
319  T xelem (octave_idx_type n) const
320  {
321  octave_idx_type i = n % rows ();
322  octave_idx_type j = n / rows ();
323  return xelem (i, j);
324  }
325 
326  T& xelem (octave_idx_type i, octave_idx_type j) { return rep->elem (i, j); }
328  {
329  return rep->celem (i, j);
330  }
331 
333  { return xelem (compute_index (ra_idx)); }
334 
336  { return xelem (compute_index (ra_idx)); }
337 
338  // FIXME: would be nice to fix this so that we don't
339  // unnecessarily force a copy, but that is not so easy, and I see no
340  // clean way to do it.
341 
343  {
344  if (n < 0 || n >= numel ())
345  return range_error ("T& Sparse<T>::checkelem", n);
346  else
347  {
348  make_unique ();
349  return xelem (n);
350  }
351  }
352 
354  {
355  if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
356  return range_error ("T& Sparse<T>::checkelem", i, j);
357  else
358  {
359  make_unique ();
360  return xelem (i, j);
361  }
362  }
363 
365  {
366  octave_idx_type i = compute_index (ra_idx);
367 
368  if (i < 0)
369  return range_error ("T& Sparse<T>::checkelem", ra_idx);
370  else
371  return elem (i);
372  }
373 
375  {
376  make_unique ();
377  return xelem (n);
378  }
379 
381  {
382  make_unique ();
383  return xelem (i, j);
384  }
385 
387  { return Sparse<T>::elem (compute_index (ra_idx)); }
388 
389 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
390  T& operator () (octave_idx_type n)
391  {
392  return checkelem (n);
393  }
394 
395  T& operator () (octave_idx_type i, octave_idx_type j)
396  {
397  return checkelem (i, j);
398  }
399 
400  T& operator () (const Array<octave_idx_type>& ra_idx)
401  {
402  return checkelem (ra_idx);
403  }
404 
405 #else
406  T& operator () (octave_idx_type n)
407  {
408  return elem (n);
409  }
410 
411  T& operator () (octave_idx_type i, octave_idx_type j)
412  {
413  return elem (i, j);
414  }
415 
416  T& operator () (const Array<octave_idx_type>& ra_idx)
417  {
418  return elem (ra_idx);
419  }
420 
421 #endif
422 
424  {
425  if (n < 0 || n >= numel ())
426  return range_error ("T Sparse<T>::checkelem", n);
427  else
428  return xelem (n);
429  }
430 
432  {
433  if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
434  return range_error ("T Sparse<T>::checkelem", i, j);
435  else
436  return xelem (i, j);
437  }
438 
440  {
441  octave_idx_type i = compute_index (ra_idx);
442 
443  if (i < 0)
444  return range_error ("T Sparse<T>::checkelem", ra_idx);
445  else
446  return Sparse<T>::elem (i);
447  }
448 
449  T elem (octave_idx_type n) const { return xelem (n); }
450 
451  T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
452 
454  { return Sparse<T>::elem (compute_index (ra_idx)); }
455 
456 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
457  T operator () (octave_idx_type n) const { return checkelem (n); }
458  T operator () (octave_idx_type i, octave_idx_type j) const
459  {
460  return checkelem (i, j);
461  }
462 
463  T operator () (const Array<octave_idx_type>& ra_idx) const
464  {
465  return checkelem (ra_idx);
466  }
467 
468 #else
469  T operator () (octave_idx_type n) const { return elem (n); }
470  T operator () (octave_idx_type i, octave_idx_type j) const
471  {
472  return elem (i, j);
473  }
474 
475  T operator () (const Array<octave_idx_type>& ra_idx) const
476  {
477  return elem (ra_idx);
478  }
479 #endif
480 
481  Sparse<T> maybe_compress (bool remove_zeros = false)
482  {
483  if (remove_zeros)
484  make_unique (); // Needs to unshare because elements are removed.
485 
486  rep->maybe_compress (remove_zeros);
487  return (*this);
488  }
489 
490  Sparse<T> reshape (const dim_vector& new_dims) const;
491 
492  Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
493 
495  {
496  return permute (vec, true);
497  }
498 
499  void resize1 (octave_idx_type n);
500 
501  void resize (octave_idx_type r, octave_idx_type c);
502 
503  void resize (const dim_vector& dv);
504 
506  {
507  if (nz < nnz ())
508  make_unique (); // Unshare now because elements will be truncated.
509  rep->change_length (nz);
510  }
511 
512  Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c);
513  Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx);
514 
515  bool is_square (void) const { return (dim1 () == dim2 ()); }
516 
517  bool is_empty (void) const { return (rows () < 1 && cols () < 1); }
518 
519  Sparse<T> transpose (void) const;
520 
521  T* data (void) { make_unique (); return rep->d; }
522  T& data (octave_idx_type i) { make_unique (); return rep->data (i); }
523  T* xdata (void) { return rep->d; }
524  T& xdata (octave_idx_type i) { return rep->data (i); }
525 
526  T data (octave_idx_type i) const { return rep->data (i); }
527  // FIXME: shouldn't this be returning const T*?
528  T* data (void) const { return rep->d; }
529 
530  octave_idx_type* ridx (void) { make_unique (); return rep->r; }
532  {
533  make_unique (); return rep->ridx (i);
534  }
535 
536  octave_idx_type* xridx (void) { return rep->r; }
537  octave_idx_type& xridx (octave_idx_type i) { return rep->ridx (i); }
538 
539  octave_idx_type ridx (octave_idx_type i) const { return rep->cridx (i); }
540  // FIXME: shouldn't this be returning const octave_idx_type*?
541  octave_idx_type* ridx (void) const { return rep->r; }
542 
543  octave_idx_type* cidx (void) { make_unique (); return rep->c; }
545  {
546  make_unique (); return rep->cidx (i);
547  }
548 
549  octave_idx_type* xcidx (void) { return rep->c; }
550  octave_idx_type& xcidx (octave_idx_type i) { return rep->cidx (i); }
551 
552  octave_idx_type cidx (octave_idx_type i) const { return rep->ccidx (i); }
553  // FIXME: shouldn't this be returning const octave_idx_type*?
554  octave_idx_type* cidx (void) const { return rep->c; }
555 
556  octave_idx_type ndims (void) const { return dimensions.ndims (); }
557 
558  void delete_elements (const idx_vector& i);
559 
560  void delete_elements (int dim, const idx_vector& i);
561 
562  void delete_elements (const idx_vector& i, const idx_vector& j);
563 
564  Sparse<T> index (const idx_vector& i, bool resize_ok = false) const;
565 
566  Sparse<T> index (const idx_vector& i, const idx_vector& j,
567  bool resize_ok = false) const;
568 
569  void assign (const idx_vector& i, const Sparse<T>& rhs);
570 
571  void assign (const idx_vector& i, const idx_vector& j, const Sparse<T>& rhs);
572 
573  void print_info (std::ostream& os, const std::string& prefix) const;
574 
575  // Unsafe. These functions exist to support the MEX interface.
576  // You should not use them anywhere else.
577  void *mex_get_data (void) const { return const_cast<T *> (data ()); }
578 
580  {
581  return const_cast<octave_idx_type *> (ridx ());
582  }
583 
585  {
586  return const_cast<octave_idx_type *> (cidx ());
587  }
588 
589  Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
590  Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
591  sortmode mode = ASCENDING) const;
592 
593  Sparse<T> diag (octave_idx_type k = 0) const;
594 
595  // dim = -1 and dim = -2 are special; see Array<T>::cat description.
596  static Sparse<T>
597  cat (int dim, octave_idx_type n, const Sparse<T> *sparse_list);
598 
599  Array<T> array_value (void) const;
600 
601  // Generic any/all test functionality with arbitrary predicate.
602  template <typename F, bool zero>
603  bool test (F fcn) const
604  {
605  return any_all_test<F, T, zero> (fcn, data (), nnz ());
606  }
607 
608  // Simpler calls.
609  template <typename F>
610  bool test_any (F fcn) const
611  { return test<F, false> (fcn); }
612 
613  template <typename F>
614  bool test_all (F fcn) const
615  { return test<F, true> (fcn); }
616 
617  // Overloads for function references.
618  bool test_any (bool (&fcn) (T)) const
619  { return test<bool (&) (T), false> (fcn); }
620 
621  bool test_any (bool (&fcn) (const T&)) const
622  { return test<bool (&) (const T&), false> (fcn); }
623 
624  bool test_all (bool (&fcn) (T)) const
625  { return test<bool (&) (T), true> (fcn); }
626 
627  bool test_all (bool (&fcn) (const T&)) const
628  { return test<bool (&) (const T&), true> (fcn); }
629 
630  template <typename U, typename F>
631  Sparse<U>
632  map (F fcn) const
633  {
635  U f_zero = fcn (0.);
636 
637  if (f_zero != 0.)
638  {
639  octave_idx_type nr = rows ();
640  octave_idx_type nc = cols ();
641 
642  result = Sparse<U> (nr, nc, f_zero);
643 
644  for (octave_idx_type j = 0; j < nc; j++)
645  for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
646  {
647  octave_quit ();
648  /* Use data instead of elem for better performance. */
649  result.data (ridx (i) + j * nr) = fcn (data (i));
650  }
651 
652  result.maybe_compress (true);
653  }
654  else
655  {
656  octave_idx_type nz = nnz ();
657  octave_idx_type nr = rows ();
658  octave_idx_type nc = cols ();
659 
660  result = Sparse<U> (nr, nc, nz);
661  octave_idx_type ii = 0;
662  result.cidx (ii) = 0;
663 
664  for (octave_idx_type j = 0; j < nc; j++)
665  {
666  for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
667  {
668  U val = fcn (data (i));
669  if (val != 0.0)
670  {
671  result.data (ii) = val;
672  result.ridx (ii++) = ridx (i);
673  }
674  octave_quit ();
675  }
676  result.cidx (j+1) = ii;
677  }
678 
679  result.maybe_compress (false);
680  }
681 
682  return result;
683  }
684 
685  // Overloads for function references.
686  template <typename U>
687  Sparse<U>
688  map (U (&fcn) (T)) const
689  { return map<U, U (&) (T)> (fcn); }
690 
691  template <typename U>
692  Sparse<U>
693  map (U (&fcn) (const T&)) const
694  { return map<U, U (&) (const T&)> (fcn); }
695 
696  bool indices_ok (void) const { return rep->indices_ok (); }
697 
698  bool any_element_is_nan (void) const
699  { return rep->any_element_is_nan (); }
700 };
701 
702 template <typename T>
703 std::istream&
704 read_sparse_matrix (std::istream& is, Sparse<T>& a,
705  T (*read_fcn) (std::istream&));
706 
707 #endif
T element_type
Definition: Sparse.h:56
octave_idx_type & xcidx(octave_idx_type i)
Definition: Sparse.h:550
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:176
T & elem(octave_idx_type _r, octave_idx_type _c)
Definition: Sparse.cc:83
octave_idx_type * xridx(void)
Definition: Sparse.h:536
Sparse< T > ipermute(const Array< octave_idx_type > &vec) const
Definition: Sparse.h:494
T & elem(octave_idx_type i, octave_idx_type j)
Definition: Sparse.h:380
~SparseRep(void)
Definition: Sparse.h:111
dim_vector dimensions
Definition: Sparse.h:170
octave_idx_type cols(void) const
Definition: Sparse.h:272
T & xelem(const Array< octave_idx_type > &ra_idx)
Definition: Sparse.h:332
T cdata(octave_idx_type i) const
Definition: Sparse.h:123
T xelem(octave_idx_type i, octave_idx_type j) const
Definition: Sparse.h:327
T * data(void)
Definition: Sparse.h:521
octave_idx_type rows(void) const
Definition: Sparse.h:271
void change_length(octave_idx_type nz)
Definition: Sparse.cc:159
octave_idx_type * cidx(void) const
Definition: Sparse.h:554
octave_idx_type numel(void) const
Definition: Sparse.h:257
const octave_base_value const Array< octave_idx_type > & ra_idx
T & elem(octave_idx_type n)
Definition: Sparse.h:374
octave_idx_type cridx(octave_idx_type i) const
Definition: Sparse.h:127
dim_vector dims(void) const
Definition: Sparse.h:291
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:125
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
T & xelem(octave_idx_type n)
Definition: Sparse.h:312
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz=0)
Definition: Sparse.h:90
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:6386
T checkelem(octave_idx_type i, octave_idx_type j) const
Definition: Sparse.h:431
octave_idx_type nzmx
Definition: Sparse.h:70
for large enough k
Definition: lu.cc:606
T & data(octave_idx_type i)
Definition: Sparse.h:121
bool test_all(F fcn) const
Definition: Sparse.h:614
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:549
octave_idx_type ridx(octave_idx_type i) const
Definition: Sparse.h:539
bool test_all(bool(&fcn)(T)) const
Definition: Sparse.h:624
cat(2, A, B) esult
Definition: data.cc:2417
octave_idx_type & xridx(octave_idx_type i)
Definition: Sparse.h:537
octave_idx_type & cidx(octave_idx_type i)
Definition: Sparse.h:129
octave_idx_type & ridx(octave_idx_type i)
Definition: Sparse.h:531
octave_idx_type ccidx(octave_idx_type i) const
Definition: Sparse.h:131
bool any_element_is_nan(void) const
Definition: Sparse.cc:197
octave_idx_type dim1(void) const
Definition: Sparse.h:268
octave_idx_type nrows
Definition: Sparse.h:71
octave_idx_type * r
Definition: Sparse.h:68
octave_idx_type * cidx(void)
Definition: Sparse.h:543
T elem(octave_idx_type i, octave_idx_type j) const
Definition: Sparse.h:451
octave_idx_type columns(void) const
Definition: Sparse.h:273
T xelem(octave_idx_type n) const
Definition: Sparse.h:319
T & checkelem(const Array< octave_idx_type > &ra_idx)
Definition: Sparse.h:364
bool indices_ok(void) const
Definition: Sparse.cc:190
octave_idx_type * c
Definition: Sparse.h:69
octave_idx_type get_row_index(octave_idx_type k)
Definition: Sparse.h:275
bool indices_ok(void) const
Definition: Sparse.h:696
T & elem(const Array< octave_idx_type > &ra_idx)
Definition: Sparse.h:386
octave_function * fcn
Definition: ov-class.cc:1743
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)
Definition: Sparse.h:100
T & data(octave_idx_type i)
Definition: Sparse.h:522
octave_idx_type nnz(void) const
Actual number of nonzero terms.
Definition: Sparse.h:253
Sparse< T > squeeze(void) const
Definition: Sparse.h:293
bool test_any(bool(&fcn)(const T &)) const
Definition: Sparse.h:621
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:398
octave_idx_type nzmax(void) const
Amount of storage for nonzero elements.
Definition: Sparse.h:245
void maybe_compress(bool remove_zeros)
Definition: Sparse.cc:135
octave_idx_type get_col_index(octave_idx_type k)
Definition: Sparse.h:276
Sparse< T >::SparseRep * rep
Definition: Sparse.h:168
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:335
octave_idx_type safe_numel(void) const
Definition: dim-vector.cc:103
T data(octave_idx_type i) const
Definition: Sparse.h:526
void make_unique(void)
Definition: Sparse.h:150
void change_capacity(octave_idx_type nz)
Definition: Sparse.h:505
octave_idx_type ncols
Definition: Sparse.h:72
T checkelem(const Array< octave_idx_type > &ra_idx) const
Definition: Sparse.h:439
octave_idx_type ndims(void) const
Definition: Sparse.h:556
octave_idx_type * mex_get_ir(void) const
Definition: Sparse.h:579
Sparse< T > maybe_compress(bool remove_zeros=false)
Definition: Sparse.h:481
bool test_all(bool(&fcn)(const T &)) const
Definition: Sparse.h:627
octave_idx_type * mex_get_jc(void) const
Definition: Sparse.h:584
static int elem
Definition: __contourc__.cc:50
Sparse< U > map(U(&fcn)(T)) const
Definition: Sparse.h:688
size_t byte_size(void) const
Definition: Sparse.h:284
Sparse< U > map(F fcn) const
Definition: Sparse.h:632
octave_idx_type cidx(octave_idx_type i) const
Definition: Sparse.h:552
Sparse(const Sparse< T > &a)
Definition: Sparse.h:220
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
bool test(F fcn) const
Definition: Sparse.h:603
T & xelem(octave_idx_type i, octave_idx_type j)
Definition: Sparse.h:326
Sparse(void)
Definition: Sparse.h:178
With real return the complex result
Definition: data.cc:3375
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:126
octave_idx_type nnz(void) const
Definition: Sparse.h:115
bool test_any(bool(&fcn)(T)) const
Definition: Sparse.h:618
SparseRep(void)
Definition: Sparse.h:75
T::size_type numel(const T &str)
Definition: oct-string.cc:61
octave_idx_type * ridx(void)
Definition: Sparse.h:530
bool is_empty(void) const
Definition: Sparse.h:517
Sparse(octave_idx_type nr, octave_idx_type nc)
Definition: Sparse.h:188
T * data(void) const
Definition: Sparse.h:528
Compressed Column Sparse(rows=3, cols=4, nnz=2[17%])(1
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
T & checkelem(octave_idx_type i, octave_idx_type j)
Definition: Sparse.h:353
bool test_any(F fcn) const
Definition: Sparse.h:610
octave_idx_type & cidx(octave_idx_type i)
Definition: Sparse.h:544
Sparse< U > map(U(&fcn)(const T &)) const
Definition: Sparse.h:693
T * xdata(void)
Definition: Sparse.h:523
T & checkelem(octave_idx_type n)
Definition: Sparse.h:342
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
T elem(const Array< octave_idx_type > &ra_idx) const
Definition: Sparse.h:453
octave_idx_type * ridx(void) const
Definition: Sparse.h:541
T & xdata(octave_idx_type i)
Definition: Sparse.h:524
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:577
octave_refcount< int > count
Definition: Sparse.h:73
Sparse(const dim_vector &dv, octave_idx_type nz)
Definition: Sparse.h:194
octave_idx_type dim2(void) const
Definition: Sparse.h:269
T checkelem(octave_idx_type n) const
Definition: Sparse.h:423
write the output to stdout if nargout is
Definition: load-save.cc:1576
octave_idx_type length(void) const
Definition: Sparse.h:113
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
bool is_square(void) const
Definition: Sparse.h:515
T elem(octave_idx_type n) const
Definition: Sparse.h:449
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:854
dim_vector dv
Definition: sub2ind.cc:263
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:719
SparseRep(octave_idx_type n)
Definition: Sparse.h:82
bool any_element_is_nan(void) const
Definition: Sparse.h:698