Mercurial > octave-dspies
annotate liboctave/util/direction.h @ 19010:3fb030666878 draft default tip dspies
Added special-case logical-indexing function
* logical-index.h (New file) : Logical-indexing function. May be called on
octave_value types via call_bool_index
* nz-iterators.h : Add base-class nz_iterator for iterator types. Array has
template bool for whether to internally store row-col or compute on the fly
Add skip_ahead method which skips forward to the next nonzero after its
argument
Add flat_index for computing octave_idx_type index of current position (with
assertion failure in the case of overflow)
Move is_zero to separate file
* ov-base-diag.cc, ov-base-mat.cc, ov-base-sparse.cc, ov-perm.cc
(do_index_op): Add call to call_bool_index in logical-index.h
* Array.h : Move forward-declaration for array_iterator to separate header file
* dim-vector.cc (dim_max): Refers to idx-bounds.h (max_idx)
* array-iter-decl.h (New file): Header file for forward declaration of
array-iterator
* direction.h : Add constants fdirc and bdirc to avoid having to reconstruct
them
* dv-utils.h, dv-utils.cc (New files) :
Utility functions for querying and constructing dim-vectors
* idx-bounds.h (New file) :
Utility constants and functions for determining whether things will overflow
the maximum allowed bounds
* interp-idx.h (New function : to_flat_idx) : Converts row-col pair to linear
index of octave_idx_type
* is-zero.h (New file) : Function for determining whether an element is zero
* logical-index.tst : Add tests for correct return-value dimensions and large
sparse matrix behavior
author | David Spies <dnspies@gmail.com> |
---|---|
date | Fri, 25 Jul 2014 13:39:31 -0600 |
parents | 2e0613dadfee |
children |
rev | line source |
---|---|
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
1 /* |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
2 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
3 Copyright (C) 2014 David Spies |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
4 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
6 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
10 option) any later version. |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
11 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
15 for more details. |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
16 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
20 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
21 */ |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
22 #if !defined (octave_direction_h) |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
23 #define octave_direction_h 1 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
24 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
25 // Simple generic parameterized functions for stepping "forward" or "backward" |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
26 // FORWARD and BACKWARD are elements of the "direction enum |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
27 // |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
28 enum direction |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
29 { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
30 FORWARD = 1, BACKWARD = -1 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
31 }; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
32 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
33 // A struct with two overloaded functions: begin(lo, hi) and |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
34 // is_ended (i, lo, hi) where i is assumed to be stepping through the range |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
35 // [lo, hi) (inclusive, exclusive). begin() returns the initial value for i |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
36 // and is_ended (i, lo, hi) returns true if i has stepped past the end of the |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
37 // range. To increment i in the proper direction, one can simply say i += dir |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
38 // (dir is implicitly cast to an int either 1 or -1 for FORWARD and BACKWARD |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
39 // respectively). |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
40 // When lo = 0, one can instead use the 1- and 2- argument variants of begin |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
41 // and is_ended respectively |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
42 template<direction dir> |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
43 struct dir_handler |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
44 { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
45 octave_idx_type |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
46 begin (octave_idx_type size) const |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
47 { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
48 return begin (0, size); |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
49 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
50 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
51 octave_idx_type |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
52 begin (octave_idx_type lo, octave_idx_type hi) const |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
53 { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
54 switch (dir) { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
55 case FORWARD: return lo; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
56 case BACKWARD: return hi - 1; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
57 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
58 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
59 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
60 bool |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
61 is_ended (octave_idx_type i, octave_idx_type size) const |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
62 { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
63 return is_ended (i, 0, size); |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
64 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
65 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
66 bool |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
67 is_ended (octave_idx_type i, octave_idx_type lo, octave_idx_type hi) const |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
68 { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
69 switch (dir) { |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
70 case FORWARD: return i >= hi; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
71 case BACKWARD: return i < lo; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
72 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
73 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
74 }; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
75 |
19010
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
76 extern const dir_handler<FORWARD> fdirc; |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
77 extern const dir_handler<BACKWARD> bdirc; |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
78 |
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
79 #endif |