xnd 0.2.0dev7 → 0.2.0dev8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88ae9320468c5a0d6129cbb1403f5c0cb4968bb3
4
- data.tar.gz: 6ca5834d15f88f89a420ec841ad191855fa846d3
3
+ metadata.gz: a0032edbe644ff3632a9c8b31e39e8f2c115e066
4
+ data.tar.gz: 71a128e17b888289770f6237010a3547665b7173
5
5
  SHA512:
6
- metadata.gz: 238cac8e9ce6e4aed41e57c55abaf68286781b642ed356ba6339eb2e262aae2c0081f2d6aabc63db104295452300eddb8daf20b9da90b512d1a5d055956bac4f
7
- data.tar.gz: 4943e104993ca0910904feaab4c29b8d484faf3fe31c910e28980d59d9d7d69edcd45e2b6ad728a08fb5dc0669ac39f617c4877889510680f5e35d626d705917
6
+ metadata.gz: fe327a114d2fe24f3e00044df66d0d4ef706df05c1b75808febd4be8470545ea47fa37d3d83e8eeb50b5b99b876761169fe50930b2f497819704ecea4ab45b83
7
+ data.tar.gz: 9ef65d4867c3d04d5e2eb0533a04bace38d5c855ff895d24563640fa93fc341338c8671441c787a2e5c06a92eb60b23ea003480c93cc4bb4aa26d18be3717773
Binary file
Binary file
@@ -54,6 +54,7 @@ extern "C" {
54
54
  VALUE rb_xnd_from_xnd(xnd_t *x);
55
55
 
56
56
  typedef struct XndObject XndObject;
57
+ extern VALUE cXND;
57
58
 
58
59
  #ifdef __cplusplus
59
60
  }
@@ -35,7 +35,9 @@
35
35
  */
36
36
 
37
37
  #include "ruby_xnd_internal.h"
38
+ #include "ruby_xnd.h"
38
39
  #include "xnd.h"
40
+ #include "ruby.h"
39
41
 
40
42
  #define XND_CHECK_NUMERIC(obj) Check_Type(obj, T_FIXNUM); \
41
43
  Check_Type(obj, T_BIGNUM); Check_Type(obj, T_RATIONAL); \
@@ -148,10 +150,8 @@ mblock_alloc(void)
148
150
  if (self == NULL) {
149
151
 
150
152
  }
151
-
152
153
  self->type = NULL;
153
154
  self->xnd = NULL;
154
-
155
155
  return self;
156
156
  }
157
157
 
@@ -422,6 +422,28 @@ mblock_init(xnd_t * const x, VALUE data)
422
422
 
423
423
  return 0;
424
424
  }
425
+
426
+ case VarDimElem: {
427
+ int64_t start, step, shape;
428
+ shape = ndt_var_indices(&start, &step, t, x->index, &ctx);
429
+ if (shape < 0) {
430
+ seterr(&ctx);
431
+ raise_error();
432
+ }
433
+
434
+ const int64_t i = adjust_index(t->VarDimElem.index, shape, &ctx);
435
+ if (i < 0) {
436
+ seterr(&ctx);
437
+ raise_error();
438
+ }
439
+
440
+ xnd_t next = xnd_var_dim_next(x, start, step, i);
441
+ if (mblock_init(&next, data) < 0) {
442
+ return -1;
443
+ }
444
+
445
+ return 0;
446
+ }
425
447
 
426
448
  case Tuple: {
427
449
  const int64_t shape = t->Tuple.shape;
@@ -621,6 +643,10 @@ mblock_init(xnd_t * const x, VALUE data)
621
643
  return 0;
622
644
  }
623
645
 
646
+ case BFloat16: {
647
+ rb_raise(rb_eNotImpError, "bfloat16 not implemented.");
648
+ }
649
+
624
650
  case Float16: {
625
651
  rb_raise(rb_eNotImpError, "float16 not implemented.");
626
652
  }
