26 #if defined (HAVE_CONFIG_H)
48 return (str.find (c) != std::string::npos
49 || str.find (std::toupper (c)) != std::string::npos);
59 if (
n > 1 && desc_comp (array (0), array (
n-1)))
69 #define INT_ARRAY_LOOKUP(TYPE) \
70 (table.is_ ## TYPE ## _type () && y.is_ ## TYPE ## _type ()) \
71 retval = do_numeric_lookup (table.TYPE ## _array_value (), \
72 y.TYPE ## _array_value (), \
73 left_inf, right_inf, \
74 match_idx, match_bool);
75 template <
typename ArrayT>
78 bool left_inf,
bool right_inf,
79 bool match_idx,
bool match_bool)
94 match.
xelem (i) = j != 0 && values(i) == array(j-1);
99 else if (match_idx || left_inf || right_inf)
108 ridx.
xelem (i) = (j != 0 && values(i) == array(j-1)) ? j : 0;
113 else if (left_inf && right_inf)
206 int nargin = args.length ();
208 if (nargin < 2 || nargin > 3)
214 warning (
"lookup: table is not a vector");
221 bool left_inf =
false;
222 bool right_inf =
false;
223 bool match_idx =
false;
224 bool match_bool =
false;
228 std::string opt = args(2).xstring_value (
"lookup: OPT must be a string");
233 if (opt.find_first_not_of (
"lrmb") != std::string::npos)
234 error (
"lookup: unrecognized option: %c",
235 opt[opt.find_first_not_of (
"lrmb")]);
238 if ((match_idx || match_bool) && (left_inf || right_inf))
239 error (
"lookup: m, b cannot be specified with l or r");
240 else if (match_idx && match_bool)
241 error (
"lookup: only one of m or b can be specified");
242 else if (str_case && (left_inf || right_inf))
243 error (
"lookup: l, r are not recognized for string lookups");
250 table = table.
abs ();
270 match_idx, match_bool);
275 match_idx, match_bool);
280 match_idx, match_bool);
302 match.
xelem (i) = j != 0 && str_y(i) == str_table(j-1);
313 ridx.
xelem (i) = (j != 0 && str_y(i) == str_table(j-1) ? j : 0);
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
N Dimensional Array with copy-on-write semantics.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type lookup(const T &value, sortmode mode=UNSORTED) const
Do a binary lookup in a sorted array.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Vector representing the dimensions (size) of an Array.
bool iscellstr(void) const
bool is_char_matrix(void) const
octave_idx_type rows(void) const
bool isnumeric(void) const
bool is_string(void) const
charNDArray char_array_value(bool frc_str_conv=false) const
octave_idx_type columns(void) const
octave_value abs(void) const
std::string string_value(bool force=false) const
NDArray array_value(bool frc_str_conv=false) const
bool is_single_type(void) const
FloatNDArray float_array_value(bool frc_str_conv=false) const
Array< std::string > cellstr_value(void) const
bool iscomplex(void) const
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
#define INT_ARRAY_LOOKUP(TYPE)
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 bool contains_char(const std::string &str, char c)
sortmode get_sort_mode(const Array< T > &array, typename octave_sort< T >::compare_fcn_type desc_comp=octave_sort< T >::descending_compare)
octave_value::octave_value(const Array< char > &chm, char type) return retval