Skip to content

Commit

Permalink
properly distinguish NArray from NVector
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Feb 15, 2018
1 parent 0fee53e commit b90f407
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/interfaces/ruby/swig_typemaps.i
Expand Up @@ -14,7 +14,7 @@
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) shogun::SGVector<SGTYPE> {
$1 = (
($input && TYPE($input) == T_ARRAY && RARRAY_LEN($input) > 0) ||
($input && NA_IsNArray($input) && NA_SHAPE0($input) > 0)
($input && NA_IsNArray($input) && NA_RANK($input) == 1 && NA_SHAPE0($input) > 0)
)? 1 : 0;
}

Expand All @@ -33,7 +33,7 @@
}
}
else {
if (NA_IsNArray($input)) {
if (NA_IsNArray($input) && NA_RANK($input) == 1) {

VALUE v = (*na_to_array_dl)($input);
len = RARRAY_LEN(v);
Expand Down Expand Up @@ -84,7 +84,7 @@ TYPEMAP_SGVECTOR(float64_t, NUM2DBL, rb_float_new)
{
$1 = (
($input && TYPE($input) == T_ARRAY && RARRAY_LEN($input) > 0 && TYPE(rb_ary_entry($input, 0)) == T_ARRAY) ||
($input && NA_IsNArray($input) && NA_SHAPE1($input) > 0 && NA_SHAPE0($input) > 0)
($input && NA_IsNArray($input) && NA_RANK($input) == 2 && NA_SHAPE1($input) > 0 && NA_SHAPE0($input) > 0)
) ? 1 : 0;
}

Expand All @@ -94,7 +94,7 @@ TYPEMAP_SGVECTOR(float64_t, NUM2DBL, rb_float_new)
VALUE vec;
VALUE v;

if (rb_obj_is_kind_of($input,rb_cArray) || NA_IsNArray($input)) {
if (rb_obj_is_kind_of($input,rb_cArray) || (NA_IsNArray($input) && NA_RANK($input) == 2)) {
if (NA_IsNArray($input)) {
v = (*na_to_array_dl)($input);
}
Expand Down

0 comments on commit b90f407

Please sign in to comment.