@@ -634,6 +660,10 @@ mblock_init(xnd_t * const x, VALUE data)
634
660
  double temp = NUM2DBL(data);
635
661
  return rb_xnd_pack_float64(temp, (unsigned char*)x->ptr, le(t->flags));
636
662
  }
663
+
664
+ case BComplex32: {
665
+ rb_raise(rb_eNotImpError, "bcomplex32 not implemented.");
666
+ }
637
667
 
638
668
  case Complex32: {
639
669
  rb_raise(rb_eNotImpError, "complex32 not implemented.");
@@ -815,6 +845,38 @@ mblock_init(xnd_t * const x, VALUE data)
815
845
  return 0;
816
846
  }
817
847
 
848
+ case Array: {
849
+ bool overflow = false;
850
+
851
+ Check_Type(data, T_ARRAY);
852
+
853
+ const size_t shape = rb_ary_size(data);
854
+ const int64_t size = MULi64(shape, t->Array.itemsize, &overflow);
855
+ if (overflow) {
856
+ ndt_err_format(&ctx, NDT_ValueError, "datasize of flexible array to large.");
857
+ seterr(&ctx);
858
+ raise_error();
859
+ }
860
+
861
+ char * aligned = ndt_aligned_calloc(t->align, size);
862
+ if (data == NULL) {
863
+ rb_raise(rb_eNoMemError, "ndt_aligned_calloc failed.");
864
+ }
865
+
866
+ xnd_clear(x, XND_OWN_EMBEDDED);
867
+ XND_ARRAY_SHAPE(x->ptr) = shape;
868
+ XND_ARRAY_DATA(x->ptr) = aligned;
869
+
870
+ for (int64_t i = 0; i < shape; i++) {
871
+ xnd_t next = xnd_array_next(x, i);
872
+ if (mblock_init(&next, rb_ary_entry(data, i)) < 0) {
873
+ return -1;
874
+ }
875
+ }
876
+
877
+ return 0;
878
+ }
879
+
818
880
  case Categorical: {
819
881
  int64_t k;
820
882
 
@@ -937,7 +999,7 @@ static VALUE XND_size(VALUE self);
937
999
 
938
1000
  /* Allocate an XndObject and return wrapped in a Ruby object. */
939
1001
  static VALUE
940
- XndObject_alloc(void)
1002
+ XndObject_alloc(VALUE klass)
941
1003
  {
942
1004
  XndObject *xnd;
943
1005
 
@@ -952,7 +1014,7 @@ XndObject_alloc(void)
952
1014
  xnd->xnd.type = NULL;
953
1015
  xnd->xnd.ptr = NULL;
954
1016
 
955
- return WRAP_XND(cXND, xnd);
1017
+ return WRAP_XND(klass, xnd);
956
1018
  }
957
1019
 
958
1020
  /* Mark Ruby objects within XndObject. */
@@ -1385,6 +1447,10 @@ _XND_value(const xnd_t * const x, const int64_t maxshape)
1385
1447
  return ULL2NUM(temp);
1386
1448
  }
1387
1449
 
1450
+ case BFloat16: {
1451
+ rb_raise(rb_eNotImpError, "bfloat16 is not implemented.");
1452
+ }
1453
+
1388
1454
  case Float16: {
1389
1455
  rb_raise(rb_eNotImpError, "float16 is not implemented.");
1390
1456
  }
@@ -1403,6 +1469,10 @@ _XND_value(const xnd_t * const x, const int64_t maxshape)
1403
1469
  return DBL2NUM(temp);
1404
1470
  }
1405
1471
 
1472
+ case BComplex32: {
1473
+ rb_raise(rb_eNotImpError, "bcomplex32 not implemented.");
1474
+ }
1475
+
1406
1476
  case Complex32: {
1407
1477
  rb_raise(rb_eNotImpError, "complex32 not implemented.");
1408
1478
  }
@@ -1481,6 +1551,34 @@ _XND_value(const xnd_t * const x, const int64_t maxshape)
1481
1551
  return bytes_from_string_and_size(s, size);
