diff options
-rw-r--r-- | functions.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/functions.c b/functions.c index 0b4f085..8770f40 100644 --- a/functions.c +++ b/functions.c @@ -495,8 +495,7 @@ fnMix(Array *right) commonsize *= commonshape->intdata[i]; } - /* TODO: think about types */ - Array *result = allocarray(right->arraydata[0]->type, right->rank + commonrank, size); + Array *result = allocarray(AtypeArray, right->rank + commonrank, size); for(i = 0; i < right->rank; i++) result->shape[i] = right->shape[i]; for(j = 0; j < commonshape->size; j++) @@ -508,16 +507,14 @@ fnMix(Array *right) Array *a = right->arraydata[i]; Array *fill = fillelement(a); if(a->rank == 0){ - memcpy( - result->rawdata + i * commonsize * datasizes[a->type], - a->rawdata, datasizes[a->type]); if(a->type == AtypeArray) - incref(a->arraydata[0]); + result->arraydata[i*commonsize] = a->arraydata[0]; + else + result->arraydata[i*commonsize] = a; + incref(result->arraydata[i*commonsize]); for(j = 1; j < commonsize; j++){ - memcpy(result->rawdata + (i * commonsize + j) * datasizes[a->type], - fill->rawdata, datasizes[a->type]); - if(fill->type == AtypeArray) - incref(fill->arraydata[0]); + result->arraydata[i*commonsize+j] = fill; + incref(fill); } }else{ for(j = 0; j < commonrank; j++) @@ -526,23 +523,21 @@ fnMix(Array *right) for(int k = 0; index[commonrank-1-k] == a->shape[a->rank-1-k]; k++){ int nfill = commonshape->intdata[commonrank-1-k] - a->shape[a->rank-1-k]; while(nfill--){ - memcpy(result->rawdata + (i * commonsize + offset) * datasizes[a->type], - fill->rawdata, datasizes[a->type]); - if(fill->type == AtypeArray) - incref(fill->arraydata[0]); + result->arraydata[i*commonsize+offset] = fill; + incref(fill); offset++; } index[commonrank-1-k] = 0; index[commonrank-2-k]++; } - if(offset < commonsize){ - memcpy( - result->rawdata + (i * commonsize + offset) * datasizes[a->type], - a->rawdata + j * datasizes[a->type], datasizes[a->type]); - if(a->type == AtypeArray) - incref(a->arraydata[j]); + if(offset < a->size){ + result->arraydata[i*commonsize+offset] = arrayitem(a, offset); offset++; index[commonrank-1]++; + }else if(offset < commonsize){ + result->arraydata[i*commonsize+offset] = fill; + incref(fill); + offset++; } } } |