view 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
line wrap: on
line source

/*

Copyright (C) 2014 David Spies

This file is part of Octave.

Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING.  If not, see
<http://www.gnu.org/licenses/>.

*/
#if !defined (octave_interp_idx_h)
#define octave_interp_idx_h 1

// Simple method for converting between C++ octave_idx_type and
// Octave data-types (convert to double and add one).
inline double
to_interp_idx (octave_idx_type idx)
{
  return idx + 1.L;
}

// Simple method for taking a row-column pair together with the matrix
// dimensions and returning the corresponding index as an octave data-type
// (note that for large heights, there's a risk of losing precision.
// This method will not overflow or throw a bad alloc, it will simply
// choose the nearest possible double-value to the proper index).
inline double
to_interp_idx (octave_idx_type row, octave_idx_type col, const dim_vector& dims)
{
#if defined(BOUNDS_CHECKING)
  check_index (row, col, dims);
#endif
  return col * static_cast<double> (dims(0)) + row + 1;
}

#endif