numo-narray-alt 0.11.3 → 0.12.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: 49f4c26235333f8e467b493aa8dda971e62599966dc12c0d81a5a0fae939bb6d
4
- data.tar.gz: 134d4eafee1f7b1165c8700c3fb2038ed018c7e36043926ed382cc3f8d1e94c6
3
+ metadata.gz: b7fe2db61f420e9d120e010bd9e34bc9f5922c7fc49df6be8a2aca032889c483
4
+ data.tar.gz: 6a8db228589e11376512981a8da2eed248155cc558058c625f6cc90439ad053a
5
5
  SHA512:
6
- metadata.gz: f9d2b83363362f38302ed35d4c3dba6807bdc90a343c0814adb78a0bd1055d7c0dd9690bbd4a69cab32b802d57f4c602f82405a17a0a5371a74d31602988165c
7
- data.tar.gz: edd47b6629ca041b3db6b843cb15887ae0a8d64d2be53d0fd683009108091a4ea679cd2c41e030a31e67548d931fa328aa724cdd1c548ec6bda808fbe40ae773
6
+ metadata.gz: b8dd3b2c04fa09b87357a75a626ed2a10f7d53da4c2a39bc93358745edae562c397acbaa8e503b5bd9483ee47f569c1452734b18c3eb3f35e46bb0d655c4bede
7
+ data.tar.gz: 38089735d3d863a211b4a2fa8dc29c162763a607bafa0cfdd463a4276e31b4278420559257b9fb4b18f95367875ad306950e0963e9a271ae3d3a2c9f9e9f85e7
@@ -1262,6 +1262,9 @@ static VALUE nary_s_from_binary(int argc, VALUE* argv, VALUE type) {
1262
1262
  VALUE vstr, vshape, vna;
1263
1263
  VALUE velmsz;
1264
1264
 
1265
+ if (RTEST(rb_class_inherited_p(type, numo_cRObject))) {
1266
+ rb_raise(rb_eTypeError, "cannot restore %s from binary data", rb_class2name(type));
1267
+ }
1265
1268
  narg = rb_scan_args(argc, argv, "11", &vstr, &vshape);
1266
1269
  Check_Type(vstr, T_STRING);
1267
1270
  str_len = RSTRING_LEN(vstr);
@@ -1341,6 +1344,9 @@ static VALUE nary_store_binary(int argc, VALUE* argv, VALUE self) {
1341
1344
  VALUE velmsz;
1342
1345
  narray_t* na;
1343
1346
 
1347
+ if (RTEST(rb_obj_is_kind_of(self, numo_cRObject))) {
1348
+ rb_raise(rb_eTypeError, "cannot store binary data to %s", rb_obj_classname(self));
1349
+ }
1344
1350
  narg = rb_scan_args(argc, argv, "11", &vstr, &voffset);
1345
1351
  Check_Type(vstr, T_STRING);
1346
1352
  str_len = RSTRING_LEN(vstr);
@@ -1415,6 +1421,9 @@ static VALUE nary_to_binary(VALUE self) {
1415
1421
  narray_t* na;
1416
1422
  int offset_in_bits;
1417
1423
 
1424
+ if (RTEST(rb_obj_is_kind_of(self, numo_cRObject))) {
1425
+ rb_raise(rb_eTypeError, "cannot convert %s into binary data", rb_obj_classname(self));
1426
+ }
1418
1427
  GetNArray(self, na);
1419
1428
  if (na->type == NARRAY_VIEW_T) {
1420
1429
  offset_in_bits = RTEST(rb_obj_is_kind_of(self, numo_cBit)) && NA_VIEW_OFFSET(na) != 0;
@@ -1443,7 +1452,7 @@ static VALUE nary_marshal_dump(VALUE self) {
1443
1452
  rb_ary_push(a, INT2FIX(1)); // version
1444
1453
  rb_ary_push(a, na_shape(self));
1445
1454
  rb_ary_push(a, INT2FIX(NA_FLAG0(self)));
1446
- if (rb_obj_class(self) == numo_cRObject) {
1455
+ if (RTEST(rb_obj_is_kind_of(self, numo_cRObject))) {
1447
1456
  narray_t* na;
1448
1457
  VALUE* ptr;
1449
1458
  size_t offset = 0;
@@ -1497,7 +1506,7 @@ static VALUE nary_marshal_load(VALUE self, VALUE a) {
1497
1506
  na_initialize(self, RARRAY_AREF(a, 1));
1498
1507
  NA_FL0_SET(self, FIX2INT(RARRAY_AREF(a, 2)));
1499
1508
  v = RARRAY_AREF(a, 3);
1500
- if (rb_obj_class(self) == numo_cRObject) {
1509
+ if (RTEST(rb_obj_is_kind_of(self, numo_cRObject))) {
1501
1510
  narray_t* na;
1502
1511
  char* ptr;
1503
1512
  if (TYPE(v) != T_ARRAY) {
@@ -13,10 +13,10 @@ extern "C" {
13
13
  #endif
14
14
  #endif
15
15
 
16
- #define NARRAY_VERSION "0.11.3"
16
+ #define NARRAY_VERSION "0.12.0"
17
17
  #define NARRAY_VERSION_MAJOR 0
18
- #define NARRAY_VERSION_MINOR 11
19
- #define NARRAY_VERSION_PATCH 3
18
+ #define NARRAY_VERSION_MINOR 12
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
 
@@ -34,7 +34,7 @@ static dtype pow_int(dtype x, int p) {
34
34
  case 3:
35
35
  return x * x * x;
36
36
  }
37
- if (p < 0) return 0;
37
+ if (p < 0) rb_raise(nary_eValueError, "integers to negative integer powers are not allowed");
38
38
  while (p) {
39
39
  if (p & 1) r *= x;
40
40
  x *= x;
@@ -26,6 +26,7 @@ static dtype pow_int(dtype x, int p) {
26
26
  case 3:
27
27
  return x * x * x;
28
28
  }
29
+ if (p < 0) rb_raise(nary_eValueError, "integers to negative integer powers are not allowed");
29
30
  while (p) {
30
31
  if (p & 1) r *= x;
31
32
  x *= x;
@@ -405,7 +405,10 @@ void Init_numo_robject(void) {
405
405
  /* Stride size of contiguous RObject array. */
406
406
  rb_define_const(cT, "CONTIGUOUS_STRIDE", INT2FIX(sizeof(dtype)));
407
407
  rb_undef_method(rb_singleton_class(cT), "from_binary");
408
+ rb_undef_method(rb_singleton_class(cT), "from_string");
409
+ rb_undef_method(cT, "store_binary");
408
410
  rb_undef_method(cT, "to_binary");
411
+ rb_undef_method(cT, "to_string");
409
412
  rb_undef_method(cT, "swap_byte");
410
413
  rb_undef_method(cT, "to_network");
411
414
  rb_undef_method(cT, "to_vacs");
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-narray-alt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
@@ -214,7 +214,7 @@ licenses:
214
214
  metadata:
215
215
  homepage_uri: https://github.com/yoshoku/numo-narray-alt
216
216
  changelog_uri: https://github.com/yoshoku/numo-narray-alt/blob/main/CHANGELOG.md
217
- documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.11.3/
217
+ documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.12.0/
218
218
  rubygems_mfa_required: 'true'
219
219
  post_install_message: |
220
220
  ===