annotate liboctave/util/interp-idx.h @ 19009:8d47ce2053f2 draft

Added safety checks to Array::xelem There's no reason to have a method which never checks invariants, ever. Added debugging checks to Array::xelem to help catch and debug out-of-bounds errors and reference overlap * configure.ac: Added configuration option for uniqueness-checking with xelem * jit-typeinfo.cc (octave_jit_paren_scalar): Call const Array::xelem rather than Array::xelem * Array-util.h, Array-util.cc (check_out_of_range): Extract common pattern to method (check_index): Methods to check index is in-bounds (compute_index): Added bool parameter check. does not check bounds when check is false and BOUNDS_CHECKING is off * Array.h, Array.cc (xelem): Use methods from Array-util.h to compute indices (is_unique): Check if this is the only reference to data * CmplxQR.cc, dbleQR.cc, fCmplxQR.cc, floatQR.cc (form): Move second assignment to after the call to xelem * lo-array-gripes.h, lo-array-gripes.cc (gripe_modifying_nonunique): Added error message for when non-const xelem is called on non-unique array
author David Spies <dnspies@gmail.com>
date Mon, 14 Jul 2014 13:07:59 -0600
parents 2e0613dadfee
children 3fb030666878
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2e0613dadfee All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff changeset
25 // 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
26 // 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
27 inline double
2e0613dadfee All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff changeset
28 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
29 {
2e0613dadfee All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff changeset
30 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
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 // 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
34 // 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
35 // (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
36 // 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
37 // 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
38 inline double
19009
8d47ce2053f2 Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents: 19006
diff changeset
39 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
40 {
19009
8d47ce2053f2 Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents: 19006
diff changeset
41 #if defined(BOUNDS_CHECKING)
8d47ce2053f2 Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents: 19006
diff changeset
42 check_index (row, col, dims);
8d47ce2053f2 Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents: 19006
diff changeset
43 #endif
8d47ce2053f2 Added safety checks to Array::xelem
David Spies <dnspies@gmail.com>
parents: 19006
diff changeset
44 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
45 }
2e0613dadfee All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff changeset
46
2e0613dadfee All calls to "find" use the same generic implementation (bug #42408, 42421)
David Spies <dnspies@gmail.com>
parents:
diff changeset
47 #endif