Mercurial > octave-dspies
comparison liboctave/array/PermMatrix.h @ 19006:2e0613dadfee draft
All calls to "find" use the same generic implementation (bug #42408, 42421)
* find.cc: Rewrite.
Move generic "find" logic to find.h
(Ffind) : Changed calls to find_nonzero_elem_idx to find_templated
Added unit test for bug #42421
* Array.cc (and .h) (Array::find): Deleted function. Replaced with find::find(Array)
from find.h
* Array.h: Added typedef for array_iterator (in nz-iterators.h) as
Array::iter_type
* DiagArray2.h: Added typedef for diag_iterator (in nz-iterators.h) as
DiagArray2::iter_type
* PermMatrix.h: Added typedef for perm_iterator (in nz-iterators.h) as
PermMatrix::iter_type
Also added typedef for bool as PermMatrix::element_type
(not octave_idx_type)
Added an nnz() function (which is an alias for perm_length) and a
perm_elem(i) function for retrieving the ith element of the permutation
* Sparse.h: Added typedef for sparse_iterator (in nz-iterators.h) as
Sparse::iter_type
Added a short comment documenting the the argument to the numel
function
* idx-vector.cc (idx_vector::idx_mask_rep::as_array): Changed Array.find to
find::find(Array) (in find.h)
* (new file) find.h
* (new file) interp-idx.h: Simple methods for converting between interpreter
index type and internal octave_idx_type/row-col pair
* (new file) min-with-nnz.h: Fast methods for taking an arbitrary matrix M and
an octave_idx_type n and finding min(M.nnz(), n)
* (new file) nz-iterators.h: Iterators for traversing (in column-major order)
the nonzero elements of any array or matrix backwards or forwards
* (new file) direction.h: Generic methods for simplifying code has to deal with
a "backwards or forwards" template argument
* build-sparse-tests.sh: Removed 5-return-value calls to "find" in unit-tests;
Admittedly this commit breaks this "feature" which was undocumented and only
partially supported to begin with (ie never worked for full matrices,
permutation matrices, or diagonal matrices)
author | David Spies <dnspies@gmail.com> |
---|---|
date | Tue, 17 Jun 2014 16:41:11 -0600 |
parents | aa9ca67f09fb |
children |
comparison
equal
deleted
inserted
replaced
19003:d00f6b09258f | 19006:2e0613dadfee |
---|---|
24 #define octave_PermMatrix_h 1 | 24 #define octave_PermMatrix_h 1 |
25 | 25 |
26 #include "Array.h" | 26 #include "Array.h" |
27 #include "mx-defs.h" | 27 #include "mx-defs.h" |
28 | 28 |
29 //Forward declaration for perm_iterator, | |
30 //the nonzero-iterator type for PermMatrix (in nz_iterator.h) | |
31 class perm_iterator; | |
32 | |
29 // Array<T> is inherited privately so that some methods, like index, don't | 33 // Array<T> is inherited privately so that some methods, like index, don't |
30 // produce unexpected results. | 34 // produce unexpected results. |
31 | 35 |
32 class OCTAVE_API PermMatrix : protected Array<octave_idx_type> | 36 class OCTAVE_API PermMatrix : protected Array<octave_idx_type> |
33 { | 37 { |
34 public: | 38 public: |
39 | |
40 typedef bool element_type; | |
41 typedef perm_iterator iter_type; | |
35 | 42 |
36 PermMatrix (void) : Array<octave_idx_type> () { } | 43 PermMatrix (void) : Array<octave_idx_type> () { } |
37 | 44 |
38 PermMatrix (octave_idx_type n); | 45 PermMatrix (octave_idx_type n); |
39 | 46 |
61 // FIXME: a dangerous ambiguity? | 68 // FIXME: a dangerous ambiguity? |
62 octave_idx_type length (void) const | 69 octave_idx_type length (void) const |
63 { return perm_length (); } | 70 { return perm_length (); } |
64 octave_idx_type nelem (void) const { return dim1 () * dim2 (); } | 71 octave_idx_type nelem (void) const { return dim1 () * dim2 (); } |
65 octave_idx_type numel (void) const { return nelem (); } | 72 octave_idx_type numel (void) const { return nelem (); } |
73 octave_idx_type nnz (void) const { return perm_length (); } | |
66 | 74 |
67 size_t byte_size (void) const | 75 size_t byte_size (void) const |
68 { return Array<octave_idx_type>::byte_size (); } | 76 { return Array<octave_idx_type>::byte_size (); } |
69 | 77 |
70 dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); } | 78 dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); } |
102 PermMatrix power (octave_idx_type n) const; | 110 PermMatrix power (octave_idx_type n) const; |
103 | 111 |
104 bool is_col_perm (void) const { return true; } | 112 bool is_col_perm (void) const { return true; } |
105 bool is_row_perm (void) const { return false; } | 113 bool is_row_perm (void) const { return false; } |
106 | 114 |
115 octave_idx_type perm_elem(octave_idx_type i) const | |
116 { return Array<octave_idx_type>::elem (i); } | |
117 | |
107 void print_info (std::ostream& os, const std::string& prefix) const | 118 void print_info (std::ostream& os, const std::string& prefix) const |
108 { Array<octave_idx_type>::print_info (os, prefix); } | 119 { Array<octave_idx_type>::print_info (os, prefix); } |
109 | 120 |
110 static PermMatrix eye (octave_idx_type n); | 121 static PermMatrix eye (octave_idx_type n); |
111 | 122 |