Navigation

Operators and Keywords

Function List:

C++ API

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:


Classes

struct  icmp_char_lt
struct  icmp_char_gt

Defines

#define INT_ARRAY_LOOKUP(TYPE)

Functions

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)
 DEFUN_DLD (lookup, args,,"-*- texinfo -*-\n\ @deftypefn {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 algorithm used by lookup is standard binary search, with optimizations\n\ to speed up the case of arrays containing pre-ordered portions (sampling).\n\ In particular, looking up a single entry is of logarithmic complexity\n\ (unless a conversion occurs due to non-numeric or unequal types).\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 shall be a string with letters indicating\n\ additional options.\n\ \n\ If 'm' is specified as option, @code{table(idx(i)) == val(i)} if @code{val(i)}\n\ occurs in table; otherwise, @code{idx(i)} is zero.\n\ If 'b' is specified, then @code{idx(i)} is a logical 1 or 0, indicating whether\n\ @code{val(i)} is contained in table or not.\n\ \n\ For numeric lookup, 'l' in @var{opts} indicates that\n\ the leftmost subinterval shall be extended to infinity (i.e., all indices\n\ at least 1), and 'r' indicates that the rightmost subinterval shall be\n\ extended to infinity (i.e., all indices at most n-1).\n\ \n\ For string lookup, 'i' indicates case-insensitive comparison.\n\ @end deftypefn")

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);


Function Documentation

DEFUN_DLD ( lookup  ,
args   
)

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]