numo-narray-alt 0.10.8 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf8873637141f0256dbedbc1ada30646faef0f119af6a5a70e69676581bf610f
4
- data.tar.gz: 7c9f38d861bcfa39ad544265ac205b33552c4139e5740524165d7cc057f0ccf2
3
+ metadata.gz: 9b2e2bc7cc99b7ef2b868b588360ff66299a6570b4d6ea98c45bbb357eed661b
4
+ data.tar.gz: '0887ab3061ad5add393ecd99921ca88e3a06545c9617ffc9686550cb87b3e843'
5
5
  SHA512:
6
- metadata.gz: afe8bb36cbf569f121565d952b4a0f7120f65b3f9b566d438747f17777cb2e28b66b268e4400866a69fd8009b7215c7f2501fef66ebaa5af32c2cf49060363d5
7
- data.tar.gz: af4a5b9071ae98832f48e038134a9d658531bada286fefc312f9d08c3eba9752b1937eaeba6643e89d82295fa31222e705de76deb58be5841e24c9044ef685e5
6
+ metadata.gz: '09f47d21922f7e24e7915222eb9ddacadf4392156e53a15aee05d4f2fc6ebdafce244c3624de375b10411768d7f1a38de7d081504ef0fe21b6b1b82156ef9410'
7
+ data.tar.gz: 4cc3900b5631971fc76195eee5ecf66a6c1647a604d19997b0bcece1d1341f9245ace1c405c3f5e9dbc493389f456c4c9c817ea145a1c3a47f2180edea52ae36
data/README.md CHANGED
@@ -24,6 +24,15 @@ This project is in no way intended to adversely affect the development of the or
24
24
  $ gem install numo-narray-alt