1482
1552
  }
1483
1553
 
1554
+ case Array: {
1555
+ VALUE lst, v;
1556
+ int64_t shape;
1557
+
1558
+ shape = XND_ARRAY_SHAPE(x->ptr);
1559
+ if (shape > maxshape) {
1560
+ shape = maxshape;
1561
+ }
1562
+
1563
+ lst = rb_ary_new2(shape);
1564
+
1565
+ for (int i = 0; i < shape; ++i) {
1566
+ if (i == maxshape-1) {
1567
+ rb_ary_store(lst, i, xnd_ellipsis());
1568
+ break;
1569
+ }
1570
+
1571
+ const xnd_t next = xnd_array_next(x, i);
1572
+ v = _XND_value(&next, maxshape);
1573
+ if (v == NULL) {
1574
+ return NULL;
1575
+ }
1576
+ rb_ary_store(lst, i, v);
1577
+ }
1578
+
1579
+ return lst;
1580
+ }
1581
+
1484
1582
  case Categorical: {
1485
1583
  int64_t k;
1486
1584
 
@@ -1568,7 +1666,7 @@ RubyXND_view_move_type(XndObject *src_p, xnd_t *x)
1568
1666
  type = rb_ndtypes_from_type(x->type);
1569
1667
  ndt_decref(x->type);
1570
1668
 
1571
- view = XndObject_alloc();
1669
+ view = XndObject_alloc(cXND);
1572
1670
  GET_XND(view, view_p);
1573
1671
 
1574
1672
  view_p->mblock = src_p->mblock;
@@ -2149,7 +2247,7 @@ XND_copy_contiguous(int argc, VALUE *argv, VALUE self)
2149
2247
  seterr(&ctx);
2150
2248
  }
2151
2249
 
2152
- dest = rb_xnd_empty_from_type(t, 0);
2250
+ dest = rb_xnd_empty_from_type(cXND, t, 0);
2153
2251
  ndt_decref(t);
2154
2252
 
2155
2253
  GET_XND(dest, dest_p);
@@ -2274,7 +2372,7 @@ XND_s_deserialize(VALUE klass, VALUE v)
2274
2372
 
2275
2373
  memcpy(mblock_p->xnd->master.ptr, s, mblock_size);
2276
2374
 
2277
- self = XndObject_alloc();
2375
+ self = XndObject_alloc(cXND);
2278
2376
  GET_XND(self, self_p);
2279
2377
  XND_from_mblock(self_p, mblock);
2280
2378
 
@@ -2297,7 +2395,7 @@ RubyXND_s_empty(VALUE klass, VALUE origin_type, VALUE device)
2297
2395
  VALUE mblock_type, xnd_type;
2298
2396
  uint32_t flags = 0;
2299
2397
 
2300
- self = XndObject_alloc();
2398
+ self = XndObject_alloc(cXND);
2301
2399
  GET_XND(self, self_p);
2302
2400
 
2303
2401
  if (device != Qnil) {
@@ -2366,7 +2464,7 @@ rb_xnd_from_xnd(xnd_t *x)
2366
2464
  MemoryBlockObject *mblock_p;
2367
2465
 
2368
2466
  mblock = mblock_from_xnd(x);
2369
- xnd = XndObject_alloc();
2467
+ xnd = XndObject_alloc(cXND);
2370
2468
  GET_XND(xnd, xnd_p);
2371
2469
  GET_MBLOCK(mblock, mblock_p);
2372
2470
  type = mblock_p->type;
@@ -2382,7 +2480,7 @@ rb_xnd_from_xnd(xnd_t *x)
2382
2480
 
2383
2481
  /* Create an XND object of type ndt_t */
2384
2482
  VALUE
2385
- rb_xnd_empty_from_type(const ndt_t *t, uint32_t flags)
2483
+ rb_xnd_empty_from_type(VALUE klass, const ndt_t *t, uint32_t flags)
2386
2484
  {
2387
2485
  MemoryBlockObject *mblock_p;
2388
2486
  XndObject *xnd_p;
@@ -2390,7 +2488,7 @@ rb_xnd_empty_from_type(const ndt_t *t, uint32_t flags)
2390
2488
 
2391
2489
  type = rb_ndtypes_from_type(t);
2392
2490
  mblock = mblock_empty(type, flags);
2393
- xnd = XndObject_alloc();
2491
+ xnd = XndObject_alloc(klass);
2394
2492
 
2395
2493
  GET_XND(xnd, xnd_p);
2396
2494
 
@@ -2409,6 +2507,34 @@ rb_xnd_get_type(void)
2409
2507
 
2410
2508
  }
2411
2509
 
2510
+ XndObject *
2511
+ rb_xnd_get_xnd_object(VALUE obj)
2512
+ {
2513
+ XndObject *xnd_p;
2514
+ GET_XND(obj, xnd_p);
2515
+ return xnd_p;
2516
+ }
2517
+
2518
+ MemoryBlockObject *
2519
+ rb_xnd_get_mblock_object(VALUE mblock)
2520
+ {
2521
+ MemoryBlockObject *mblock_p;
2522
+ GET_MBLOCK(mblock, mblock_p);
2523
+ return mblock_p;
2524
+ }
2525
+
2526
+ int
2527
+ rb_xnd_is_cuda_managed(VALUE xnd)
2528
+ {
2529
+ XndObject *xnd_p;
2530
+ MemoryBlockObject *mblock_p;
2531
+
2532
+ GET_XND(xnd, xnd_p);
2533
+ GET_MBLOCK(xnd_p->mblock, mblock_p);
2534
+
2535
+ return (mblock_p->xnd->flags & XND_CUDA_MANAGED);
2536
+ }
2537
+
2412
2538
  /*
2413
2539
  * This function handles two common view cases:
2414
2540
  *
@@ -45,16 +45,21 @@ extern "C" {
45
45
  #include "xnd.h"
46
46
  #include "overflow.h"
47
47
 
48
+ typedef struct MemoryBlockObject MemoryBlockObject;
49
+ typedef struct XndObject XndObject;
50
+ extern VALUE cXND;
51
+
48
52
  size_t rb_xnd_hash_size(VALUE hash);
49
53
  int rb_xnd_get_complex_values(VALUE comp, double *real, double *imag);
50
54
  /* Return true if obj is of type XND. */
51
55
  int rb_xnd_check_type(VALUE obj);
52
56
  const xnd_t * rb_xnd_const_xnd(VALUE xnd);
53
- VALUE rb_xnd_empty_from_type(const ndt_t *t, uint32_t flags);
57
+ VALUE rb_xnd_empty_from_type(VALUE klass, const ndt_t *t, uint32_t flags);
54
58
  VALUE rb_xnd_from_xnd(xnd_t *x);
55
-
56
- typedef struct XndObject XndObject;
57
-
59
+ XndObject * rb_xnd_get_xnd_object(VALUE obj);
60
+ MemoryBlockObject * rb_xnd_get_mblock_object(VALUE mblock);
61
+ int rb_xnd_is_cuda_managed(VALUE xnd);
62
+
58
63
  #ifdef __cplusplus
59
64
  }
60
65
  #endif
@@ -163,3 +163,18 @@ ndt_exists(void)
163
163
  {
164
164
  return RTEST(rb_const_get(rb_cObject, rb_intern("NDT")));
165
165
  }
166
+
167
+ int
168
+ rb_ary_size(VALUE array)
169
+ {
170
+ Check_Type(array, T_ARRAY);
171
+ return FIX2INT(rb_funcall(array, rb_intern("size"), 0, NULL));
172
+ }
173
+
174
+ void
175
+ rb_puts(VALUE v) {
176
+ ID sym_puts = rb_intern("puts");
177
+ ID sym_inspect = rb_intern("inspect");
178
+ rb_funcall(rb_mKernel, sym_puts, 1,
179
+ rb_funcall(v, sym_inspect, 0));
180
+ }
@@ -58,4 +58,8 @@ VALUE bytes_from_string_and_size(const char *str, int64_t size);
58
58
 
59
59
  int ndt_exists(void);
60
60
 
61
+ int rb_ary_size(VALUE array);
62
+
63
+ void rb_puts(VALUE v);
64
+
61
65
  #endif /* UTIL_H */
@@ -12,9 +12,9 @@ generated by GNU Autoconf 2.69. Invocation command line was
12
12
 
13
13
  hostname = sameer-K401UB
14
14
  uname -m = x86_64
15
- uname -r = 5.0.0-23-generic
15
+ uname -r = 5.0.0-27-generic
16
16
  uname -s = Linux
17
- uname -v = #24~18.04.1-Ubuntu SMP Mon Jul 29 16:12:28 UTC 2019
17
+ uname -v = #28~18.04.1-Ubuntu SMP Thu Aug 22 03:00:32 UTC 2019
18
18
 
19
19
  /usr/bin/uname -p = unknown
20
20
  /bin/uname -X = unknown
@@ -29,6 +29,7 @@ uname -v = #24~18.04.1-Ubuntu SMP Mon Jul 29 16:12:28 UTC 2019
29
29
 
30
30
  PATH: /home/sameer/.rvm/gems/ruby-2.4.1/bin
31
31
  PATH: /home/sameer/anaconda3/condabin
32
+ PATH: /home/sameer/anaconda3/bin
32
33
  PATH: /home/sameer/gitrepos/starpu-1.2.8/bin
33
34
  PATH: /home/sameer/.rvm/gems/ruby-2.4.1@global/bin
34
35
  PATH: /home/sameer/.rvm/rubies/ruby-2.4.1/bin
Binary file
data/lib/xnd.rb CHANGED
@@ -298,7 +298,6 @@ class XND < RubyXND
298
298
  end
299
299
  end
300
300
 
301
-
302
301
  def initialize data, type: nil, dtype: nil, levels: nil, typedef: nil,
303
302
  dtypedef: nil, device: nil
304
303
  if [type, dtype, levels, typedef, dtypedef].count(nil) < 2
@@ -346,5 +345,17 @@ class XND < RubyXND
346
345
  _transpose(permute)
347
346
  end
348
347
 
349
- alias :to_a :value
348
+ def inspect
349
+ str = "#<#{self.class}:#{object_id}>\n"
350
+ str += "\t type= " + self.type.to_s + "\n"
351
+ str += "\t value= "
352
+ str += self.short_value(10).to_s
353
+ str += "\n"
354
+
355
+ str
356
+ end
357
+
358
+ def to_s
359
+ short_value(10).to_s
360
+ end
350
361
  end # class XND
@@ -1,6 +1,6 @@
1
1
  class RubyXND
2
2
  # VERSION number should be the version of libxnd this is built against.
3
- VERSION = "0.2.0dev7"
3
+ VERSION = "0.2.0dev8"
4
4
  # Working commit in xnd repo
5
5
  COMMIT = '6f305cd40d90b4f3fc2fe51ae144b433d186a6cc'
6
6
  end
@@ -45,5 +45,5 @@ Gem::Specification.new do |spec|
45
45
  spec.add_development_dependency 'pry'
46
46
  spec.add_development_dependency 'pry-byebug'
47
47
 
48
- spec.add_runtime_dependency 'ndtypes', '>= 0.2.0dev6'
48
+ spec.add_runtime_dependency 'ndtypes', '>= 0.2.0dev8'
49
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xnd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0dev7
4
+ version: 0.2.0dev8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Deshmukh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2019-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.2.0dev6
103
+ version: 0.2.0dev8
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.2.0dev6
110
+ version: 0.2.0dev8
111
111
  description: 'XND is a library for typed data arrays in Ruby. It is a wrapper over
112
112
  the libxnd C library.
113
113