ext/gsl_native/randist.c in gsl-1.16.0.6 vs ext/gsl_native/randist.c in gsl-2.1.0
- old
+ new
@@ -1314,10 +1314,24 @@
ptr2 = NA_PTR_TYPE(ary, double*);
for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i]);
return ary;
}
#endif
+
+#ifdef HAVE_NMATRIX_H
+ if (NM_IsNMatrix(xx)) {
+ NM_DENSE_STORAGE *nm;
+ double *ptr1, *ptr2;
+ nm = NM_STORAGE_DENSE(xx);
+ n = NM_DENSE_COUNT(xx);
+ ptr1 = (double *) nm->elements;
+ ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
+ ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i]);
+ return ary;
+ }
+#endif
if (VECTOR_P(xx)) {
Data_Get_Struct(xx, gsl_vector, v);
vnew = gsl_vector_alloc(v->size);
for (i = 0; i < v->size; i++) {
gsl_vector_set(vnew, i, (*f)(gsl_vector_get(v, i)));
@@ -1382,10 +1396,24 @@
ptr2 = NA_PTR_TYPE(ary, double*);
for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i], a);
return ary;
}
#endif
+
+#ifdef HAVE_NMATRIX_H
+ if (NM_IsNMatrix(xx)) {
+ NM_DENSE_STORAGE *nm;
+ double *ptr1, *ptr2;
+ nm = NM_STORAGE_DENSE(xx);
+ n = NM_DENSE_COUNT(xx);
+ ptr1 = (double*) nm->elements;
+ ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
+ ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i], a);
+ return ary;
+ }
+#endif
if (VECTOR_P(xx)) {
Data_Get_Struct(xx, gsl_vector, v);
vnew = gsl_vector_alloc(v->size);
for (i = 0; i < v->size; i++) {
gsl_vector_set(vnew, i, (*f)(gsl_vector_get(v, i), a));
@@ -1446,9 +1474,23 @@
GetNArray(xx, na);
ptr1 = (double *) na->ptr;
n = na->total;
ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
ptr2 = NA_PTR_TYPE(ary, double*);
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i], a, b);
+ return ary;
+ }
+#endif
+
+#ifdef HAVE_NMATRIX_H
+ if (NM_IsNMatrix(xx)) {
+ NM_DENSE_STORAGE *nm;
+ double *ptr1, *ptr2;
+ nm = NM_STORAGE_DENSE(xx);
+ n = NM_DENSE_COUNT(xx);
+ ptr1 = (double *) nm->elements;
+ ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
+ ptr2 = (double*) NM_DENSE_ELEMENTS(ary);
for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i], a, b);
return ary;
}
#endif
if (VECTOR_P(xx)) {