26 #if defined (HAVE_CONFIG_H)
50 return (str.find (c) != std::string::npos
51 || str.find (std::toupper (c)) != std::string::npos);
61 if (
n > 1 && desc_comp (array (0), array (
n-1)))
71 #define INT_ARRAY_LOOKUP(TYPE) \
72 (table.is_ ## TYPE ## _type () && y.is_ ## TYPE ## _type ()) \
73 retval = do_numeric_lookup (table.TYPE ## _array_value (), \
74 y.TYPE ## _array_value (), \
75 left_inf, right_inf, \
76 match_idx, match_bool);
77 template <
typename ArrayT>
80 bool left_inf,
bool right_inf,
81 bool match_idx,
bool match_bool)
96 match.
xelem (i) = j != 0 && values(i) == array(j-1);
101 else if (match_idx || left_inf || right_inf)
110 ridx.
xelem (i) = (j != 0 && values(i) == array(j-1)) ? j : 0;
115 else if (left_inf && right_inf)
208 int nargin = args.length ();
210 if (nargin < 2 || nargin > 3)
216 warning (
"lookup: table is not a vector");
223 bool left_inf =
false;
224 bool right_inf =
false;
225 bool match_idx =
false;
226 bool match_bool =
false;
230 std::string opt = args(2).xstring_value (
"lookup: OPT must be a string");
235 if (opt.find_first_not_of (
"lrmb") != std::string::npos)
236 error (
"lookup: unrecognized option: %c",
237 opt[opt.find_first_not_of (
"lrmb")]);
240 if ((match_idx || match_bool) && (left_inf || right_inf))
241 error (
"lookup: m, b cannot be specified with l or r");
242 else if (match_idx && match_bool)
243 error (
"lookup: only one of m or b can be specified");
244 else if (str_case && (left_inf || right_inf))
245 error (
"lookup: l, r are not recognized for string lookups");
252 table = table.
abs ();
272 match_idx, match_bool);
277 match_idx, match_bool);
282 match_idx, match_bool);
304 match.
xelem (i) = j != 0 && str_y(i) == str_table(j-1);
315 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)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API octave_idx_type lookup(const T &value, sortmode mode=UNSORTED) const
Do a binary lookup in a sorted array.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
std::function< bool(typename ref_param< T >::type, typename ref_param< T >::type)> compare_fcn_type
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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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,...)
octave::idx_vector idx_vector
#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)