comparison src/DLD-FUNCTIONS/lookup.cc @ 7919:9d080df0c843

new NDArray constructor for ArrayN<octave_idx_type>
author David Bateman <dbateman@free.fr>
date Mon, 30 Jun 2008 15:51:31 +0200
parents 82be108cc558
children 4976f66d469b
comparison
equal deleted inserted replaced
7918:78eef61f75d5 7919:9d080df0c843
45 bool 45 bool
46 contains_char (const std::string& str, char c) 46 contains_char (const std::string& str, char c)
47 { 47 {
48 return (str.find (c) != std::string::npos 48 return (str.find (c) != std::string::npos
49 || str.find (std::toupper (c)) != std::string::npos); 49 || str.find (std::toupper (c)) != std::string::npos);
50 }
51
52 // FIXME -- remove these one once octave_value supports octave_idx_type.
53 static octave_value&
54 assign (octave_value& ov, octave_idx_type idx)
55 {
56 double tmp = idx;
57 ov = tmp;
58 return ov;
59 }
60
61 static octave_value&
62 assign (octave_value& ov, const ArrayN<octave_idx_type>& ida)
63 {
64 NDArray tmp (ida.dims ());
65 for (int i = 0; i < ida.numel (); i++)
66 tmp(i) = ida(i);
67 ov = tmp;
68 return ov;
69 } 50 }
70 51
71 // normal ascending comparator 52 // normal ascending comparator
72 static bool 53 static bool
73 ov_str_less (const octave_value& a, const octave_value& b) 54 ov_str_less (const octave_value& a, const octave_value& b)
237 seq_lookup (table.data (), offset, size, 218 seq_lookup (table.data (), offset, size,
238 y.data (), y.length (), idx.fortran_vec (), 219 y.data (), y.length (), idx.fortran_vec (),
239 std::less<double> ()); 220 std::less<double> ());
240 } 221 }
241 222
242 //retval(0) = idx; 223 retval(0) = NDArray (idx);
243 assign (retval(0), idx);
244 } 224 }
245 else if (str_case) 225 else if (str_case)
246 { 226 {
247 Cell table = argtable.cell_value (); 227 Cell table = argtable.cell_value ();
248 228
286 266
287 for (int i = 0; i < y.numel (); i++) 267 for (int i = 0; i < y.numel (); i++)
288 idx(i) = bin_lookup (table.data (), table.length (), y(i), 268 idx(i) = bin_lookup (table.data (), table.length (), y(i),
289 std::ptr_fun (ov_str_comp)); 269 std::ptr_fun (ov_str_comp));
290 270
291 //retval(0) = idx; 271 retval(0) = NDArray (idx);
292 assign (retval(0), idx);
293 } 272 }
294 else 273 else
295 { 274 {
296 octave_idx_type idx; 275 octave_idx_type idx;
297 276
298 idx = bin_lookup (table.data (), table.length (), argy, 277 idx = bin_lookup (table.data (), table.length (), argy,
299 std::ptr_fun (ov_str_comp)); 278 std::ptr_fun (ov_str_comp));
300 279
301 //retval(0) = idx; 280 retval(0) = static_cast<double> (idx);
302 assign (retval(0), idx);
303 } 281 }
304 } 282 }
305 else 283 else
306 error("lookup: table is not a cell array of strings."); 284 error("lookup: table is not a cell array of strings.");
307 } 285 }