Mercurial > octave-dspies
annotate liboctave/util/interp-idx.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 | 8d47ce2053f2 |
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_interp_idx_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_interp_idx_h 1 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
24 |
19010
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
25 #include "idx-bounds.h" |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
26 #include "Array-util.h" |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
27 |
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
28 // Simple method for converting between C++ octave_idx_type and |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
29 // Octave data-types (convert to double and add one). |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
30 inline double |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
31 to_interp_idx (octave_idx_type idx) |
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 return idx + 1.L; |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
34 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
35 |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
36 // Simple method for taking a row-column pair together with the matrix |
19009
8d47ce2053f2
Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
37 // dimensions and returning the corresponding index as an octave data-type |
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
38 // (note that for large heights, there's a risk of losing precision. |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
39 // This method will not overflow or throw a bad alloc, it will simply |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
40 // choose the nearest possible double-value to the proper index). |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
41 inline double |
19009
8d47ce2053f2
Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
42 to_interp_idx (octave_idx_type row, octave_idx_type col, const dim_vector& dims) |
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
43 { |
19009
8d47ce2053f2
Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
44 #if defined(BOUNDS_CHECKING) |
8d47ce2053f2
Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
45 check_index (row, col, dims); |
8d47ce2053f2
Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
46 #endif |
8d47ce2053f2
Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents:
19006
diff
changeset
|
47 return col * static_cast<double> (dims(0)) + row + 1; |
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
48 } |
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
49 |
19010
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
50 //Converts a row-column pair to a "flat" linear index. |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
51 //Asserts that its result won't overflow octave_idx_type |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
52 inline octave_idx_type |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
53 to_flat_idx (octave_idx_type row, octave_idx_type col, const dim_vector& dims) |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
54 { |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
55 assert(!row_col_to_idx_overflows (row, col, dims(0))); |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
56 return compute_index (row, col, dims, false); |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
57 } |
3fb030666878
Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents:
19009
diff
changeset
|
58 |
19006
2e0613dadfee
All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff
changeset
|
59 #endif |