ext/numo/narray/ndloop.c in numo-narray-0.9.1.1 vs ext/numo/narray/ndloop.c in numo-narray-0.9.1.2

- old
+ new

@@ -508,11 +508,11 @@ */ static void ndloop_set_stepidx(na_md_loop_t *lp, int j, VALUE vna, int *dim_map, int rwflag) { size_t n, s; - int i, k; + int i, k, nd; stridx_t sdx; narray_t *na; LARG(lp,j).value = vna; LARG(lp,j).elmsz = nary_element_stride(vna); @@ -526,10 +526,11 @@ LARG(lp,j).ptr = na_get_pointer_for_read_write(vna); } else { rb_bug("invalid value for read-write flag"); } GetNArray(vna,na); + nd = LARG(lp,j).ndim; switch(NA_TYPE(na)) { case NARRAY_DATA_T: if (NA_DATA_PTR(na)==NULL && NA_SIZE(na)>0) { rb_bug("cannot read no-data NArray"); @@ -538,39 +539,41 @@ // through case NARRAY_FILEMAP_T: s = LARG(lp,j).elmsz; for (k=na->ndim; k--;) { n = na->shape[k]; - if (n > 1) { + if (n > 1 || nd > 0) { i = dim_map[k]; //printf("n=%d k=%d i=%d\n",n,k,i); LITER(lp,i,j).step = s; - LITER(lp,i,j).idx = NULL; + //LITER(lp,i,j).idx = NULL; } s *= n; + nd--; } LITER(lp,0,j).pos = 0; break; case NARRAY_VIEW_T: LITER(lp,0,j).pos = NA_VIEW_OFFSET(na); for (k=0; k<na->ndim; k++) { n = na->shape[k]; sdx = NA_VIEW_STRIDX(na)[k]; - if (n > 1) { + if (n > 1 || nd > 0) { i = dim_map[k]; if (SDX_IS_INDEX(sdx)) { LITER(lp,i,j).step = 0; LITER(lp,i,j).idx = SDX_GET_INDEX(sdx); } else { LITER(lp,i,j).step = SDX_GET_STRIDE(sdx); - LITER(lp,i,j).idx = NULL; + //LITER(lp,i,j).idx = NULL; } } else if (n==1) { if (SDX_IS_INDEX(sdx)) { LITER(lp,0,j).pos += SDX_GET_INDEX(sdx)[0]; } } + nd--; } break; default: rb_bug("invalid narray internal type"); } @@ -619,12 +622,12 @@ if (nf->ain[j].type==OVERWRITE) { lp->xargs[j].flag = flag = NDL_WRITE; } else { lp->xargs[j].flag = flag = NDL_READ; } - ndloop_set_stepidx(lp, j, v, dim_map, flag); LARG(lp,j).ndim = nf_dim; + ndloop_set_stepidx(lp, j, v, dim_map, flag); if (nf_dim > 0) { LARG(lp,j).shape = na->shape + (na->ndim - nf_dim); } } else if (TYPE(v)==T_ARRAY) { LARG(lp,j).value = v; @@ -785,12 +788,12 @@ v = nary_new(type, na_ndim, na_shape); flag = NDL_WRITE; } j = lp->nin + k; - ndloop_set_stepidx(lp, j, v, dim_map, flag); LARG(lp,j).ndim = nd = nf->aout[k].dim; + ndloop_set_stepidx(lp, j, v, dim_map, flag); if (nd > 0) { LARG(lp,j).shape = nf->aout[k].shape; } return v; @@ -979,10 +982,10 @@ for (i=ndim; i>0; ) { i--; if (LARG(lp,j).shape) { n = LARG(lp,j).shape[i]; } else { - printf("shape is NULL\n"); + //printf("shape is NULL\n"); n = lp->user.n[i]; } stride = sz * n; //printf("{j=%d,i=%d,ndim=%d,nd=%d,idx=%lx,step=%ld,n=%ld,sz=%ld,stride=%ld}\n",j,i,ndim,nd,(size_t)src_iter[i].idx,src_iter[i].step,n,sz,stride); if (src_iter[i].idx) {