ext/numo/narray/gen/tmpl_bit/aref.c in numo-narray-0.9.0.3 vs ext/numo/narray/gen/tmpl_bit/aref.c in numo-narray-0.9.0.4
- old
+ new
@@ -7,10 +7,11 @@
--- Returns the element at +dim0+, +dim1+, ... are Numeric indices
for each dimension, or returns a NArray View as a sliced subarray if
+dim0+, +dim1+, ... includes other than Numeric index, e.g., Range
or Array or true.
+ @example
a = Numo::DFloat.new(4,5).seq
=> Numo::DFloat#shape=[4,5]
[[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
@@ -36,16 +37,17 @@
[15, 16, 99, 18, 19]]
*/
static VALUE
<%=c_func%>(int argc, VALUE *argv, VALUE self)
{
- ssize_t pos;
+ int nd;
+ size_t pos;
char *ptr;
dtype x;
- pos = na_get_scalar_position(self, argc, argv, 1);
- if (pos == -1) {
- return na_aref_main(argc, argv, self, 0);
+ nd = na_get_result_dimension(self, argc, argv, 1, &pos);
+ if (nd) {
+ return na_aref_main(argc, argv, self, 0, nd);
} else {
ptr = na_get_pointer_for_read(self);
LOAD_BIT(ptr,pos,x);
return m_data_to_num(x);
}