Classes | Defines | Functions

lookup.cc File Reference

#include <cctype>
#include <functional>
#include <algorithm>
#include "dNDArray.h"
#include "CNDArray.h"
#include "Cell.h"
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
#include "ov.h"
Include dependency graph for lookup.cc:

Go to the source code of this file.

Classes

struct  icmp_char_gt
struct  icmp_char_lt

Defines

#define INT_ARRAY_LOOKUP(TYPE)

Functions

static bool contains_char (const std::string &str, char c)
 DEFUN_DLD (lookup, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{idx} =} lookup (@var{table}, @var{y})\n\ @deftypefnx {Loadable Function} {@var{idx} =} lookup (@var{table}, @var{y}, @var{opt})\n\ Lookup values in a sorted table. Usually used as a prelude to\n\ interpolation.\n\ \n\ If table is increasing and @code{idx = lookup (table, y)}, then\n\ @code{table(idx(i)) <= y(i) < table(idx(i+1))} for all @code{y(i)}\n\ within the table. If @code{y(i) < table(1)} then\n\ @code{idx(i)} is 0. If @code{y(i) >= table(end)} or @code{isnan (y(i))} then\n\ @code{idx(i)} is @code{n}.\n\ \n\ If the table is decreasing, then the tests are reversed.\n\ For non-strictly monotonic tables, empty intervals are always skipped.\n\ The result is undefined if @var{table} is not monotonic, or if\n\ @var{table} contains a NaN.\n\ \n\ The complexity of the lookup is O(M*log(N)) where N is the size of\n\ @var{table} and M is the size of @var{y}. In the special case when @var{y}\n\ is also sorted, the complexity is O(min(M*log(N),M+N)).\n\ \n\ @var{table} and @var{y} can also be cell arrays of strings\n\ (or @var{y} can be a single string). In this case, string lookup\n\ is performed using lexicographical comparison.\n\ \n\ If @var{opts} is specified, it must be a string with letters indicating\n\ additional options.\n\ \n\ @table @code\n\ @item m\n\ @code{table(idx(i)) == val(i)} if @code{val(i)}\n\ occurs in table; otherwise, @code{idx(i)} is zero.\n\ \n\ @item b\n\ @code{idx(i)} is a logical 1 or 0, indicating whether\n\ @code{val(i)} is contained in table or not.\n\ \n\ @item l\n\ For numeric lookups\n\ the leftmost subinterval shall be extended to infinity (i.e., all indices\n\ at least 1)\n\ \n\ @item r\n\ For numeric lookups\n\ the rightmost subinterval shall be extended to infinity (i.e., all indices\n\ at most n-1).\n\ @end table\n\ @end deftypefn")
template<class ArrayT >
static octave_value do_numeric_lookup (const ArrayT &array, const ArrayT &values, bool left_inf, bool right_inf, bool match_idx, bool match_bool)
template<class T >
sortmode get_sort_mode (const Array< T > &array, typename octave_sort< T >::compare_fcn_type desc_comp=octave_sort< T >::descending_compare)

Define Documentation

#define INT_ARRAY_LOOKUP (   TYPE  ) 
Value:
(table.is_ ## TYPE ## _type () && y.is_ ## TYPE ## _type ()) \
    retval = do_numeric_lookup (table.TYPE ## _array_value (), \
                                y.TYPE ## _array_value (), \
                                left_inf, right_inf, \
                                match_idx, match_bool);

Definition at line 103 of file lookup.cc.

Referenced by DEFUN_DLD().


Function Documentation

static bool contains_char ( const std::string &  str,
char  c 
) [static]

Definition at line 45 of file lookup.cc.

Referenced by DEFUN_DLD().

DEFUN_DLD ( lookup  ,
args   
)
template<class ArrayT >
static octave_value do_numeric_lookup ( const ArrayT &  array,
const ArrayT &  values,
bool  left_inf,
bool  right_inf,
bool  match_idx,
bool  match_bool 
) [static]

Definition at line 111 of file lookup.cc.

References Array< T >::dims(), match(), max(), min(), octave_value::numel(), and Array< T >::xelem().

Referenced by DEFUN_DLD().

template<class T >
sortmode get_sort_mode ( const Array< T > &  array,
typename octave_sort< T >::compare_fcn_type  desc_comp = octave_sort<T>::descending_compare 
) [inline]

Definition at line 88 of file lookup.cc.

References Array< T >::numel().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines