GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
Sparse.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1998-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
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
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License 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// <https://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 <cstddef>
32
33#include <algorithm>
34#include <iosfwd>
35#include <string>
36
37#include "Array-fwd.h"
38#include "Sparse-fwd.h"
39#include "mx-fwd.h"
40
41// Two dimensional sparse class. Handles the reference counting for
42// all the derived classes.
43
44template <typename T, typename Alloc>
46{
47public:
48
49 typedef T element_type;
50
51protected:
52 //--------------------------------------------------------------------
53 // The real representation of all Sparse arrays.
54 //--------------------------------------------------------------------
55
56 class SparseRep : public Alloc
57 {
58 public:
59
60 typedef std::allocator_traits<Alloc> Alloc_traits;
61
62 typedef typename Alloc_traits::template rebind_traits<T> T_Alloc_traits;
63 typedef typename T_Alloc_traits::pointer T_pointer;
64
65 typedef typename Alloc_traits::template rebind_traits<octave_idx_type> idx_type_Alloc_traits;
66 typedef typename idx_type_Alloc_traits::pointer idx_type_pointer;
67
74 octave::refcount<octave_idx_type> m_count;
75
77 : Alloc (), m_data (T_allocate (1)), m_ridx (idx_type_allocate (1)),
78 m_cidx (idx_type_allocate (1)),
79 m_nzmax (1), m_nrows (0), m_ncols (0), m_count (1)
80 { }
81
83 : Alloc (), m_data (T_allocate (1)), m_ridx (idx_type_allocate (1)),
84 m_cidx (idx_type_allocate (n+1)),
85 m_nzmax (1), m_nrows (n), m_ncols (n), m_count (1)
86 { }
87
89 : Alloc (), m_data (T_allocate (nz > 0 ? nz : 1)),
90 m_ridx (idx_type_allocate (nz > 0 ? nz : 1)),
91 m_cidx (idx_type_allocate (nc+1)),
92 m_nzmax (nz > 0 ? nz : 1), m_nrows (nr), m_ncols (nc), m_count (1)
93 { }
94
96 const T *d, const octave_idx_type *r, const octave_idx_type *c)
97 : Alloc (), m_data (T_allocate (nz)),
98 m_ridx (idx_type_allocate (nz)),
99 m_cidx (idx_type_allocate (nc+1)),
100 m_nzmax (nz), m_nrows (nr), m_ncols (nc), m_count (1)
101 {
102 std::copy_n (d, nz, m_data);
103 std::copy_n (r, nz, m_ridx);
104 std::copy_n (c, m_ncols + 1, m_cidx);
105 }
106
107 template <typename U>
109 const U *d, const octave_idx_type *r, const octave_idx_type *c)
110 : Alloc (), m_data (T_allocate (nz)),
111 m_ridx (idx_type_allocate (nz)),
112 m_cidx (idx_type_allocate (nc+1)),
113 m_nzmax (nz), m_nrows (nr), m_ncols (nc), m_count (1)
114 {
115 std::copy_n (d, nz, m_data);
116 std::copy_n (r, nz, m_ridx);
117 std::copy_n (c, nc + 1, m_cidx);
118 }
119
120 template <typename U>
123 const Alloc& xallocator = Alloc ())
124 : Alloc (xallocator), m_data (d), m_ridx (r), m_cidx (c),
125 m_nzmax (nz), m_nrows (dv(0)), m_ncols (dv(1)), m_count (1)
126 { }
127
129 : Alloc (), m_data (T_allocate (a.m_nzmax)),
130 m_ridx (idx_type_allocate (a.m_nzmax)),
131 m_cidx (idx_type_allocate (a.m_ncols + 1)),
132 m_nzmax (a.m_nzmax), m_nrows (a.m_nrows), m_ncols (a.m_ncols),
133 m_count (1)
134 {
135 octave_idx_type nz = a.nnz ();
136 std::copy_n (a.m_data, nz, m_data);
137 std::copy_n (a.m_ridx, nz, m_ridx);
138 std::copy_n (a.m_cidx, m_ncols + 1, m_cidx);
139 }
140
142 {
143 T_deallocate (m_data, m_nzmax);
144 idx_type_deallocate (m_ridx, m_nzmax);
145 idx_type_deallocate (m_cidx, m_ncols + 1);
146 }
147
148 octave_idx_type nzmax () const { return m_nzmax; }
149 octave_idx_type nnz () const { return m_cidx[m_ncols]; }
150
151 octave_idx_type rows () const { return m_nrows; }
152 octave_idx_type cols () const { return m_ncols; }
153 octave_idx_type columns () const { return m_ncols; }
154
156
157 OCTAVE_API T celem (octave_idx_type r, octave_idx_type c) const;
158
159 T& data (octave_idx_type i) { return m_data[i]; }
160
161 T cdata (octave_idx_type i) const { return m_data[i]; }
162
163 octave_idx_type& ridx (octave_idx_type i) { return m_ridx[i]; }
164
165 octave_idx_type cridx (octave_idx_type i) const { return m_ridx[i]; }
166
167 octave_idx_type& cidx (octave_idx_type i) { return m_cidx[i]; }
168
169 octave_idx_type ccidx (octave_idx_type i) const { return m_cidx[i]; }
170
171 OCTAVE_API void maybe_compress (bool remove_zeros);
172
173 OCTAVE_API void change_length (octave_idx_type nz);
174
175 OCTAVE_API bool indices_ok () const;
176
177 OCTAVE_API bool any_element_is_nan () const;
178
179 // Prefer nzmax.
180 octave_idx_type length () const { return m_nzmax; }
181
182 template <typename U, typename A> friend class Sparse;
183
184 // No assignment!
185
186 SparseRep& operator = (const SparseRep&) = delete;
187
189 {
190 typename T_Alloc_traits::allocator_type& alloc = *this;
191
192 T_pointer data = T_Alloc_traits::allocate (alloc, len);
193 for (size_t i = 0; i < len; i++)
194 T_Alloc_traits::construct (alloc, data+i);
195
196 return data;
197 }
198
199 void T_deallocate (T_pointer data, size_t len)
200 {
201 typename T_Alloc_traits::allocator_type& alloc = *this;
202
203 for (size_t i = 0; i < len; i++)
204 T_Alloc_traits::destroy (alloc, data+i);
205 T_Alloc_traits::deallocate (alloc, data, len);
206 }
207
209 {
210 typename idx_type_Alloc_traits::allocator_type alloc = *this;
211
212 idx_type_pointer idx = idx_type_Alloc_traits::allocate (alloc, len);
213 for (size_t i = 0; i < len; i++)
214 idx_type_Alloc_traits::construct (alloc, idx+i);
215
216 return idx;
217 }
218
220 {
221 typename idx_type_Alloc_traits::allocator_type alloc = *this;
222
223 for (size_t i = 0; i < len; i++)
224 idx_type_Alloc_traits::destroy (alloc, idx+i);
225 idx_type_Alloc_traits::deallocate (alloc, idx, len);
226 }
227 };
228
229 //--------------------------------------------------------------------
230
232 {
233 if (m_rep->m_count > 1)
234 {
235 SparseRep *r = new SparseRep (*m_rep);
236
237 if (--m_rep->m_count == 0)
238 delete m_rep;
239
240 m_rep = r;
241 }
242 }
243
244protected:
245
247
249
250private:
251
252 static OCTAVE_API typename Sparse<T, Alloc>::SparseRep * nil_rep ();
253
254public:
255
257 : m_rep (nil_rep ()), m_dimensions (dim_vector (0, 0))
258 {
259 m_rep->m_count++;
260 }
261
263 : m_rep (new typename Sparse<T, Alloc>::SparseRep (n)),
264 m_dimensions (dim_vector (n, n)) { }
265
267 : m_rep (new typename Sparse<T, Alloc>::SparseRep (nr, nc)),
268 m_dimensions (dim_vector (nr, nc)) { }
269
270 explicit OCTAVE_API Sparse (octave_idx_type nr, octave_idx_type nc, T val);
271
273 : m_rep (new typename Sparse<T, Alloc>::SparseRep (dv(0), dv(1), nz)),
274 m_dimensions (dv) { }
275
277 : m_rep (new typename Sparse<T, Alloc>::SparseRep (nr, nc, nz)),
278 m_dimensions (dim_vector (nr, nc)) { }
279
280 // Construct a Sparse array from pointers to externally allocated
281 // arrays of values and indices. PTR, RIDX, and CIDX must be
282 // allocated with operator new. The Sparse object takes ownership of
283 // these arrays and will delete them when the Sparse object is
284 // deleted. The dimension vector DV must be consistent with the sizes
285 // of the allocated PTR, CIDX, and RIDX arrays.
286
288 T *ptr, octave_idx_type *ridx, octave_idx_type *cidx,
289 const Alloc& xallocator = Alloc ())
290 : m_rep (new typename Sparse<T, Alloc>::SparseRep (dv, nz, ptr, ridx, cidx, xallocator)),
291 m_dimensions (dv)
292 { }
293
294 // Both SparseMatrix and SparseBoolMatrix need this ctor, and this
295 // is their only common ancestor.
296 explicit OCTAVE_API Sparse (const PermMatrix& a);
297
298 // Type conversion case. Preserves nzmax.
299 template <typename U>
300 Sparse (const Sparse<U>& a)
301 : m_rep (new typename Sparse<T, Alloc>::SparseRep (a.rows (), a.cols (),
302 a.nzmax (), a.data (),
303 a.ridx (), a.cidx ())),
304 m_dimensions (a.dims ()) { }
305
306 // No type conversion case.
308 : m_rep (a.m_rep), m_dimensions (a.m_dimensions)
309 {
310 m_rep->m_count++;
311 }
312
313public:
314
315 OCTAVE_API Sparse (const dim_vector& dv);
316
317 OCTAVE_API Sparse (const Sparse<T, Alloc>& a, const dim_vector& dv);
318
320 Sparse (const Array<T>& a, const octave::idx_vector& r, const octave::idx_vector& c,
321 octave_idx_type nr = -1, octave_idx_type nc = -1,
322 bool sum_terms = true, octave_idx_type nzm = -1);
323
324 // Sparsify a normal matrix
325 OCTAVE_API Sparse (const Array<T>& a);
326
327 virtual ~Sparse ();
328
329 OCTAVE_API Sparse<T, Alloc>& operator = (const Sparse<T, Alloc>& a);
330
331 //! Amount of storage for nonzero elements.
332 //! This may differ from the actual number of elements, see nnz().
333 octave_idx_type nzmax () const { return m_rep->nzmax (); }
334
335 //! Actual number of nonzero terms.
336 octave_idx_type nnz () const { return m_rep->nnz (); }
337
338 // Querying the number of elements (incl. zeros) may overflow the index type,
339 // so don't do it unless you really need it.
341 {
342 return m_dimensions.safe_numel ();
343 }
344
345 octave_idx_type dim1 () const { return m_dimensions(0); }
346 octave_idx_type dim2 () const { return m_dimensions(1); }
347
348 octave_idx_type rows () const { return dim1 (); }
349 octave_idx_type cols () const { return dim2 (); }
350 octave_idx_type columns () const { return dim2 (); }
351
354 {
355 octave_idx_type ret = 0;
356 while (cidx (ret+1) < k)
357 ret++;
358 return ret;
359 }
360
361 std::size_t byte_size () const
362 {
363 return (static_cast<std::size_t> (cols () + 1) * sizeof (octave_idx_type)
364 + static_cast<std::size_t> (nzmax ())
365 * (sizeof (T) + sizeof (octave_idx_type)));
366 }
367
368 dim_vector dims () const { return m_dimensions; }
369
370 Sparse<T, Alloc> squeeze () const { return *this; }
371
374
375 OCTAVE_NORETURN OCTAVE_API T
376 range_error (const char *fcn, octave_idx_type n) const;
377 OCTAVE_NORETURN OCTAVE_API T&
378 range_error (const char *fcn, octave_idx_type n);
379
380 OCTAVE_NORETURN OCTAVE_API T
381 range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const;
382 OCTAVE_NORETURN OCTAVE_API T&
383 range_error (const char *fcn, octave_idx_type i, octave_idx_type j);
384
385 OCTAVE_NORETURN OCTAVE_API T
386 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) const;
387 OCTAVE_NORETURN OCTAVE_API T&
388 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx);
389
390 // No checking, even for multiple references, ever.
391
393 {
394 octave_idx_type i = n % rows ();
395 octave_idx_type j = n / rows ();
396 return xelem (i, j);
397 }
398
400 {
401 octave_idx_type i = n % rows ();
402 octave_idx_type j = n / rows ();
403 return xelem (i, j);
404 }
405
406 T& xelem (octave_idx_type i, octave_idx_type j) { return m_rep->elem (i, j); }
408 {
409 return m_rep->celem (i, j);
410 }
411
413 { return xelem (compute_index (ra_idx)); }
414
416 { return xelem (compute_index (ra_idx)); }
417
418 // FIXME: would be nice to fix this so that we don't unnecessarily force a
419 // copy, but that is not so easy, and I see no clean way to do it.
420
422 {
423 if (n < 0 || n >= numel ())
424 range_error ("T& Sparse<T>::checkelem", n);
425 else
426 {
427 make_unique ();
428 return xelem (n);
429 }
430 }
431
433 {
434 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
435 range_error ("T& Sparse<T>::checkelem", i, j);
436 else
437 {
438 make_unique ();
439 return xelem (i, j);
440 }
441 }
442
444 {
446
447 if (i < 0)
448 range_error ("T& Sparse<T>::checkelem", ra_idx);
449 else
450 return elem (i);
451 }
452
454 {
455 make_unique ();
456 return xelem (n);
457 }
458
460 {
461 make_unique ();
462 return xelem (i, j);
463 }
464
467
468 T& operator () (octave_idx_type n)
469 {
470 return elem (n);
471 }
472
473 T& operator () (octave_idx_type i, octave_idx_type j)
474 {
475 return elem (i, j);
476 }
477
478 T& operator () (const Array<octave_idx_type>& ra_idx)
479 {
480 return elem (ra_idx);
481 }
482
484 {
485 if (n < 0 || n >= numel ())
486 range_error ("T Sparse<T>::checkelem", n);
487 else
488 return xelem (n);
489 }
490
492 {
493 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
494 range_error ("T Sparse<T>::checkelem", i, j);
495 else
496 return xelem (i, j);
497 }
498
500 {
502
503 if (i < 0)
504 range_error ("T Sparse<T>::checkelem", ra_idx);
505 else
506 return Sparse<T, Alloc>::elem (i);
507 }
508
509 T elem (octave_idx_type n) const { return xelem (n); }
510
511 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
512
515
516 T operator () (octave_idx_type n) const { return elem (n); }
517
518 T operator () (octave_idx_type i, octave_idx_type j) const
519 {
520 return elem (i, j);
521 }
522
523 T operator () (const Array<octave_idx_type>& ra_idx) const
524 {
525 return elem (ra_idx);
526 }
527
528 Sparse<T, Alloc> maybe_compress (bool remove_zeros = false)
529 {
530 if (remove_zeros)
531 make_unique (); // Need to unshare because elements are removed.
532
533 m_rep->maybe_compress (remove_zeros);
534 return (*this);
535 }
536
537 OCTAVE_API Sparse<T, Alloc> reshape (const dim_vector& new_dims) const;
538
540 permute (const Array<octave_idx_type>& vec, bool inv = false) const;
541
543 {
544 return permute (vec, true);
545 }
546
547 OCTAVE_API void resize1 (octave_idx_type n);
548
549 OCTAVE_API void resize (octave_idx_type r, octave_idx_type c);
550
551 OCTAVE_API void resize (const dim_vector& dv);
552
554 {
555 if (nz < nnz ())
556 make_unique (); // Unshare now because elements will be truncated.
557 m_rep->change_length (nz);
558 }
559
561 insert (const Sparse<T, Alloc>& a, octave_idx_type r, octave_idx_type c);
563 insert (const Sparse<T, Alloc>& a, const Array<octave_idx_type>& idx);
564
565 bool issquare () const { return (dim1 () == dim2 ()); }
566
567 bool isempty () const { return (rows () < 1 || cols () < 1); }
568
569 OCTAVE_API Sparse<T, Alloc> transpose () const;
570
571 T * data () { make_unique (); return m_rep->m_data; }
572 T& data (octave_idx_type i) { make_unique (); return m_rep->data (i); }
573 T * xdata () { return m_rep->m_data; }
574 T& xdata (octave_idx_type i) { return m_rep->data (i); }
575
576 T data (octave_idx_type i) const { return m_rep->data (i); }
577 // FIXME: shouldn't this be returning const T*?
578 T * data () const { return m_rep->m_data; }
579
580 octave_idx_type * ridx () { make_unique (); return m_rep->m_ridx; }
582 {
583 make_unique (); return m_rep->ridx (i);
584 }
585
586 octave_idx_type * xridx () { return m_rep->m_ridx; }
587 octave_idx_type& xridx (octave_idx_type i) { return m_rep->ridx (i); }
588
589 octave_idx_type ridx (octave_idx_type i) const { return m_rep->cridx (i); }
590 // FIXME: shouldn't this be returning const octave_idx_type*?
591 octave_idx_type * ridx () const { return m_rep->m_ridx; }
592
593 octave_idx_type * cidx () { make_unique (); return m_rep->m_cidx; }
595 {
596 make_unique (); return m_rep->cidx (i);
597 }
598
599 octave_idx_type * xcidx () { return m_rep->m_cidx; }
600 octave_idx_type& xcidx (octave_idx_type i) { return m_rep->cidx (i); }
601
602 octave_idx_type cidx (octave_idx_type i) const { return m_rep->ccidx (i); }
603 // FIXME: shouldn't this be returning const octave_idx_type*?
604 octave_idx_type * cidx () const { return m_rep->m_cidx; }
605
606 octave_idx_type ndims () const { return m_dimensions.ndims (); }
607
608 OCTAVE_API void delete_elements (const octave::idx_vector& i);
609
610 OCTAVE_API void delete_elements (int dim, const octave::idx_vector& i);
611
612 OCTAVE_API void delete_elements (const octave::idx_vector& i, const octave::idx_vector& j);
613
615 index (const octave::idx_vector& i, bool resize_ok = false) const;
616
618 index (const octave::idx_vector& i, const octave::idx_vector& j,
619 bool resize_ok = false) const;
620
621 OCTAVE_API void assign (const octave::idx_vector& i,
622 const Sparse<T, Alloc>& rhs);
623
624 OCTAVE_API void assign (const octave::idx_vector& i, const T& rhs);
625
626 OCTAVE_API void
627 assign (const octave::idx_vector& i, const octave::idx_vector& j,
628 const Sparse<T, Alloc>& rhs);
629
630 OCTAVE_API void
631 assign (const octave::idx_vector& i, const octave::idx_vector& j,
632 const T& rhs);
633
634 OCTAVE_API void
635 print_info (std::ostream& os, const std::string& prefix) const;
636
638 sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
640 sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
641 sortmode mode = ASCENDING) const;
642
644
645 // dim = -1 and dim = -2 are special; see Array<T>::cat description.
647 cat (int dim, octave_idx_type n, const Sparse<T, Alloc> *sparse_list);
648
649 OCTAVE_API Array<T> array_value () const;
650
651 // Generic any/all test functionality with arbitrary predicate.
652 template <typename F, bool zero>
653 bool test (F fcn) const
654 {
655 return octave::any_all_test<F, T, zero> (fcn, data (), nnz ());
656 }
657
658 // Simpler calls.
659 template <typename F>
660 bool test_any (F fcn) const
661 { return test<F, false> (fcn); }
662
663 template <typename F>
664 bool test_all (F fcn) const
665 { return test<F, true> (fcn); }
666
667 // Overloads for function references.
668 bool test_any (bool (&fcn) (T)) const
669 { return test<bool (&) (T), false> (fcn); }
670
671 bool test_any (bool (&fcn) (const T&)) const
672 { return test<bool (&) (const T&), false> (fcn); }
673
674 bool test_all (bool (&fcn) (T)) const
675 { return test<bool (&) (T), true> (fcn); }
676
677 bool test_all (bool (&fcn) (const T&)) const
678 { return test<bool (&) (const T&), true> (fcn); }
679
680 template <typename U, typename F>
682 map (F fcn) const
683 {
684 Sparse<U> result;
685 U f_zero = fcn (0.0);
686
687 if (f_zero != 0.0)
688 {
689 octave_idx_type nr = rows ();
690 octave_idx_type nc = cols ();
691
692 result = Sparse<U> (nr, nc, f_zero);
693
694 for (octave_idx_type j = 0; j < nc; j++)
695 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
696 {
697 octave_quit ();
698 /* Use data instead of elem for better performance. */
699 result.data (ridx (i) + j * nr) = fcn (data (i));
700 }
701
702 result.maybe_compress (true);
703 }
704 else
705 {
706 octave_idx_type nz = nnz ();
707 octave_idx_type nr = rows ();
708 octave_idx_type nc = cols ();
709
710 result = Sparse<U> (nr, nc, nz);
711 octave_idx_type ii = 0;
712 result.cidx (ii) = 0;
713
714 for (octave_idx_type j = 0; j < nc; j++)
715 {
716 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
717 {
718 U val = fcn (data (i));
719 if (val != 0.0)
720 {
721 result.data (ii) = val;
722 result.ridx (ii++) = ridx (i);
723 }
724 octave_quit ();
725 }
726 result.cidx (j+1) = ii;
727 }
728
729 result.maybe_compress (false);
730 }
731
732 return result;
733 }
734
735 // Overloads for function references.
736 template <typename U>
738 map (U (&fcn) (T)) const
739 { return map<U, U (&) (T)> (fcn); }
740
741 template <typename U>
743 map (U (&fcn) (const T&)) const
744 { return map<U, U (&) (const T&)> (fcn); }
745
746 bool indices_ok () const { return m_rep->indices_ok (); }
747
748 bool any_element_is_nan () const
749 { return m_rep->any_element_is_nan (); }
750};
751
752template <typename T>
754std::istream&
755read_sparse_matrix (std::istream& is, Sparse<T>& a,
756 T (*read_fcn) (std::istream&));
757
758#endif
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
std::istream & read_sparse_matrix(std::istream &is, Sparse< T > &a, T(*read_fcn)(std::istream &))
Definition Sparse.cc:2791
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
SparseRep(const dim_vector &dv, octave_idx_type nz, U *d, octave_idx_type *r, octave_idx_type *c, const Alloc &xallocator=Alloc())
Definition Sparse.h:121
bool indices_ok() const
Definition Sparse.cc:178
octave_idx_type cols() const
Definition Sparse.h:152
bool any_element_is_nan() const
Definition Sparse.cc:186
void change_length(octave_idx_type nz)
Definition Sparse.cc:144
octave_idx_type nzmax() const
Definition Sparse.h:148
octave_idx_type nnz() const
Definition Sparse.h:149
octave_idx_type m_ncols
Definition Sparse.h:73
void T_deallocate(T_pointer data, size_t len)
Definition Sparse.h:199
octave::refcount< octave_idx_type > m_count
Definition Sparse.h:74
idx_type_pointer m_cidx
Definition Sparse.h:70
Alloc_traits::template rebind_traits< T > T_Alloc_traits
Definition Sparse.h:62
T_pointer m_data
Definition Sparse.h:68
SparseRep(octave_idx_type n)
Definition Sparse.h:82
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz, const T *d, const octave_idx_type *r, const octave_idx_type *c)
Definition Sparse.h:95
octave_idx_type columns() const
Definition Sparse.h:153
octave_idx_type rows() const
Definition Sparse.h:151
T cdata(octave_idx_type i) const
Definition Sparse.h:161
T_pointer T_allocate(size_t len)
Definition Sparse.h:188
octave_idx_type m_nrows
Definition Sparse.h:72
SparseRep(const SparseRep &a)
Definition Sparse.h:128
T & data(octave_idx_type i)
Definition Sparse.h:159
void maybe_compress(bool remove_zeros)
Definition Sparse.cc:119
octave_idx_type & ridx(octave_idx_type i)
Definition Sparse.h:163
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz=1)
Definition Sparse.h:88
octave_idx_type length() const
Definition Sparse.h:180
SparseRep(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz, const U *d, const octave_idx_type *r, const octave_idx_type *c)
Definition Sparse.h:108
T & elem(octave_idx_type r, octave_idx_type c)
Definition Sparse.cc:65
idx_type_pointer m_ridx
Definition Sparse.h:69
T_Alloc_traits::pointer T_pointer
Definition Sparse.h:63
octave_idx_type m_nzmax
Definition Sparse.h:71
idx_type_pointer idx_type_allocate(size_t len)
Definition Sparse.h:208
std::allocator_traits< Alloc > Alloc_traits
Definition Sparse.h:60
octave_idx_type cridx(octave_idx_type i) const
Definition Sparse.h:165
idx_type_Alloc_traits::pointer idx_type_pointer
Definition Sparse.h:66
octave_idx_type & cidx(octave_idx_type i)
Definition Sparse.h:167
octave_idx_type ccidx(octave_idx_type i) const
Definition Sparse.h:169
Alloc_traits::template rebind_traits< octave_idx_type > idx_type_Alloc_traits
Definition Sparse.h:65
T celem(octave_idx_type r, octave_idx_type c) const
Definition Sparse.cc:107
void idx_type_deallocate(idx_type_pointer idx, size_t len)
Definition Sparse.h:219
T * data() const
Definition Sparse.h:578
T & data(octave_idx_type i)
Definition Sparse.h:572
octave_idx_type cols() const
Definition Sparse.h:349
Sparse< U > map(U(&fcn)(const T &)) const
Definition Sparse.h:743
T xelem(const Array< octave_idx_type > &ra_idx) const
Definition Sparse.h:415
Sparse(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
Definition Sparse.h:276
bool test_all(F fcn) const
Definition Sparse.h:664
octave_idx_type * ridx() const
Definition Sparse.h:591
octave_idx_type nzmax() const
Amount of storage for nonzero elements.
Definition Sparse.h:333
T checkelem(octave_idx_type n) const
Definition Sparse.h:483
Sparse(const dim_vector &dv, octave_idx_type nz)
Definition Sparse.h:272
T elem(const Array< octave_idx_type > &ra_idx) const
Definition Sparse.h:513
octave_idx_type get_col_index(octave_idx_type k)
Definition Sparse.h:353
octave_idx_type & ridx(octave_idx_type i)
Definition Sparse.h:581
void make_unique()
Definition Sparse.h:231
octave_idx_type * cidx()
Definition Sparse.h:593
octave_idx_type columns() const
Definition Sparse.h:350
bool test_any(bool(&fcn)(const T &)) const
Definition Sparse.h:671
T * data()
Definition Sparse.h:571
T xelem(octave_idx_type n) const
Definition Sparse.h:399
T & xelem(octave_idx_type i, octave_idx_type j)
Definition Sparse.h:406
T & elem(octave_idx_type i, octave_idx_type j)
Definition Sparse.h:459
bool test_any(bool(&fcn)(T)) const
Definition Sparse.h:668
Sparse< T, Alloc > squeeze() const
Definition Sparse.h:370
bool indices_ok() const
Definition Sparse.h:746
T & checkelem(octave_idx_type n)
Definition Sparse.h:421
Sparse(octave_idx_type n)
Definition Sparse.h:262
octave_idx_type * cidx() const
Definition Sparse.h:604
octave_idx_type get_row_index(octave_idx_type k)
Definition Sparse.h:352
Sparse< U > map(F fcn) const
Definition Sparse.h:682
bool test_any(F fcn) const
Definition Sparse.h:660
T element_type
Definition Sparse.h:49
T checkelem(const Array< octave_idx_type > &ra_idx) const
Definition Sparse.h:499
T * xdata()
Definition Sparse.h:573
bool test(F fcn) const
Definition Sparse.h:653
T & elem(octave_idx_type n)
Definition Sparse.h:453
octave_idx_type ridx(octave_idx_type i) const
Definition Sparse.h:589
octave_idx_type & xridx(octave_idx_type i)
Definition Sparse.h:587
octave_idx_type ndims() const
Definition Sparse.h:606
octave_idx_type * ridx()
Definition Sparse.h:580
T elem(octave_idx_type n) const
Definition Sparse.h:509
T & checkelem(const Array< octave_idx_type > &ra_idx)
Definition Sparse.h:443
bool test_all(bool(&fcn)(T)) const
Definition Sparse.h:674
Sparse(const Sparse< U > &a)
Definition Sparse.h:300
octave_idx_type numel() const
Definition Sparse.h:340
T & elem(const Array< octave_idx_type > &ra_idx)
Definition Sparse.h:465
Sparse< T, Alloc > ipermute(const Array< octave_idx_type > &vec) const
Definition Sparse.h:542
Sparse()
Definition Sparse.h:256
T data(octave_idx_type i) const
Definition Sparse.h:576
bool test_all(bool(&fcn)(const T &)) const
Definition Sparse.h:677
Sparse(const dim_vector &dv, octave_idx_type nz, T *ptr, octave_idx_type *ridx, octave_idx_type *cidx, const Alloc &xallocator=Alloc())
Definition Sparse.h:287
T & xdata(octave_idx_type i)
Definition Sparse.h:574
T xelem(octave_idx_type i, octave_idx_type j) const
Definition Sparse.h:407
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
Definition Sparse.h:528
std::size_t byte_size() const
Definition Sparse.h:361
octave_idx_type dim2() const
Definition Sparse.h:346
octave_idx_type dim1() const
Definition Sparse.h:345
T elem(octave_idx_type i, octave_idx_type j) const
Definition Sparse.h:511
octave_idx_type nnz() const
Actual number of nonzero terms.
Definition Sparse.h:336
Sparse(const Sparse< T, Alloc > &a)
Definition Sparse.h:307
bool issquare() const
Definition Sparse.h:565
T checkelem(octave_idx_type i, octave_idx_type j) const
Definition Sparse.h:491
octave_idx_type rows() const
Definition Sparse.h:348
T & xelem(const Array< octave_idx_type > &ra_idx)
Definition Sparse.h:412
void change_capacity(octave_idx_type nz)
Definition Sparse.h:553
Sparse(octave_idx_type nr, octave_idx_type nc)
Definition Sparse.h:266
T & checkelem(octave_idx_type i, octave_idx_type j)
Definition Sparse.h:432
dim_vector m_dimensions
Definition Sparse.h:248
Sparse< U > map(U(&fcn)(T)) const
Definition Sparse.h:738
T & xelem(octave_idx_type n)
Definition Sparse.h:392
octave_idx_type cidx(octave_idx_type i) const
Definition Sparse.h:602
Sparse< T, Alloc >::SparseRep * m_rep
Definition Sparse.h:246
bool any_element_is_nan() const
Definition Sparse.h:748
octave_idx_type & cidx(octave_idx_type i)
Definition Sparse.h:594
dim_vector dims() const
Definition Sparse.h:368
octave_idx_type & xcidx(octave_idx_type i)
Definition Sparse.h:600
octave_idx_type * xcidx()
Definition Sparse.h:599
octave_idx_type * xridx()
Definition Sparse.h:586
bool isempty() const
Definition Sparse.h:567
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
octave_idx_type safe_numel() const
The following function will throw a std::bad_alloc () exception if the requested size is larger than ...
Definition dim-vector.cc:98
octave_idx_type ndims() const
Number of dimensions.
Definition dim-vector.h:253
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
#define OCTAVE_API
Definition main.in.cc:55
sortmode
Definition oct-sort.h:97
@ ASCENDING
Definition oct-sort.h:97
T::size_type numel(const T &str)
Definition oct-string.cc:74
const octave_base_value const Array< octave_idx_type > & ra_idx
F77_RET_T len
Definition xerbla.cc:61