25
25
  ```
26
26
 
27
+ ### Build options
28
+
29
+ By default, the floating-point classes (`Numo::SFloat` / `Numo::DFloat`) use SIMD instructions
30
+ (SSE2 / AVX / NEON) when the target CPU supports them. To build without SIMD, pass `--with-no-simd`:
31
+
32
+ ```shell
33
+ $ gem install numo-narray-alt -- --with-no-simd
34
+ ```
35
+
27
36
  ## Usage
28
37
 
29
38
  The usage is exactly the same as Numo::NArray.
@@ -8,7 +8,6 @@
8
8
  #include "numo/narray.h"
9
9
  #include "numo/template.h"
10
10
 
11
- static ID id_copy;
12
11
  static ID id_mulsum;
13
12
  static ID id_store;
14
13
  static ID id_swap_byte;
@@ -106,11 +105,7 @@ static VALUE nary_swap_byte(VALUE self) {
106
105
  ndfunc_arg_out_t aout[1] = { { INT2FIX(0), 0 } };
107
106
  ndfunc_t ndf = { iter_swap_byte, FULL_LOOP | NDF_ACCEPT_BYTESWAP, 1, 1, ain, aout };
108
107
 
109
- if (RTEST(rb_obj_is_kind_of(self, numo_cBit))) {
110
- v = TEST_INPLACE(self) ? self : rb_funcall(self, id_copy, 0);
111
- } else {
112
- v = na_ndloop(&ndf, 1, self);
113
- }
108
+ v = na_ndloop(&ndf, 1, self);
114
109
  if (self != v) {
115
110
  na_copy_flags(self, v);
116
111
  }
@@ -330,17 +325,9 @@ static void na_check_reshape(int argc, VALUE* argv, VALUE self, size_t* shape) {
330
325
  /* get shape from argument */
331
326
  for (i = 0; i < argc; ++i) {
332
327
  switch (TYPE(argv[i])) {
333
- case T_FIXNUM: {
334
- ssize_t x = NUM2SSIZET(argv[i]);
335
- if (x < 0) {
336
- rb_raise(rb_eArgError, "size must be non-negative");
337
- }
338
- if (x != 0 && total > SIZE_MAX / (size_t)x) {
339
- rb_raise(rb_eArgError, "total size is too large");
340
- }
341
- total *= shape[i] = (size_t)x;
328
+ case T_FIXNUM:
329
+ total *= shape[i] = NUM2INT(argv[i]);
342
330
  break;
343
- }
344
331
  case T_NIL:
345
332
  case T_TRUE:
346
333
  if (unfixed >= 0) {
@@ -354,9 +341,6 @@ static void na_check_reshape(int argc, VALUE* argv, VALUE self, size_t* shape) {
354
341
  }
355
342
 
356
343
  if (unfixed >= 0) {
357
- if (total == 0) {
358
- rb_raise(rb_eArgError, "cannot determine unfixed dimension when total size is zero");
359
- }
360
344
  if (NA_SIZE(na) % total != 0) {
361
345
  rb_raise(rb_eArgError, "Total size size must be divisor");
362
346
  }
@@ -364,10 +348,6 @@ static void na_check_reshape(int argc, VALUE* argv, VALUE self, size_t* shape) {
364
348
  } else if (total != NA_SIZE(na)) {
365
349
  rb_raise(rb_eArgError, "Total size must be same");
366
350
  }
367
-
368
- if (argc > NA_MAX_DIMENSION) {
369
- rb_raise(nary_eDimensionError, "ndim=%d is too many", argc);
370
- }
371
351
  }
372
352
 
373
353
  /*
@@ -385,15 +365,11 @@ static VALUE na_reshape_bang(int argc, VALUE* argv, VALUE self) {
385
365
  ssize_t stride;
386
366
  stridx_t* stridx;
387
367
  int i;
388
- VALUE tmp;
389
368
 
390
- if (OBJ_FROZEN(self)) {
391
- rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
392
- }
393
369
  if (na_check_contiguous(self) == Qfalse) {
394
370
  rb_raise(rb_eStandardError, "cannot change shape of non-contiguous NArray");
395
371
  }
396
- shape = RB_ALLOCV_N(size_t, tmp, argc);
372
+ shape = ALLOCA_N(size_t, argc);
397
373
  na_check_reshape(argc, argv, self, shape);
398
374
 
399
375
  GetNArray(self, na);
@@ -404,11 +380,7 @@ static VALUE na_reshape_bang(int argc, VALUE* argv, VALUE self) {
404
380
  } else {
405
381
  stridx = na2->stridx;
406
382
  }
407
- if (na->ndim == 0) {
408
- stride = nary_element_stride(self);
409
- } else {
410
- stride = SDX_GET_STRIDE(na2->stridx[na->ndim - 1]);
411
- }
383
+ stride = SDX_GET_STRIDE(na2->stridx[na->ndim - 1]);
412
384
  for (i = argc; i--;) {
413
385
  SDX_SET_STRIDE(stridx[i], stride);
414
386
  stride *= shape[i];
@@ -419,7 +391,6 @@ static VALUE na_reshape_bang(int argc, VALUE* argv, VALUE self) {
419
391
  }
420
392
  }
421
393
  na_setup_shape(na, argc, shape);
422
- RB_ALLOCV_END(tmp);
423
394
  return self;
424
395
  }
425
396
 
@@ -434,15 +405,14 @@ static VALUE na_reshape_bang(int argc, VALUE* argv, VALUE self) {
434
405
  static VALUE na_reshape(int argc, VALUE* argv, VALUE self) {
435
406
  size_t* shape;
436
407
  narray_t* na;
437
- VALUE copy, tmp;
408
+ VALUE copy;
438
409
 
439
- shape = RB_ALLOCV_N(size_t, tmp, argc);
410
+ shape = ALLOCA_N(size_t, argc);
440
411
  na_check_reshape(argc, argv, self, shape);
441
412
 
442
413
  copy = rb_funcall(self, rb_intern("dup"), 0);
443
414
  GetNArray(copy, na);
444
415
  na_setup_shape(na, argc, shape);
445
- RB_ALLOCV_END(tmp);
446
416
  return copy;
447
417
  }
448
418
 
@@ -524,9 +494,6 @@ na_flatten_dim(VALUE self, int sd) {
524
494
  // set index
525
495
  idx2 = ALLOC_N(size_t, (shape[sd] == 0) ? 1 : shape[sd]);
526
496
  SDX_SET_INDEX(na2->stridx[sd], idx2);
527
- if (shape[sd] == 0) {
528
- return view;
529
- }
530
497
  // init for md-loop
531
498
  fd = nd - sd;
532
499
  c = ALLOCA_N(size_t, fd);
@@ -987,7 +954,6 @@ void Init_nary_data(void) {
987
954
 
988
955
  // rb_define_method(cNArray, "dot", numo_na_dot, 1);
989
956
 
990
- id_copy = rb_intern("copy");
991
957
  id_mulsum = rb_intern("mulsum");
992
958
  id_store = rb_intern("store");
993
959
  id_swap_byte = rb_intern("swap_byte");
@@ -66,6 +66,8 @@ have_func('RTYPEDDATA_GET_DATA')
66
66
 
67
67
  have_var('rb_cComplex')
68
68
 
69
+ $defs << '-DNUMO_NO_SIMD' if with_config('no-simd', false)
70
+
69
71
  $objs = srcs.collect { |i| "#{i}.o" }
70
72
 
71
73
  create_header d('numo/extconf.h')
@@ -126,7 +126,7 @@ static void na_parse_narray_index(VALUE a, int orig_dim, ssize_t size, na_index_
126
126
  GetNArray(idx, nidx);
127
127
  n = NA_SIZE(nidx);
128
128
  q->idx = ALLOC_N(size_t, n);
129
- if (nidx->type != NARRAY_DATA_T) {
129
+ if (na->type != NARRAY_DATA_T) {
130
130
  rb_bug("NArray#where returned wrong type of NArray");
131
131
  }
132
132
  if (rb_obj_class(idx) == numo_cInt32) {
@@ -183,13 +183,7 @@ na_parse_range(VALUE range, ssize_t step, int orig_dim, ssize_t size, na_index_a
183
183
 
184
184
  rb_arithmetic_sequence_components_t x;
185
185
  rb_arithmetic_sequence_extract(range, &x);
186
- if (!RB_INTEGER_TYPE_P(x.step)) {
187
- rb_raise(rb_eArgError, "step must be an Integer");
188
- }
189
186
  step = NUM2SSIZET(x.step);
190
- if (step == 0) {
191
- rb_raise(rb_eArgError, "step must not be zero");
192
- }
193
187
 
194
188
  beg = beg_orig = NUM2SSIZET(x.begin);
195
189
  if (beg < 0) {
@@ -439,9 +433,7 @@ static size_t na_index_parse_args(VALUE args, narray_t* na, na_index_arg_t* q, i
439
433
  }
440
434
  // new dimension
441
435
  else if (v == sym_new) {
442
- // Past the last dimension, which is how the aref functions below tell
443
- // a new axis from a real one.
444
- na_index_parse_each(v, 1, na->ndim, &q[j]);
436
+ na_index_parse_each(v, 1, k, &q[j]);
445
437
  j++;
446
438
  }
447
439
  // other dimension
@@ -467,25 +459,6 @@ static void na_get_strides_nadata(const narray_data_t* na, ssize_t* strides, ssi
467
459
  }
468
460
  }
469
461
 
470
- // A new axis holds one element, so any stride addresses it. Give it the size of
471
- // the block below it, to keep the chain na_check_ladder() walks: a break there
472
- // costs contiguous?, and na_flatten_dim() takes the last dimension's stride as
473
- // the flat one on the strength of that same chain.
474
- static void na_index_set_newaxis_strides(
475
- narray_view_t* na2, const int* newaxis, int n_newaxes, int ndim_new
476
- ) {
477
- int i, j;
478
-
479
- for (i = n_newaxes - 1; i >= 0; i--) {
480
- j = newaxis[i];
481
- if (j + 1 < ndim_new && SDX_IS_STRIDE(na2->stridx[j + 1])) {
482
- SDX_SET_STRIDE(
483
- na2->stridx[j], SDX_GET_STRIDE(na2->stridx[j + 1]) * (ssize_t)na2->base.shape[j + 1]
484
- );
485
- }
486
- }
487
- }
488
-
489
462
  static void na_index_aref_nadata(
490
463
  narray_data_t* na1, narray_view_t* na2, na_index_arg_t* q, ssize_t elmsz, int ndim,
491
464
  int keep_dim
@@ -496,26 +469,19 @@ static void na_index_aref_nadata(
496
469
  ssize_t* strides_na1;
497
470
  size_t* index;
498
471
  ssize_t beg, step;
499
- int* newaxis;
500
- int n_newaxes = 0;
501
472
  VALUE m;
502
473
 
503
- newaxis = ALLOCA_N(int, ndim);
504
474
  strides_na1 = ALLOCA_N(ssize_t, na1->base.ndim);
505
475
  na_get_strides_nadata(na1, strides_na1, elmsz);
506
476
 
507
477
  for (i = j = 0; i < ndim; i++) {
508
- const int qi_orig_dim = q[i].orig_dim;
509
- stride1 = 0;
510
- if (qi_orig_dim < na1->base.ndim) {
511
- stride1 = strides_na1[qi_orig_dim];
478
+ stride1 = strides_na1[q[i].orig_dim];
512
479
 
513
- // numeric index -- trim dimension
514
- if (!keep_dim && q[i].n == 1 && q[i].step == 0) {
515
- beg = q[i].beg;
516
- na2->offset += stride1 * beg;
517
- continue;
518
- }
480
+ // numeric index -- trim dimension
481
+ if (!keep_dim && q[i].n == 1 && q[i].step == 0) {
482
+ beg = q[i].beg;
483
+ na2->offset += stride1 * beg;
484
+ continue;
519
485
  }
520
486
 
521
487
  na2->base.shape[j] = size = q[i].n;
@@ -525,12 +491,8 @@ static void na_index_aref_nadata(
525
491
  na2->base.reduce = rb_funcall(m, '|', 1, na2->base.reduce);
526
492
  }
527
493
 
528
- if (qi_orig_dim >= na1->base.ndim) {
529
- // new dimension
530
- newaxis[n_newaxes++] = j;
531
- SDX_SET_STRIDE(na2->stridx[j], elmsz);
532
- } else if (q[i].idx != NULL) {
533
- // array index
494
+ // array index
495
+ if (q[i].idx != NULL) {
534
496
  index = q[i].idx;
535
497
  SDX_SET_INDEX(na2->stridx[j], index);
536
498
  q[i].idx = NULL;
@@ -546,7 +508,6 @@ static void na_index_aref_nadata(
546
508
  j++;
547
509
  total *= size;
548
510
  }
549
- na_index_set_newaxis_strides(na2, newaxis, n_newaxes, j);
550
511
  na2->base.size = total;
551
512
  }
552
513
 
@@ -556,10 +517,6 @@ static void na_index_aref_naview(
556
517
  ) {
557
518
  int i, j;
558
519
  ssize_t total = 1;
559
- int* newaxis;
560
- int n_newaxes = 0;
561
-
562
- newaxis = ALLOCA_N(int, ndim);
563
520
 
564
521
  for (i = j = 0; i < ndim; i++) {
565
522
  stridx_t sdx1;
@@ -590,7 +547,6 @@ static void na_index_aref_naview(
590
547
 
591
548
  if (qi_orig_dim >= na1->base.ndim) {
592
549
  // new dimension
593
- newaxis[n_newaxes++] = j;
594
550
  SDX_SET_STRIDE(na2->stridx[j], elmsz);
595
551
  } else if (q[i].idx != NULL && SDX_IS_INDEX(sdx1)) {
596
552
  // index <- index
@@ -649,7 +605,6 @@ static void na_index_aref_naview(
649
605
  j++;
650
606
  total *= size;
651
607
  }
652
- na_index_set_newaxis_strides(na2, newaxis, n_newaxes, j);
653
608
  na2->base.size = total;
654
609
  }
655
610
 
@@ -870,10 +825,7 @@ int na_get_result_dimension(
870
825
  }
871
826
 
872
827
  if (j != argc) {
873
- int nd = check_index_count(argc, na->ndim, count_new, count_rest);
874
- if (nd != 0) {
875
- return nd;
876
- }
828
+ return check_index_count(argc, na->ndim, count_new, count_rest);
877
829
  }
878
830
 
879
831
  switch (na->type) {
@@ -275,18 +275,7 @@ void na_array_to_internal_shape(VALUE self, VALUE ary, size_t* shape) {
275
275
  }
276
276
  }
277
277
 
278
- static void na_check_ndim(int ndim) {
279
- if (ndim < 0) {
280
- rb_raise(nary_eDimensionError, "ndim=%d is negative", ndim);
281
- }
282
- if (ndim > NA_MAX_DIMENSION) {
283
- rb_raise(nary_eDimensionError, "ndim=%d is too many", ndim);
284
- }
285
- }
286
-
287
278
  void na_alloc_shape(narray_t* na, int ndim) {
288
- na_check_ndim(ndim);
289
-
290
279
  na->ndim = ndim;
291
280
  na->size = 0;
292
281
  if (na->shape != NULL && na->shape != &(na->size)) {
@@ -299,6 +288,12 @@ void na_alloc_shape(narray_t* na, int ndim) {
299
288
  na->shape = &(na->size);
300
289
  break;
301
290
  default:
291
+ if (ndim < 0) {
292
+ rb_raise(nary_eDimensionError, "ndim=%d is negative", ndim);
293
+ }
294
+ if (ndim > NA_MAX_DIMENSION) {
295
+ rb_raise(nary_eDimensionError, "ndim=%d is too many", ndim);
296
+ }
302
297
  na->shape = ALLOC_N(size_t, ndim);
303
298
  }
304
299
  }
@@ -307,23 +302,19 @@ void na_setup_shape(narray_t* na, int ndim, size_t* shape) {
307
302
  int i;
308
303
  size_t size;
309
304
 
310
- na_check_ndim(ndim);
311
-
312
- for (i = 0, size = 1; i < ndim; i++) {
313
- if (shape[i] != 0 && size > SIZE_MAX / shape[i]) {
314
- rb_raise(rb_eRangeError, "total number of elements is too large");
315
- }
316
- size *= shape[i];
317
- }
318
-
319
305
  na_alloc_shape(na, ndim);
320
306
 
321
- if (ndim > 1) {
322
- for (i = 0; i < ndim; i++) {
307
+ if (ndim == 0) {
308
+ na->size = 1;
309
+ } else if (ndim == 1) {
310
+ na->size = shape[0];
311
+ } else {
312
+ for (i = 0, size = 1; i < ndim; i++) {
323
313
  na->shape[i] = shape[i];
314
+ size *= shape[i];
324
315
  }
316
+ na->size = size;
325
317
  }
326
- na->size = (ndim == 0) ? 1 : size;
327
318
  }
328
319
 
329
320
  static void na_setup(VALUE self, int ndim, size_t* shape) {
@@ -885,9 +876,6 @@ na_check_ladder(VALUE self, int start_dim) {
885
876
  narray_t* na;
886
877
  GetNArray(self, na);
887
878
 
888
- if (na->ndim == 0) {
889
- return Qtrue;
890
- }
891
879
  if (start_dim < -na->ndim || start_dim >= na->ndim) {
892
880
  rb_bug("start_dim (%d) out of range", start_dim);
893
881
  }
@@ -932,9 +920,6 @@ na_check_contiguous(VALUE self) {
932
920
  if (NA_VIEW_STRIDX(na) == 0) {
933
921
  return Qtrue;
934
922
  }
935
- if (NA_NDIM(na) == 0) {
936
- return Qtrue;
937
- }
938
923
  if (na_check_ladder(self, 0) == Qtrue) {
939
924
  elmsz = nary_element_stride(self);
940
925
  if (elmsz == NA_STRIDE_AT(na, NA_NDIM(na) - 1)) {
@@ -1058,7 +1043,6 @@ static VALUE na_expand_dims(VALUE self, VALUE vdim) {
1058
1043
 
1059
1044
  GetNArray(self, na);
1060
1045
  nd = na->ndim;
1061
- na_check_ndim(nd + 1);
1062
1046
 
1063
1047
  dim = NUM2INT(vdim);
1064
1048
  if (dim < -nd - 1 || dim > nd) {
@@ -1288,11 +1272,7 @@ static VALUE nary_s_from_binary(int argc, VALUE* argv, VALUE type) {
1288
1272
  rb_raise(rb_eArgError, "second argument must be size or shape");
1289
1273
  }
1290
1274
  if (FIXNUM_P(velmsz)) {
1291
- size_t elmsz = NUM2SIZET(velmsz);
1292
- if (elmsz != 0 && len > SIZE_MAX / elmsz) {
1293
- rb_raise(rb_eArgError, "specified size is too large");
1294
- }
1295
- byte_size = len * elmsz;
1275
+ byte_size = len * NUM2SIZET(velmsz);
1296
1276
  } else {
1297
1277
  byte_size = ceil(len * NUM2DBL(velmsz));
1298
1278
  }
@@ -1335,14 +1315,13 @@ static VALUE nary_s_from_binary(int argc, VALUE* argv, VALUE type) {
1335
1315
  @return [Integer] stored length.
1336
1316
  */
1337
1317
  static VALUE nary_store_binary(int argc, VALUE* argv, VALUE self) {
1338
- size_t size, str_len, byte_size, offset, view_offset = 0;
1318
+ size_t size, str_len, byte_size, offset;
1339
1319
  int narg;
1340
1320
  VALUE vstr, voffset;
1341
1321
  VALUE velmsz;
1342
1322
  narray_t* na;
1343
1323
 
1344
1324
  narg = rb_scan_args(argc, argv, "11", &vstr, &voffset);
1345
- Check_Type(vstr, T_STRING);
1346
1325
  str_len = RSTRING_LEN(vstr);
1347
1326
  if (narg == 2) {
1348
1327
  offset = NUM2SIZET(voffset);
@@ -1358,11 +1337,7 @@ static VALUE nary_store_binary(int argc, VALUE* argv, VALUE self) {
1358
1337
  size = NA_SIZE(na);
1359
1338
  velmsz = rb_const_get(rb_obj_class(self), id_element_byte_size);
1360
1339
  if (FIXNUM_P(velmsz)) {
1361
- size_t elmsz = NUM2SIZET(velmsz);
1362
- if (elmsz != 0 && size > SIZE_MAX / elmsz) {
1363
- rb_raise(rb_eArgError, "string is too short to store");
1364
- }
1365
- byte_size = size * elmsz;
1340
+ byte_size = size * NUM2SIZET(velmsz);
1366
1341
  } else {
1367
1342
  byte_size = ceil(size * NUM2DBL(velmsz));
1368
1343
  }
@@ -1370,34 +1345,12 @@ static VALUE nary_store_binary(int argc, VALUE* argv, VALUE self) {
1370
1345
  rb_raise(rb_eArgError, "string is too short to store");
1371
1346
  }
1372
1347
 
1373
- if (na->type == NARRAY_VIEW_T) {
1374
- narray_t* nab;
1375
- size_t data_byte_size;
1376
-
1377
- if (na_check_contiguous(self) == Qfalse) {
1378
- rb_raise(rb_eStandardError, "cannot store binary data to non-contiguous NArray");
1379
- }
1380
- view_offset = NA_VIEW_OFFSET(na);
1381
- if (!FIXNUM_P(velmsz) && view_offset != 0) {
1382
- rb_raise(rb_eStandardError, "cannot store binary data to NArray view offset in bits");
1383
- }
1384
- GetNArray(NA_VIEW_DATA(na), nab);
1385
- if (FIXNUM_P(velmsz)) {
1386
- data_byte_size = NA_SIZE(nab) * NUM2SIZET(velmsz);
1387
- } else {
1388
- data_byte_size = ceil(NA_SIZE(nab) * NUM2DBL(velmsz));
1389
- }
1390
- if (view_offset > data_byte_size || byte_size > data_byte_size - view_offset) {
1391
- rb_raise(rb_eArgError, "string is too long to store");
1392
- }
1393
- }
1394
-
1395
- if (OBJ_FROZEN(vstr) && na->type != NARRAY_VIEW_T) {
1348
+ if (OBJ_FROZEN(vstr)) {
1396
1349
  na_set_pointer(self, RSTRING_PTR(vstr) + offset, byte_size);
1397
1350
  rb_ivar_set(self, id_source, vstr);
1398
1351
  } else {
1399
- char* ptr = na_get_pointer_for_write(self);
1400
- memcpy(ptr + view_offset, RSTRING_PTR(vstr) + offset, byte_size);
1352
+ void* ptr = na_get_pointer_for_write(self);
1353
+ memcpy(ptr, RSTRING_PTR(vstr) + offset, byte_size);
1401
1354
  }
1402
1355
 
1403
1356
  return SIZET2NUM(byte_size);
@@ -1413,12 +1366,10 @@ static VALUE nary_to_binary(VALUE self) {
1413
1366
  char* ptr;
1414
1367
  VALUE str;
1415
1368
  narray_t* na;
1416
- int offset_in_bits;
1417
1369
 
1418
1370
  GetNArray(self, na);
1419
1371
  if (na->type == NARRAY_VIEW_T) {
1420
- offset_in_bits = RTEST(rb_obj_is_kind_of(self, numo_cBit)) && NA_VIEW_OFFSET(na) != 0;
1421
- if (!offset_in_bits && na_check_contiguous(self) == Qtrue) {
1372
+ if (na_check_contiguous(self) == Qtrue) {
1422
1373
  offset = NA_VIEW_OFFSET(na);
1423
1374
  } else {
1424
1375
  self = rb_funcall(self, id_dup, 0);
@@ -1450,7 +1401,7 @@ static VALUE nary_marshal_dump(VALUE self) {
1450
1401
  GetNArray(self, na);
1451
1402
  if (na->type == NARRAY_VIEW_T) {
1452
1403
  if (na_check_contiguous(self) == Qtrue) {
1453
- offset = NA_VIEW_OFFSET(na) / sizeof(VALUE);
1404
+ offset = NA_VIEW_OFFSET(na);
1454
1405
  } else {
1455
1406
  self = rb_funcall(self, id_dup, 0);
1456
1407
  }
@@ -1474,9 +1425,6 @@ static VALUE na_inplace(VALUE self);
1474
1425
  static VALUE nary_marshal_load(VALUE self, VALUE a) {
1475
1426
  VALUE v;
1476
1427
 
1477
- if (OBJ_FROZEN(self)) {
1478
- rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
1479
- }
1480
1428
  if (TYPE(a) != T_ARRAY) {
1481
1429
  rb_raise(rb_eArgError, "marshal argument should be array");
1482
1430
  }
@@ -1491,9 +1439,6 @@ static VALUE nary_marshal_load(VALUE self, VALUE a) {
1491
1439
  NUM2INT(RARRAY_AREF(a, 0))
1492
1440
  );
1493
1441
  }
1494
- if (TYPE(RARRAY_AREF(a, 1)) != T_ARRAY) {
1495
- rb_raise(rb_eArgError, "marshal shape should be array");
1496
- }
1497
1442
  na_initialize(self, RARRAY_AREF(a, 1));
1498
1443
  NA_FL0_SET(self, FIX2INT(RARRAY_AREF(a, 2)));
1499
1444
  v = RARRAY_AREF(a, 3);
@@ -1510,7 +1455,6 @@ static VALUE nary_marshal_load(VALUE self, VALUE a) {
1510
1455
  ptr = na_get_pointer_for_write(self);
1511
1456
  memcpy(ptr, RARRAY_PTR(v), NA_SIZE(na) * sizeof(VALUE));
1512
1457
  } else {
1513
- Check_Type(v, T_STRING);
1514
1458
  rb_str_freeze(v);
1515
1459
  nary_store_binary(1, &v, self);
1516
1460
  if (TEST_BYTE_SWAPPED(self)) {
@@ -520,7 +520,7 @@ static void ndloop_set_stepidx(na_md_loop_t* lp, int j, VALUE vna, int* dim_map,
520
520
  if (n > 1 || nd > 0) {
521
521
  i = dim_map[k];
522
522
  LITER(lp, i, j).step = s;
523
- LITER(lp, i, j).idx = NULL;
523
+ // LITER(lp,i,j).idx = NULL;
524
524
  }
525
525
  s *= n;
526
526
  nd--;
@@ -539,7 +539,7 @@ static void ndloop_set_stepidx(na_md_loop_t* lp, int j, VALUE vna, int* dim_map,
539
539
  LITER(lp, i, j).idx = SDX_GET_INDEX(sdx);
540
540
  } else {
541
541
  LITER(lp, i, j).step = SDX_GET_STRIDE(sdx);
542
- LITER(lp, i, j).idx = NULL;
542
+ // LITER(lp,i,j).idx = NULL;
543
543
  }
544
544
  } else if (n == 1) {
545
545
  if (SDX_IS_INDEX(sdx)) {
@@ -1540,7 +1540,6 @@ static void loop_store_subnarray(ndfunc_t* nf, na_md_loop_t* lp, int i0, size_t*
1540
1540
  dim_map[i] = lp->trans_map[i + i0];
1541
1541
  }
1542
1542
  ndloop_set_stepidx(lp, 1, a, dim_map, NDL_READ);
1543
- LITER(lp, i0, 1).pos = LITER(lp, 0, 1).pos;
1544
1543
  LARG(lp, 1).shape = &(na->shape[na->ndim - 1]);
1545
1544
 
1546
1545
  // loop body
@@ -13,10 +13,10 @@ extern "C" {
13
13
  #endif
14
14
  #endif
15
15
 
16
- #define NARRAY_VERSION "0.10.8"
16
+ #define NARRAY_VERSION "0.11.0"
17
17
  #define NARRAY_VERSION_MAJOR 0
18
- #define NARRAY_VERSION_MINOR 10
19
- #define NARRAY_VERSION_PATCH 8
18
+ #define NARRAY_VERSION_MINOR 11
19
+ #define NARRAY_VERSION_PATCH 0
20
20
  #define NARRAY_VERSION_CODE \
21
21
  (NARRAY_VERSION_MAJOR * 10000 + NARRAY_VERSION_MINOR * 100 + NARRAY_VERSION_PATCH)
22
22
 
@@ -68,6 +68,13 @@
68
68
 
69
69
  #define m_mulsum_init INT2FIX(0)
70
70
 
71
+ #define m_sprintf(s, x) robj_sprintf(s, x)
72
+
73
+ static inline int robj_sprintf(char* s, VALUE x) {
74
+ VALUE v = rb_funcall(x, rb_intern("to_s"), 0);
75
+ return sprintf(s, "%s", StringValuePtr(v));
76
+ }
77
+
71
78
  #define m_sqrt(x) \
72
79
  rb_funcall(rb_const_get(rb_mKernel, rb_intern("Math")), rb_intern("sqrt"), 1, x);
73
80