GNU Octave 11.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-2026 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 OCTAVE_API bool any_element_is_inf_or_nan () const;
180
181 // Prefer nzmax.
182 octave_idx_type length () const { return m_nzmax; }
183
184 template <typename U, typename A> friend class Sparse;
185
186 // No assignment!
187
188 SparseRep& operator = (const SparseRep&) = delete;
189
191 {
192 typename T_Alloc_traits::allocator_type& alloc = *this;
193
194 T_pointer data = T_Alloc_traits::allocate (alloc, len);
195 for (size_t i = 0; i < len; i++)
196 T_Alloc_traits::construct (alloc, data+i);
197
198 return data;
199 }
200
201 void T_deallocate (T_pointer data, size_t len)
202 {
203 typename T_Alloc_traits::allocator_type& alloc = *this;
204
205 for (size_t i = 0; i < len; i++)
206 T_Alloc_traits::destroy (alloc, data+i);
207 T_Alloc_traits::deallocate (alloc, data, len);
208 }
209
211 {
212 typename idx_type_Alloc_traits::allocator_type alloc = *this;
213
214 idx_type_pointer idx = idx_type_Alloc_traits::allocate (alloc, len);
215 for (size_t i = 0; i < len; i++)
216 idx_type_Alloc_traits::construct (alloc, idx+i);
217
218 return idx;
219 }
220
222 {
223 typename idx_type_Alloc_traits::allocator_type alloc = *this;
224
225 for (size_t i = 0; i < len; i++)
226 idx_type_Alloc_traits::destroy (alloc, idx+i);
227 idx_type_Alloc_traits::deallocate (alloc, idx, len);
228 }
229 };
230
231 //--------------------------------------------------------------------
232
234 {
235 if (m_rep->m_count > 1)
236 {
237 SparseRep *r = new SparseRep (*m_rep);
238
239 if (--m_rep->m_count == 0)
240 delete m_rep;
241
242 m_rep = r;
243 }
244 }
245
246protected:
247
249
251
252private:
253
254 static OCTAVE_API typename Sparse<T, Alloc>::SparseRep * nil_rep ();
255
256public:
257
259 : m_rep (nil_rep ()), m_dimensions (dim_vector (0, 0))
260 {
261 m_rep->m_count++;
262 }
263
265 : m_rep (new typename Sparse<T, Alloc>::SparseRep (n)),
266 m_dimensions (dim_vector (n, n)) { }
267
269 : m_rep (new typename Sparse<T, Alloc>::SparseRep (nr, nc)),
270 m_dimensions (dim_vector (nr, nc)) { }
271
272 explicit OCTAVE_API Sparse (octave_idx_type nr, octave_idx_type nc, T val);
273
275 : m_rep (new typename Sparse<T, Alloc>::SparseRep (dv(0), dv(1), nz)),
276 m_dimensions (dv) { }
277
279 : m_rep (new typename Sparse<T, Alloc>::SparseRep (nr, nc, nz)),
280 m_dimensions (dim_vector (nr, nc)) { }
281
282 // Construct a Sparse array from pointers to externally allocated
283 // arrays of values and indices. PTR, RIDX, and CIDX must be
284 // allocated with operator new. The Sparse object takes ownership of
285 // these arrays and will delete them when the Sparse object is
286 // deleted. The dimension vector DV must be consistent with the sizes
287 // of the allocated PTR, CIDX, and RIDX arrays.
288
290 T *ptr, octave_idx_type *ridx, octave_idx_type *cidx,
291 const Alloc& xallocator = Alloc ())
292 : m_rep (new typename Sparse<T, Alloc>::SparseRep (dv, nz, ptr, ridx, cidx, xallocator)),
293 m_dimensions (dv)
294 { }
295
296 // Both SparseMatrix and SparseBoolMatrix need this ctor, and this
297 // is their only common ancestor.
298 explicit OCTAVE_API Sparse (const PermMatrix& a);
299
300 // Type conversion case. Preserves nzmax.
301 template <typename U>
302 Sparse (const Sparse<U>& a)
303 : m_rep (new typename Sparse<T, Alloc>::SparseRep (a.rows (), a.cols (),
304 a.nzmax (), a.data (),
305 a.ridx (), a.cidx ())),
306 m_dimensions (a.dims ()) { }
307
308 // No type conversion case.
310 : m_rep (a.m_rep), m_dimensions (a.m_dimensions)
311 {
312 m_rep->m_count++;
313 }
314
315public:
316
317 OCTAVE_API Sparse (const dim_vector& dv);
318
319 OCTAVE_API Sparse (const Sparse<T, Alloc>& a, const dim_vector& dv);
320
322 Sparse (const Array<T>& a, const octave::idx_vector& r, const octave::idx_vector& c,
323 octave_idx_type nr = -1, octave_idx_type nc = -1,
324 bool sum_terms = true, octave_idx_type nzm = -1);
325
326 // Sparsify a normal matrix
327 OCTAVE_API Sparse (const Array<T>& a);
328
329 virtual ~Sparse ();
330
331 OCTAVE_API Sparse<T, Alloc>& operator = (const Sparse<T, Alloc>& a);
332
333 //! Amount of storage for nonzero elements.
334 //! This may differ from the actual number of elements, see nnz().
335 octave_idx_type nzmax () const { return m_rep->nzmax (); }
336
337 //! Actual number of nonzero terms.
338 octave_idx_type nnz () const { return m_rep->nnz (); }
339
340 // Querying the number of elements (incl. zeros) may overflow the index type,
341 // so don't do it unless you really need it.
343 {
344 return m_dimensions.safe_numel ();
345 }
346
347 octave_idx_type dim1 () const { return m_dimensions(0); }
348 octave_idx_type dim2 () const { return m_dimensions(1); }
349
350 octave_idx_type rows () const { return dim1 (); }
351 octave_idx_type cols () const { return dim2 (); }
352 octave_idx_type columns () const { return dim2 (); }
353
356 {
357 octave_idx_type ret = 0;
358 while (cidx (ret+1) < k)
359 ret++;
360 return ret;
361 }
362
363 std::size_t byte_size () const
364 {
365 return (static_cast<std::size_t> (cols () + 1) * sizeof (octave_idx_type)
366 + static_cast<std::size_t> (nzmax ())
367 * (sizeof (T) + sizeof (octave_idx_type)));
368 }
369
370 dim_vector dims () const { return m_dimensions; }
371
372 Sparse<T, Alloc> squeeze () const { return *this; }
373
376
377 OCTAVE_NORETURN OCTAVE_API T
378 range_error (const char *fcn, octave_idx_type n) const;
379 OCTAVE_NORETURN OCTAVE_API T&
380 range_error (const char *fcn, octave_idx_type n);
381
382 OCTAVE_NORETURN OCTAVE_API T
383 range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const;
384 OCTAVE_NORETURN OCTAVE_API T&
385 range_error (const char *fcn, octave_idx_type i, octave_idx_type j);
386
387 OCTAVE_NORETURN OCTAVE_API T
388 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) const;
389 OCTAVE_NORETURN OCTAVE_API T&
390 range_error (const char *fcn, const Array<octave_idx_type>& ra_idx);
391
392 // No checking, even for multiple references, ever.
393
395 {
396 octave_idx_type i = n % rows ();
397 octave_idx_type j = n / rows ();
398 return xelem (i, j);
399 }
400
402 {
403 octave_idx_type i = n % rows ();
404 octave_idx_type j = n / rows ();
405 return xelem (i, j);
406 }
407
408 T& xelem (octave_idx_type i, octave_idx_type j) { return m_rep->elem (i, j); }
410 {
411 return m_rep->celem (i, j);
412 }
413
415 { return xelem (compute_index (ra_idx)); }
416
418 { return xelem (compute_index (ra_idx)); }
419
420 // FIXME: would be nice to fix this so that we don't unnecessarily force a
421 // copy, but that is not so easy, and I see no clean way to do it.
422
424 {
425 if (n < 0 || n >= numel ())
426 range_error ("T& Sparse<T>::checkelem", n);
427 else
428 {
429 make_unique ();
430 return xelem (n);
431 }
432 }
433
435 {
436 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
437 range_error ("T& Sparse<T>::checkelem", i, j);
438 else
439 {
440 make_unique ();
441 return xelem (i, j);
442 }
443 }
444
446 {
448
449 if (i < 0)
450 range_error ("T& Sparse<T>::checkelem", ra_idx);
451 else
452 return elem (i);
453 }
454
456 {
457 make_unique ();
458 return xelem (n);
459 }
460
462 {
463 make_unique ();
464 return xelem (i, j);
465 }
466
469
470 T& operator () (octave_idx_type n)
471 {
472 return elem (n);
473 }
474
475 T& operator () (octave_idx_type i, octave_idx_type j)
476 {
477 return elem (i, j);
478 }
479
480 T& operator () (const Array<octave_idx_type>& ra_idx)
481 {
482 return elem (ra_idx);
483 }
484
486 {
487 if (n < 0 || n >= numel ())
488 range_error ("T Sparse<T>::checkelem", n);
489 else
490 return xelem (n);
491 }
492
494 {
495 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
496 range_error ("T Sparse<T>::checkelem", i, j);
497 else
498 return xelem (i, j);
499 }
500
502 {
504
505 if (i < 0)
506 range_error ("T Sparse<T>::checkelem", ra_idx);
507 else
508 return Sparse<T, Alloc>::elem (i);
509 }
510
511 T elem (octave_idx_type n) const { return xelem (n); }
512
513 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
514
517
518 T operator () (octave_idx_type n) const { return elem (n); }
519
520 T operator () (octave_idx_type i, octave_idx_type j) const
521 {
522 return elem (i, j);
523 }
524
525 T operator () (const Array<octave_idx_type>& ra_idx) const
526 {
527 return elem (ra_idx);
528 }
529
530 Sparse<T, Alloc> maybe_compress (bool remove_zeros = false)
531 {
532 if (remove_zeros)
533 make_unique (); // Need to unshare because elements are removed.
534
535 m_rep->maybe_compress (remove_zeros);
536 return (*this);
537 }
538
539 OCTAVE_API Sparse<T, Alloc> reshape (const dim_vector& new_dims) const;
540
542 permute (const Array<octave_idx_type>& vec, bool inv = false) const;
543
545 {
546 return permute (vec, true);
547 }
548
549 OCTAVE_API void resize1 (octave_idx_type n);
550
551 OCTAVE_API void resize (octave_idx_type r, octave_idx_type c);
552
553 OCTAVE_API void resize (const dim_vector& dv);
554
556 {
557 if (nz < nnz ())
558 make_unique (); // Unshare now because elements will be truncated.
559 m_rep->change_length (nz);
560 }
561
563 insert (const Sparse<T, Alloc>& a, octave_idx_type r, octave_idx_type c);
565 insert (const Sparse<T, Alloc>& a, const Array<octave_idx_type>& idx);
566
567 bool issquare () const { return (dim1 () == dim2 ()); }
568
569 bool isempty () const { return (rows () < 1 || cols () < 1); }
570
571 OCTAVE_API Sparse<T, Alloc> transpose () const;
572
573 T * data () { make_unique (); return m_rep->m_data; }
574 T& data (octave_idx_type i) { make_unique (); return m_rep->data (i); }
575 T * xdata () { return m_rep->m_data; }
576 T& xdata (octave_idx_type i) { return m_rep->data (i); }
577
578 T data (octave_idx_type i) const { return m_rep->data (i); }
579 // FIXME: shouldn't this be returning const T*?
580 T * data () const { return m_rep->m_data; }
581
582 octave_idx_type * ridx () { make_unique (); return m_rep->m_ridx; }
584 {
585 make_unique (); return m_rep->ridx (i);
586 }
587
588 octave_idx_type * xridx () { return m_rep->m_ridx; }
589 octave_idx_type& xridx (octave_idx_type i) { return m_rep->ridx (i); }
590
591 octave_idx_type ridx (octave_idx_type i) const { return m_rep->cridx (i); }
592 // FIXME: shouldn't this be returning const octave_idx_type*?
593 octave_idx_type * ridx () const { return m_rep->m_ridx; }
594
595 octave_idx_type * cidx () { make_unique (); return m_rep->m_cidx; }
597 {
598 make_unique (); return m_rep->cidx (i);
599 }
600
601 octave_idx_type * xcidx () { return m_rep->m_cidx; }
602 octave_idx_type& xcidx (octave_idx_type i) { return m_rep->cidx (i); }
603
604 octave_idx_type cidx (octave_idx_type i) const { return m_rep->ccidx (i); }
605 // FIXME: shouldn't this be returning const octave_idx_type*?
606 octave_idx_type * cidx () const { return m_rep->m_cidx; }
607
608 octave_idx_type ndims () const { return m_dimensions.ndims (); }
609
610 OCTAVE_API void delete_elements (const octave::idx_vector& i);
611
612 OCTAVE_API void delete_elements (int dim, const octave::idx_vector& i);
613
614 OCTAVE_API void delete_elements (const octave::idx_vector& i, const octave::idx_vector& j);
615
617 index (const octave::idx_vector& i, bool resize_ok = false) const;
618
620 index (const octave::idx_vector& i, const octave::idx_vector& j,
621 bool resize_ok = false) const;
622
623 OCTAVE_API void assign (const octave::idx_vector& i,
624 const Sparse<T, Alloc>& rhs);
625
626 OCTAVE_API void assign (const octave::idx_vector& i, const T& rhs);
627
628 OCTAVE_API void
629 assign (const octave::idx_vector& i, const octave::idx_vector& j,
630 const Sparse<T, Alloc>& rhs);
631
632 OCTAVE_API void
633 assign (const octave::idx_vector& i, const octave::idx_vector& j,
634 const T& rhs);
635
636 OCTAVE_API void
637 print_info (std::ostream& os, const std::string& prefix) const;
638
640 sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
642 sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
643 sortmode mode = ASCENDING) const;
644
646
647 // dim = -1 and dim = -2 are special; see Array<T>::cat description.
649 cat (int dim, octave_idx_type n, const Sparse<T, Alloc> *sparse_list);
650
651 OCTAVE_API Array<T> array_value () const;
652
653 // Generic any/all test functionality with arbitrary predicate.
654 template <typename F, bool zero>
655 bool test (F fcn) const
656 {
657 return octave::any_all_test<F, T, zero> (fcn, data (), nnz ());
658 }
659
660 // Simpler calls.
661 template <typename F>
662 bool test_any (F fcn) const
663 { return test<F, false> (fcn); }
664
665 template <typename F>
666 bool test_all (F fcn) const
667 { return test<F, true> (fcn); }
668
669 // Overloads for function references.
670 bool test_any (bool (&fcn) (T)) const
671 { return test<bool (&) (T), false> (fcn); }
672
673 bool test_any (bool (&fcn) (const T&)) const
674 { return test<bool (&) (const T&), false> (fcn); }
675
676 bool test_all (bool (&fcn) (T)) const
677 { return test<bool (&) (T), true> (fcn); }
678
679 bool test_all (bool (&fcn) (const T&)) const
680 { return test<bool (&) (const T&), true> (fcn); }
681
682 template <typename U, typename F>
684 map (F fcn) const
685 {
686 Sparse<U> result;
687 U f_zero = fcn (0.0);
688
689 if (f_zero != 0.0)
690 {
691 octave_idx_type nr = rows ();
692 octave_idx_type nc = cols ();
693
694 result = Sparse<U> (nr, nc, f_zero);
695
696 for (octave_idx_type j = 0; j < nc; j++)
697 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
698 {
699 octave_quit ();
700 /* Use data instead of elem for better performance. */
701 result.data (ridx (i) + j * nr) = fcn (data (i));
702 }
703
704 result.maybe_compress (true);
705 }
706 else
707 {
708 octave_idx_type nz = nnz ();
709 octave_idx_type nr = rows ();
710 octave_idx_type nc = cols ();
711
712 result = Sparse<U> (nr, nc, nz);
713 octave_idx_type ii = 0;
714 result.cidx (ii) = 0;
715
716 for (octave_idx_type j = 0; j < nc; j++)
717 {
718 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
719 {
720 U val = fcn (data (i));
721 if (val != 0.0)
722 {
723 result.data (ii) = val;
724 result.ridx (ii++) = ridx (i);
725 }
726 octave_quit ();
727 }
728 result.cidx (j+1) = ii;
729 }
730
731 result.maybe_compress (false);
732 }
733
734 return result;
735 }
736
737 // Overloads for function references.
738 template <typename U>
740 map (U (&fcn) (T)) const
741 { return map<U, U (&) (T)> (fcn); }
742
743 template <typename U>
745 map (U (&fcn) (const T&)) const
746 { return map<U, U (&) (const T&)> (fcn); }
747
748 bool indices_ok () const { return m_rep->indices_ok (); }
749
750 bool any_element_is_nan () const
751 { return m_rep->any_element_is_nan (); }
752
754 { return m_rep->any_element_is_inf_or_nan (); }
755};
756
757template <typename T>
759std::istream&
760read_sparse_matrix (std::istream& is, Sparse<T>& a,
761 T (*read_fcn) (std::istream&));
762
763#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:2805
N Dimensional Array with copy-on-write semantics.
Definition Array-base.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:201
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:190
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:182
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:210
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
bool any_element_is_inf_or_nan() const
Definition Sparse.cc:200
void idx_type_deallocate(idx_type_pointer idx, size_t len)
Definition Sparse.h:221
T * data() const
Definition Sparse.h:580
T & data(octave_idx_type i)
Definition Sparse.h:574
octave_idx_type cols() const
Definition Sparse.h:351
Sparse< U > map(U(&fcn)(const T &)) const
Definition Sparse.h:745
T xelem(const Array< octave_idx_type > &ra_idx) const
Definition Sparse.h:417
Sparse(octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
Definition Sparse.h:278
bool test_all(F fcn) const
Definition Sparse.h:666
octave_idx_type * ridx() const
Definition Sparse.h:593
octave_idx_type nzmax() const
Amount of storage for nonzero elements.
Definition Sparse.h:335
T checkelem(octave_idx_type n) const
Definition Sparse.h:485
Sparse(const dim_vector &dv, octave_idx_type nz)
Definition Sparse.h:274
T elem(const Array< octave_idx_type > &ra_idx) const
Definition Sparse.h:515
octave_idx_type get_col_index(octave_idx_type k)
Definition Sparse.h:355
octave_idx_type & ridx(octave_idx_type i)
Definition Sparse.h:583
void make_unique()
Definition Sparse.h:233
octave_idx_type * cidx()
Definition Sparse.h:595
octave_idx_type columns() const
Definition Sparse.h:352
bool test_any(bool(&fcn)(const T &)) const
Definition Sparse.h:673
T * data()
Definition Sparse.h:573
T xelem(octave_idx_type n) const
Definition Sparse.h:401
T & xelem(octave_idx_type i, octave_idx_type j)
Definition Sparse.h:408
T & elem(octave_idx_type i, octave_idx_type j)
Definition Sparse.h:461
bool test_any(bool(&fcn)(T)) const
Definition Sparse.h:670
Sparse< T, Alloc > squeeze() const
Definition Sparse.h:372
bool indices_ok() const
Definition Sparse.h:748
T & checkelem(octave_idx_type n)
Definition Sparse.h:423
Sparse(octave_idx_type n)
Definition Sparse.h:264
octave_idx_type * cidx() const
Definition Sparse.h:606
octave_idx_type get_row_index(octave_idx_type k)
Definition Sparse.h:354
Sparse< U > map(F fcn) const
Definition Sparse.h:684
bool test_any(F fcn) const
Definition Sparse.h:662
T element_type
Definition Sparse.h:49
T checkelem(const Array< octave_idx_type > &ra_idx) const
Definition Sparse.h:501
T * xdata()
Definition Sparse.h:575
bool test(F fcn) const
Definition Sparse.h:655
T & elem(octave_idx_type n)
Definition Sparse.h:455
octave_idx_type ridx(octave_idx_type i) const
Definition Sparse.h:591
octave_idx_type & xridx(octave_idx_type i)
Definition Sparse.h:589
octave_idx_type ndims() const
Definition Sparse.h:608
octave_idx_type * ridx()
Definition Sparse.h:582
T elem(octave_idx_type n) const
Definition Sparse.h:511
T & checkelem(const Array< octave_idx_type > &ra_idx)
Definition Sparse.h:445
bool test_all(bool(&fcn)(T)) const
Definition Sparse.h:676
Sparse(const Sparse< U > &a)
Definition Sparse.h:302
octave_idx_type numel() const
Definition Sparse.h:342
T & elem(const Array< octave_idx_type > &ra_idx)
Definition Sparse.h:467
Sparse< T, Alloc > ipermute(const Array< octave_idx_type > &vec) const
Definition Sparse.h:544
bool any_element_is_inf_or_nan() const
Definition Sparse.h:753
Sparse()
Definition Sparse.h:258
T data(octave_idx_type i) const
Definition Sparse.h:578
bool test_all(bool(&fcn)(const T &)) const
Definition Sparse.h:679
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:289
T & xdata(octave_idx_type i)
Definition Sparse.h:576
T xelem(octave_idx_type i, octave_idx_type j) const
Definition Sparse.h:409
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
Definition Sparse.h:530
std::size_t byte_size() const
Definition Sparse.h:363
octave_idx_type dim2() const
Definition Sparse.h:348
octave_idx_type dim1() const
Definition Sparse.h:347
T elem(octave_idx_type i, octave_idx_type j) const
Definition Sparse.h:513
octave_idx_type nnz() const
Actual number of nonzero terms.
Definition Sparse.h:338
Sparse(const Sparse< T, Alloc > &a)
Definition Sparse.h:309
bool issquare() const
Definition Sparse.h:567
T checkelem(octave_idx_type i, octave_idx_type j) const
Definition Sparse.h:493
octave_idx_type rows() const
Definition Sparse.h:350
T & xelem(const Array< octave_idx_type > &ra_idx)
Definition Sparse.h:414
void change_capacity(octave_idx_type nz)
Definition Sparse.h:555
Sparse(octave_idx_type nr, octave_idx_type nc)
Definition Sparse.h:268
T & checkelem(octave_idx_type i, octave_idx_type j)
Definition Sparse.h:434
dim_vector m_dimensions
Definition Sparse.h:250
Sparse< U > map(U(&fcn)(T)) const
Definition Sparse.h:740
T & xelem(octave_idx_type n)
Definition Sparse.h:394
octave_idx_type cidx(octave_idx_type i) const
Definition Sparse.h:604
Sparse< T, Alloc >::SparseRep * m_rep
Definition Sparse.h:248
bool any_element_is_nan() const
Definition Sparse.h:750
octave_idx_type & cidx(octave_idx_type i)
Definition Sparse.h:596
dim_vector dims() const
Definition Sparse.h:370
octave_idx_type & xcidx(octave_idx_type i)
Definition Sparse.h:602
octave_idx_type * xcidx()
Definition Sparse.h:601
octave_idx_type * xridx()
Definition Sparse.h:588
bool isempty() const
Definition Sparse.h:569
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:92
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.h:364
octave_idx_type ndims() const
Number of dimensions.
Definition dim-vector.h:263
#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:81
const octave_base_value const Array< octave_idx_type > & ra_idx
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T len
Definition xerbla.cc:61