ndtypes 0.2.0dev5 → 0.2.0dev6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +12 -0
  3. data/Rakefile +8 -0
  4. data/ext/ruby_ndtypes/GPATH +0 -0
  5. data/ext/ruby_ndtypes/GRTAGS +0 -0
  6. data/ext/ruby_ndtypes/GTAGS +0 -0
  7. data/ext/ruby_ndtypes/extconf.rb +1 -1
  8. data/ext/ruby_ndtypes/include/ndtypes.h +231 -122
  9. data/ext/ruby_ndtypes/include/ruby_ndtypes.h +1 -1
  10. data/ext/ruby_ndtypes/lib/libndtypes.a +0 -0
  11. data/ext/ruby_ndtypes/lib/libndtypes.so.0.2.0dev3 +0 -0
  12. data/ext/ruby_ndtypes/ndtypes/Makefile +87 -0
  13. data/ext/ruby_ndtypes/ndtypes/config.h +68 -0
  14. data/ext/ruby_ndtypes/ndtypes/config.log +477 -0
  15. data/ext/ruby_ndtypes/ndtypes/config.status +1027 -0
  16. data/ext/ruby_ndtypes/ndtypes/doc/_static/style.css +7 -0
  17. data/ext/ruby_ndtypes/ndtypes/doc/_templates/layout.html +2 -0
  18. data/ext/ruby_ndtypes/ndtypes/doc/conf.py +40 -4
  19. data/ext/ruby_ndtypes/ndtypes/doc/images/xndlogo.png +0 -0
  20. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +1 -1
  21. data/ext/ruby_ndtypes/ndtypes/doc/requirements.txt +2 -0
  22. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile +287 -0
  23. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +20 -4
  24. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +22 -3
  25. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +1 -1
  26. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.o +0 -0
  27. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.o +0 -0
  28. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile +73 -0
  29. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +246 -229
  30. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +15 -11
  31. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.o +0 -0
  32. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +38 -28
  33. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +91 -91
  34. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +1 -1
  35. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +4 -3
  36. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.o +0 -0
  37. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +8 -7
  38. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.o +0 -0
  39. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +2 -2
  40. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.o +0 -0
  41. data/ext/ruby_ndtypes/ndtypes/libndtypes/context.o +0 -0
  42. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +263 -182
  43. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.o +0 -0
  44. data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.o +0 -0
  45. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +67 -7
  46. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.o +0 -0
  47. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +1112 -1000
  48. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +69 -58
  49. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.o +0 -0
  50. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +150 -99
  51. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +185 -15
  52. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.o +0 -0
  53. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +301 -276
  54. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +1 -1
  55. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +9 -4
  56. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.o +0 -0
  57. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.a +0 -0
  58. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so +1 -0
  59. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so.0 +1 -0
  60. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so.0.2.0dev3 +0 -0
  61. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +729 -228
  62. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.o +0 -0
  63. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +768 -403
  64. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h +1002 -0
  65. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +231 -122
  66. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.o +0 -0
  67. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +176 -84
  68. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +26 -14
  69. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.o +0 -0
  70. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +57 -35
  71. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.o +0 -0
  72. data/ext/ruby_ndtypes/ndtypes/libndtypes/primitive.c +420 -0
  73. data/ext/ruby_ndtypes/ndtypes/libndtypes/primitive.o +0 -0
  74. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +8 -8
  75. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +1 -1
  76. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.o +0 -0
  77. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile +48 -0
  78. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +200 -116
  79. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.o +0 -0
  80. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +46 -4
  81. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.o +0 -0
  82. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +58 -27
  83. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +1 -1
  84. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.o +0 -0
  85. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +3 -5
  86. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +12 -4
  87. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.o +0 -0
  88. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile +55 -0
  89. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +8 -8
  90. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +5 -5
  91. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +274 -172
  92. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +24 -4
  93. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +2 -2
  94. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +14 -14
  95. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +32 -30
  96. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +37 -0
  97. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +36 -0
  98. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +16 -0
  99. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +5 -5
  100. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +706 -253
  101. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_unify.c +132 -0
  102. data/ext/ruby_ndtypes/ndtypes/libndtypes/unify.c +703 -0
  103. data/ext/ruby_ndtypes/ndtypes/libndtypes/unify.o +0 -0
  104. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +335 -127
  105. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.o +0 -0
  106. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +2 -2
  107. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.o +0 -0
  108. data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +88 -71
  109. data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +0 -1
  110. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +10 -13
  111. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +395 -314
  112. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.a +0 -0
  113. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so +1 -0
  114. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0 +1 -0
  115. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0.2.0dev3 +0 -0
  116. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/ndtypes.h +1002 -0
  117. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +15 -33
  118. data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +340 -132
  119. data/ext/ruby_ndtypes/ndtypes/setup.py +11 -2
  120. data/ext/ruby_ndtypes/ruby_ndtypes.c +364 -241
  121. data/ext/ruby_ndtypes/ruby_ndtypes.h +1 -1
  122. data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +0 -1
  123. data/lib/ndtypes.rb +11 -0
  124. data/lib/ndtypes/version.rb +2 -2
  125. data/lib/ruby_ndtypes.so +0 -0
  126. data/ndtypes.gemspec +3 -0
  127. data/spec/ndtypes_spec.rb +6 -0
  128. metadata +98 -4
  129. data/ext/ruby_ndtypes/gc_guard.c +0 -36
  130. data/ext/ruby_ndtypes/gc_guard.h +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dde7a1b96db3ec81d383486bbc07eb83073290f
4
- data.tar.gz: 84e6162b7e364d6254a6de3c0ba3518a92b73861
3
+ metadata.gz: 146d295eb8030be1aa6ab3970ed79f6281f4ff74
4
+ data.tar.gz: 856f4db436aa8440ea84b6a1d00d6d9d029c30f2
5
5
  SHA512:
6
- metadata.gz: 4d69c91b4bcb0a37b86b134f8c283d83d780681866082b52bcd50259163493ee88b4a134aee3f17143b499ee24ca35fa17d9e7d168a4144209cee79ae0e7370e
7
- data.tar.gz: 03fbb84d4998cfd564a08ebe10d2641158516128e44cb280730cd5fb9d7826632f536a89cc031fae13b37c87662770ee7737af5dd87afab81ee78b311969674b
6
+ metadata.gz: 312cda068f83102905c7f383311d989ef74118160e6f8a9db9447ed6748de9026291cbfa295b2e1abfa1610407794e52baeee8aac27b64f0aa43517e31e82f95
7
+ data.tar.gz: 1eaea4defd4d79fd50e4ba1ec657efe795b9ce535a068e7eb7b95460c140bb179590f6b05b248a43f4848196faff9dfe8eb126f941a5f11fe940844f6a27d623
data/CONTRIBUTING.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Developer notes
2
2
 
3
+ ## Contributing to ndtypes Ruby wrapper
4
+
5
+ If you're interested in contributing to the ndtypes Ruby wrapper, follow the following
6
+ steps for getting started:
7
+
8
+ * Clone the ndtypes repo: `git clone https://github.com/plures/ndtypes.git`.
9
+ * Switch to the `ruby-wrapper` branch: `git checkout ruby-wrapper`.
10
+ * Run `bundle install`.
11
+ * Run `rake develop`. This will build ndtypes with the latest working master branch
12
+ of libndtypes.
13
+ * Run `rspec` for running the tests.
14
+
3
15
  ## Interfacing with Ruby's GC
4
16
 
5
17
  ### Background
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/extensiontask'
3
+ require 'rake/testtask'
3
4
  require 'rspec/core/rake_task'
4
5
  require 'bundler/gem_tasks'
5
6
  require 'fileutils'
@@ -92,6 +93,13 @@ task :leakcheck => [ :compile ] do |task|
92
93
  run( *cmd )
93
94
  end
94
95
 
96
+
97
+ Rake::TestTask.new(:test) do |t|
98
+ t.libs << "test"
99
+ t.libs << "lib"
100
+ t.test_files = FileList['test/**/test_*.rb']
101
+ end
102
+
95
103
  task :clobber do |task|
96
104
  [
97
105
  "ext/#{ext_name}/include",
Binary file
Binary file
Binary file
@@ -54,7 +54,7 @@ FileUtils.copy_file File.expand_path(File.join(File.dirname(__FILE__) +
54
54
 
55
55
  dir_config("ndtypes", [headers], [binaries])
56
56
 
57
- basenames = %w{gc_guard ruby_ndtypes}
57
+ basenames = %w{ruby_ndtypes}
58
58
  $objs = basenames.map { |b| "#{b}.o" }
59
59
  $srcs = basenames.map { |b| "#{b}.c" }
60
60
 
@@ -35,13 +35,23 @@
35
35
  #define NDTYPES_H
36
36
 
37
37
 
38
+ #ifdef __cplusplus
39
+ extern "C" {
40
+ #endif
41
+
38
42
  #include <stdio.h>
39
43
  #include <stdlib.h>
40
- #include <stdint.h>
41
44
  #include <limits.h>
42
45
  #include <stdbool.h>
43
46
  #include <stddef.h>
44
- #include <complex.h>
47
+
48
+ #ifdef __cplusplus
49
+ #include <cstdint>
50
+ #else
51
+ #include <stdint.h>
52
+ #include <inttypes.h>
53
+ #include <complex.h>
54
+ #endif
45
55
 
46
56
 
47
57
  #if SIZE_MAX > ULLONG_MAX
@@ -67,12 +77,18 @@
67
77
  #define NDTYPES_API
68
78
  #endif
69
79
 
70
- typedef _Dcomplex ndt_complex128_t;
71
- typedef _Fcomplex ndt_complex64_t;
72
80
  #define alignof __alignof
73
81
  #define alignas(n) __declspec(align(n))
74
82
  #define MAX_ALIGN 8
75
83
  #define NDT_SYS_BIG_ENDIAN 0
84
+
85
+ #ifdef __cplusplus
86
+ #define ATOMIC_INT64 int64_t
87
+ #else
88
+ #define ATOMIC_INT64 __int64 volatile
89
+ typedef _Dcomplex ndt_complex128_t;
90
+ typedef _Fcomplex ndt_complex64_t;
91
+ #endif
76
92
  #else
77
93
  #define NDTYPES_API
78
94
 
@@ -80,10 +96,18 @@
80
96
  #error "ndtypes requires IEEE floating point arithmetic"
81
97
  #endif
82
98
  #include <stdalign.h>
83
- typedef double complex ndt_complex128_t;
84
- typedef float complex ndt_complex64_t;
99
+
85
100
  #define MAX_ALIGN (alignof(max_align_t))
86
101
  #define NDT_SYS_BIG_ENDIAN 0
102
+
103
+ #ifdef __cplusplus
104
+ #define ATOMIC_INT64 int64_t
105
+ #else
106
+ #include <stdatomic.h>
107
+ #define ATOMIC_INT64 _Atomic int64_t
108
+ typedef double complex ndt_complex128_t;
109
+ typedef float complex ndt_complex64_t;
110
+ #endif
87
111
  #endif
88
112
 
89
113
  #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \
@@ -105,11 +129,14 @@
105
129
  #define NDT_MAX_DIM 128
106
130
  #define NDT_MAX_ARGS 128
107
131
 
108
- #define NDT_LITTLE_ENDIAN 0x00000001U
109
- #define NDT_BIG_ENDIAN 0x00000002U
110
- #define NDT_OPTION 0x00000004U
111
- #define NDT_SUBTREE_OPTION 0x00000008U
132
+ #define NDT_OPTION 0x00000001U
133
+ #define NDT_SUBTREE_OPTION 0x00000002U
134
+ #define NDT_LITTLE_ENDIAN 0x00000004U
135
+ #define NDT_BIG_ENDIAN 0x00000008U
112
136
  #define NDT_ELLIPSIS 0x00000010U
137
+ #define NDT_POINTER 0x00000020U
138
+ #define NDT_REF 0x00000040U
139
+ #define NDT_CHAR 0x00000080U
113
140
 
114
141
 
115
142
  /* Types: ndt_t */
@@ -145,34 +172,37 @@ enum ndt_variadic {
145
172
  Variadic
146
173
  };
147
174
 
148
- /* Ownership flag for var dim offsets */
149
- enum ndt_offsets {
150
- InternalOffsets,
151
- ExternalOffsets,
175
+ /* Offsets for a variable dimension. Shared between copies or slices. */
176
+ typedef struct _ndt_offsets ndt_offsets_t;
177
+
178
+ struct _ndt_offsets {
179
+ ATOMIC_INT64 refcnt;
180
+ int32_t n; /* number of offsets */
181
+ const int32_t *v; /* offset array */
152
182
  };
153
183
 
184
+ NDTYPES_API ndt_offsets_t *ndt_offsets_new(int32_t size, ndt_context_t *ctx);
185
+ NDTYPES_API ndt_offsets_t *ndt_offsets_from_ptr(int32_t *ptr, int32_t size, ndt_context_t *ctx);
186
+ NDTYPES_API void ndt_incref_offsets(const ndt_offsets_t *);
187
+ NDTYPES_API void ndt_decref_offsets(const ndt_offsets_t *);
188
+
154
189
  /*
155
- * Collect offsets during parsing for transferring ownership to an external
156
- * resource manager later.
157
- *
158
190
  * The arrays are addressed by t->ndim-1, where t->ndim > 0. It follows that
159
191
  * offsets[0] are the offsets of the innermost dimension and offsets[ndims-1]
160
192
  * the offsets of the outermost dimension.
161
193
  */
162
194
  typedef struct {
163
- int ndims; /* number of offset arrays */
164
- int32_t noffsets[NDT_MAX_DIM]; /* length of the nth offset array */
165
- int32_t *offsets[NDT_MAX_DIM]; /* nth offset array */
195
+ int ndims; /* number of offset structs */
196
+ ndt_offsets_t *offsets[NDT_MAX_DIM]; /* offset structs */
166
197
  } ndt_meta_t;
167
198
 
168
-
169
199
  /* Encoding for characters and strings */
170
200
  enum ndt_encoding {
171
201
  Ascii,
172
202
  Utf8,
203
+ Ucs2,
173
204
  Utf16,
174
205
  Utf32,
175
- Ucs2,
176
206
  };
177
207
 
178
208
 
@@ -188,12 +218,15 @@ enum ndt {
188
218
  AnyKind,
189
219
  FixedDim,
190
220
  VarDim,
221
+ VarDimElem,
191
222
  SymbolicDim,
192
223
  EllipsisDim,
193
224
 
194
225
  /* Dtype */
226
+ Array,
195
227
  Tuple,
196
228
  Record,
229
+ Union,
197
230
  Ref,
198
231
  Constr,
199
232
  Nominal,
@@ -228,11 +261,13 @@ enum ndt {
228
261
  Uint64,
229
262
 
230
263
  FloatKind,
264
+ BFloat16,
231
265
  Float16,
232
266
  Float32,
233
267
  Float64,
234
268
 
235
269
  ComplexKind,
270
+ BComplex32,
236
271
  Complex32,
237
272
  Complex64,
238
273
  Complex128,
@@ -267,7 +302,7 @@ enum ndt_contig {
267
302
  typedef struct {
268
303
  enum ndt_access access;
269
304
  char *name;
270
- ndt_t *type;
305
+ const ndt_t *type;
271
306
  struct {
272
307
  uint16_t align;
273
308
  bool explicit_align;
@@ -353,7 +388,7 @@ struct _ndt {
353
388
  union {
354
389
  struct {
355
390
  char *name;
356
- ndt_t *type;
391
+ const ndt_t *type;
357
392
  } Module;
358
393
 
359
394
  struct {
@@ -361,62 +396,73 @@ struct _ndt {
361
396
  int64_t nin;
362
397
  int64_t nout;
363
398
  int64_t nargs;
364
- ndt_t **types;
399
+ const ndt_t **types;
365
400
  } Function;
366
401
 
367
402
  struct {
368
403
  enum ndt_contig tag;
369
404
  int64_t shape;
370
- ndt_t *type;
405
+ const ndt_t *type;
371
406
  } FixedDim;
372
407
 
373
408
  struct {
374
- ndt_t *type;
409
+ const ndt_t *type;
375
410
  } VarDim;
376
411
 
412
+ struct {
413
+ const ndt_t *type;
414
+ int64_t index;
415
+ } VarDimElem;
416
+
377
417
  struct {
378
418
  enum ndt_contig tag;
379
419
  char *name;
380
- ndt_t *type;
420
+ const ndt_t *type;
381
421
  } SymbolicDim;
382
422
 
383
423
  struct {
384
424
  enum ndt_contig tag;
385
425
  char *name;
386
- ndt_t *type;
426
+ const ndt_t *type;
387
427
  } EllipsisDim;
388
428
 
389
429
  struct {
390
430
  enum ndt_variadic flag;
391
431
  int64_t shape;
392
- ndt_t **types;
432
+ const ndt_t **types;
393
433
  } Tuple;
394
434
 
395
435
  struct {
396
436
  enum ndt_variadic flag;
397
437
  int64_t shape;
398
438
  char **names;
399
- ndt_t **types;
439
+ const ndt_t **types;
400
440
  } Record;
401
441
 
402
442
  struct {
403
- ndt_t *type;
443
+ int64_t ntags;
444
+ char **tags;
445
+ const ndt_t **types;
446
+ } Union;
447
+
448
+ struct {
449
+ const ndt_t *type;
404
450
  } Ref;
405
451
 
406
452
  struct {
407
453
  char *name;
408
- ndt_t *type;
454
+ const ndt_t *type;
409
455
  } Constr;
410
456
 
411
457
  struct {
412
458
  char *name;
413
- ndt_t *type;
459
+ const ndt_t *type;
414
460
  const ndt_methods_t *meth;
415
461
  } Nominal;
416
462
 
417
463
  struct {
418
464
  int64_t ntypes;
419
- ndt_value_t *types;
465
+ const ndt_value_t *types;
420
466
  } Categorical;
421
467
 
422
468
  struct {
@@ -433,6 +479,11 @@ struct _ndt {
433
479
  uint16_t target_align;
434
480
  } Bytes;
435
481
 
482
+ struct {
483
+ int64_t itemsize;
484
+ const ndt_t *type;
485
+ } Array;
486
+
436
487
  struct {
437
488
  enum ndt_encoding encoding;
438
489
  } Char;
@@ -451,10 +502,8 @@ struct _ndt {
451
502
  } FixedDim;
452
503
 
453
504
  struct {
454
- enum ndt_offsets flag;
455
505
  int64_t itemsize;
456
- int32_t noffsets;
457
- const int32_t *offsets;
506
+ const ndt_offsets_t *offsets;
458
507
  int nslices;
459
508
  ndt_slice_t *slices;
460
509
  } VarDim;
@@ -473,6 +522,10 @@ struct _ndt {
473
522
  };
474
523
  } Concrete;
475
524
 
525
+ /* Reference counting */
526
+ ATOMIC_INT64 refcnt;
527
+
528
+ /* Extra space */
476
529
  alignas(MAX_ALIGN) char extra[];
477
530
  };
478
531
 
@@ -544,21 +597,40 @@ typedef struct {
544
597
  int64_t steps[NDT_MAX_DIM];
545
598
  } ndt_ndarray_t;
546
599
 
547
- /* This may go into gumath at some point. A flag is set if the inner dimensions
548
- of all input and output arguments have the property. */
549
- #define NDT_ELEMWISE_1D 0x00000001U /* 1D elementwise and contiguous */
550
- #define NDT_C 0x00000004U /* ND C-contiguous */
551
- #define NDT_FORTRAN 0x00000008U /* ND F-contiguous */
552
- #define NDT_STRIDED 0x00000010U /* ND non-contiguous */
553
- #define NDT_XND 0x00000020U /* Any XND container */
600
+ /*
601
+ * Type properties that determine what kind of kernel can be used safely. A
602
+ * property flag is set if it applies to all input and output arguments.
603
+ */
604
+ #define NDT_INNER_C 0x00000001U /* inner dims C-contiguous */
605
+ #define NDT_INNER_F 0x00000002U /* inner dims F-contiguous */
606
+ #define NDT_INNER_STRIDED 0x00000004U /* inner dims strided */
607
+
608
+ /*
609
+ * Modifiers to the above properties that determine whether an extended
610
+ * optimized kernel (inner+1) can be used safely.
611
+ *
612
+ * C inner dimensions can be extended to a pure inner+1 C array. Fortran
613
+ * inner dimensions cannot be extended to yield another Fortran array,
614
+ * hence the unfortunate asymmetry.
615
+ */
616
+ #define NDT_EXT_C 0x00000010U /* inner+1 dims are C */
617
+ #define NDT_EXT_ZERO 0x00000020U /* inner dims are C, loop has C or zero stride (GPU) */
618
+ #define NDT_EXT_STRIDED 0x00000040U /* inner dims are {C,F,strided}, loop is strided */
619
+
620
+ #define NDT_INNER_XND 0x00000100U /* inner dims are xnd */
621
+
622
+ #define NDT_SPEC_FLAGS_ALL (NDT_INNER_C|NDT_INNER_F|NDT_INNER_STRIDED| \
623
+ NDT_EXT_C|NDT_EXT_ZERO|NDT_EXT_STRIDED| \
624
+ NDT_INNER_XND)
625
+
554
626
 
555
627
  typedef struct {
556
628
  uint32_t flags;
557
- int nout;
558
- int nbroadcast;
559
629
  int outer_dims;
560
- ndt_t *out[NDT_MAX_ARGS];
561
- ndt_t *broadcast[NDT_MAX_ARGS];
630
+ int nin; /* number of 'in' types */
631
+ int nout; /* number of 'out' types */
632
+ int nargs; /* nin+nout, for convenience */
633
+ const ndt_t *types[NDT_MAX_ARGS];
562
634
  } ndt_apply_spec_t;
563
635
 
564
636
  NDTYPES_API extern const ndt_apply_spec_t ndt_apply_spec_empty;
@@ -567,11 +639,10 @@ NDTYPES_API ndt_apply_spec_t *ndt_apply_spec_new(ndt_context_t *ctx);
567
639
  NDTYPES_API void ndt_apply_spec_clear(ndt_apply_spec_t *spec);
568
640
  NDTYPES_API void ndt_apply_spec_del(ndt_apply_spec_t *spec);
569
641
  NDTYPES_API const char *ndt_apply_flags_as_string(const ndt_apply_spec_t *spec);
570
- NDTYPES_API int ndt_broadcast_all(ndt_apply_spec_t *spec, const ndt_t *sig, const ndt_t *in[], const int nin,
571
- const int64_t *shape, int outer_dims, ndt_context_t *ctx);
642
+ NDTYPES_API int ndt_broadcast_all(ndt_apply_spec_t *spec, const ndt_t *sig, bool check_broadcast,
643
+ const int64_t *shape, const int outer_dims, ndt_context_t *ctx);
572
644
 
573
- NDTYPES_API void ndt_select_kernel_strategy(ndt_apply_spec_t *spec, const ndt_t *sig,
574
- const ndt_t *in[], int nin);
645
+ NDTYPES_API int ndt_select_kernel_strategy(ndt_apply_spec_t *spec, ndt_context_t *ctx);
575
646
 
576
647
 
577
648
  /*****************************************************************************/
@@ -583,12 +654,15 @@ NDTYPES_API char *ndt_strdup(const char *s, ndt_context_t *ctx);
583
654
  NDTYPES_API char *ndt_asprintf(ndt_context_t *ctx, const char *fmt, ...);
584
655
 
585
656
  /* Type functions (unstable API) */
657
+ NDTYPES_API int64_t ndt_nelem(const ndt_t *t);
658
+ NDTYPES_API int ndt_logical_ndim(const ndt_t *t);
659
+ NDTYPES_API const ndt_t *ndt_logical_dim_at(const ndt_t *t, int n);
586
660
  NDTYPES_API const ndt_t *ndt_dtype(const ndt_t *t);
587
661
  NDTYPES_API const ndt_t *ndt_hidden_dtype(const ndt_t *t);
588
662
  NDTYPES_API int ndt_dims_dtype(const ndt_t *dims[NDT_MAX_DIM], const ndt_t **dtype, const ndt_t *t);
589
- NDTYPES_API const ndt_t *ndt_dim_at(const ndt_t *t, int n);
590
663
  NDTYPES_API int ndt_as_ndarray(ndt_ndarray_t *a, const ndt_t *t, ndt_context_t *ctx);
591
- NDTYPES_API ndt_ssize_t ndt_hash(ndt_t *t, ndt_context_t *ctx);
664
+ NDTYPES_API const ndt_t *ndt_transpose(const ndt_t *t, const int *p, int ndim, ndt_context_t *ctx);
665
+ NDTYPES_API ndt_ssize_t ndt_hash(const ndt_t *t, ndt_context_t *ctx);
592
666
 
593
667
 
594
668
  /*****************************************************************************/
@@ -596,14 +670,14 @@ NDTYPES_API ndt_ssize_t ndt_hash(ndt_t *t, ndt_context_t *ctx);
596
670
  /*****************************************************************************/
597
671
 
598
672
  /* Fields */
599
- NDTYPES_API ndt_field_t *ndt_field(char *name, ndt_t *type, uint16_opt_t align,
673
+ NDTYPES_API ndt_field_t *ndt_field(char *name, const ndt_t *type, uint16_opt_t align,
600
674
  uint16_opt_t pack, uint16_opt_t pad, ndt_context_t *ctx);
601
675
  NDTYPES_API void ndt_field_del(ndt_field_t *field);
602
676
  NDTYPES_API void ndt_field_array_del(ndt_field_t *fields, int64_t shape);
603
677
 
604
678
  /* Typed values */
605
679
  NDTYPES_API void ndt_value_del(ndt_value_t *mem);
606
- NDTYPES_API void ndt_value_array_del(ndt_value_t *types, int64_t ntypes);
680
+ NDTYPES_API void ndt_value_array_del(const ndt_value_t *types, int64_t ntypes);
607
681
 
608
682
  NDTYPES_API ndt_value_t *ndt_value_from_number(enum ndt_value tag, char *v, ndt_context_t *ctx);
609
683
  NDTYPES_API ndt_value_t *ndt_value_from_string(char *v, ndt_context_t *ctx);
@@ -613,8 +687,8 @@ NDTYPES_API int ndt_value_mem_equal(const ndt_value_t *x, const ndt_value_t *y);
613
687
  NDTYPES_API int ndt_value_compare(const ndt_value_t *x, const ndt_value_t *y);
614
688
 
615
689
  /* Type array */
616
- NDTYPES_API void ndt_type_array_clear(ndt_t **types, int64_t shape);
617
- NDTYPES_API void ndt_type_array_del(ndt_t **types, int64_t shape);
690
+ NDTYPES_API void ndt_type_array_clear(const ndt_t **types, int64_t shape);
691
+ NDTYPES_API void ndt_type_array_del(const ndt_t **types, int64_t shape);
618
692
 
619
693
 
620
694
  /*****************************************************************************/
@@ -631,17 +705,24 @@ NDTYPES_API uint16_t ndt_alignof_encoding(enum ndt_encoding encoding);
631
705
  /* Predicates */
632
706
  /*****************************************************************************/
633
707
 
708
+ NDTYPES_API bool ndt_is_static(const ndt_t *t);
709
+ NDTYPES_API bool ndt_is_static_tag(enum ndt tag);
710
+
634
711
  NDTYPES_API int ndt_is_abstract(const ndt_t *t);
635
712
  NDTYPES_API int ndt_is_concrete(const ndt_t *t);
636
713
 
637
714
  NDTYPES_API int ndt_is_optional(const ndt_t *t);
638
715
  NDTYPES_API int ndt_subtree_is_optional(const ndt_t *t);
716
+ NDTYPES_API int ndt_is_pointer_free(const ndt_t *t);
717
+ NDTYPES_API int ndt_is_ref_free(const ndt_t *t);
639
718
 
640
719
  NDTYPES_API int ndt_is_ndarray(const ndt_t *t);
641
720
  NDTYPES_API int ndt_is_c_contiguous(const ndt_t *t);
642
721
  NDTYPES_API int ndt_is_f_contiguous(const ndt_t *t);
643
722
  NDTYPES_API int ndt_really_fortran(const ndt_t *t);
644
723
 
724
+ NDTYPES_API int ndt_is_var_contiguous(const ndt_t *t);
725
+
645
726
  NDTYPES_API int ndt_is_scalar(const ndt_t *t);
646
727
  NDTYPES_API int ndt_is_signed(const ndt_t *t);
647
728
  NDTYPES_API int ndt_is_unsigned(const ndt_t *t);
@@ -657,23 +738,34 @@ NDTYPES_API int ndt_is_big_endian(const ndt_t *t);
657
738
  /* Functions */
658
739
  /*****************************************************************************/
659
740
 
660
- NDTYPES_API ndt_t *ndt_copy(const ndt_t *t, ndt_context_t *ctx);
661
- NDTYPES_API ndt_t *ndt_copy_contiguous(const ndt_t *t, ndt_context_t *ctx);
662
- NDTYPES_API ndt_t *ndt_copy_contiguous_dtype(const ndt_t *t, ndt_t *dtype, ndt_context_t *ctx);
663
- NDTYPES_API ndt_t *ndt_copy_abstract_var_dtype(const ndt_t *t, ndt_t *dtype, ndt_context_t *ctx);
741
+ NDTYPES_API const ndt_t *ndt_copy(const ndt_t *t, ndt_context_t *ctx);
742
+ NDTYPES_API const ndt_t *ndt_copy_contiguous(const ndt_t *t, int64_t linear_index, ndt_context_t *ctx);
743
+ NDTYPES_API const ndt_t *ndt_copy_contiguous_dtype(const ndt_t *t, const ndt_t *dtype, int64_t linear_index, ndt_context_t *ctx);
744
+ NDTYPES_API const ndt_t *ndt_copy_contiguous_at(const ndt_t *t, int n, const ndt_t *dtype, ndt_context_t *ctx);
745
+ NDTYPES_API const ndt_t *ndt_copy_abstract_var_dtype(const ndt_t *t, const ndt_t *dtype, ndt_context_t *ctx);
746
+
747
+ NDTYPES_API const ndt_t *ndt_convert_to_var_elem(const ndt_t *t, const ndt_t *type, int64_t index, ndt_context_t *ctx);
748
+
664
749
 
665
750
  NDTYPES_API int ndt_equal(const ndt_t *t, const ndt_t *u);
666
751
  NDTYPES_API int ndt_match(const ndt_t *p, const ndt_t *c, ndt_context_t *ctx);
667
752
  NDTYPES_API int ndt_typecheck(ndt_apply_spec_t *spec, const ndt_t *sig,
668
- const ndt_t *in[], const int nin,
753
+ const ndt_t *types[], const int64_t li[],
754
+ const int nin, const int nout, bool check_broadcast,
669
755
  const ndt_constraint_t *c, const void *args,
670
756
  ndt_context_t *ctx);
757
+ NDTYPES_API int ndt_fast_unary_fixed_typecheck(ndt_apply_spec_t *spec, const ndt_t *sig,
758
+ const ndt_t *types[], const int nin, const int nout,
759
+ const bool check_broadcast, ndt_context_t *ctx);
671
760
  NDTYPES_API int ndt_fast_binary_fixed_typecheck(ndt_apply_spec_t *spec, const ndt_t *sig,
672
- const ndt_t *in[], const int nin, ndt_t *dtype,
673
- ndt_context_t *ctx);
761
+ const ndt_t *types[], const int nin, const int nout,
762
+ const bool check_broadcast, ndt_context_t *ctx);
674
763
 
675
764
  NDTYPES_API int64_t ndt_itemsize(const ndt_t *t);
676
765
 
766
+ NDTYPES_API const ndt_t *ndt_unify(const ndt_t *t, const ndt_t *u, ndt_context_t *ctx);
767
+ NDTYPES_API const ndt_t *ndt_unify_replace_any(const ndt_t *t, const ndt_t *u, ndt_context_t *ctx);
768
+
677
769
 
678
770
  /*****************************************************************************/
679
771
  /* Input/Output */
@@ -696,8 +788,7 @@ NDTYPES_API char *ndt_indent(const ndt_t *t, ndt_context_t *ctx);
696
788
  NDTYPES_API char *ndt_ast_repr(const ndt_t *t, ndt_context_t *ctx);
697
789
 
698
790
  NDTYPES_API int64_t ndt_serialize(char **dest, const ndt_t * const t, ndt_context_t *ctx);
699
- NDTYPES_API ndt_t *ndt_deserialize(ndt_meta_t *m, const char * const ptr, int64_t len,
700
- ndt_context_t *ctx);
791
+ NDTYPES_API const ndt_t *ndt_deserialize(const char * const ptr, int64_t len, ndt_context_t *ctx);
701
792
 
702
793
 
703
794
  /*****************************************************************************/
@@ -710,10 +801,10 @@ typedef struct {
710
801
  } ndt_typedef_t;
711
802
 
712
803
  /* Typedef for nominal types */
713
- NDTYPES_API int ndt_typedef_add(const char *name, ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
804
+ NDTYPES_API int ndt_typedef_add(const char *name, const ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
714
805
  NDTYPES_API const ndt_typedef_t *ndt_typedef_find(const char *name, ndt_context_t *ctx);
715
806
 
716
- NDTYPES_API int ndt_typedef(const char *name, ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
807
+ NDTYPES_API int ndt_typedef(const char *name, const ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
717
808
  NDTYPES_API int ndt_typedef_from_string(const char *name, const char *type, const ndt_methods_t *m, ndt_context_t *ctx);
718
809
 
719
810
 
@@ -721,11 +812,14 @@ NDTYPES_API int ndt_typedef_from_string(const char *name, const char *type, cons
721
812
  /* Allocate types */
722
813
  /*****************************************************************************/
723
814
 
724
- NDTYPES_API ndt_t *ndt_new(enum ndt tag, ndt_context_t *ctx);
815
+ NDTYPES_API ndt_t *ndt_new(enum ndt tag, uint32_t flags, ndt_context_t *ctx);
725
816
  NDTYPES_API ndt_t *ndt_function_new(int64_t nargs, ndt_context_t *ctx);
726
- NDTYPES_API ndt_t *ndt_tuple_new(enum ndt_variadic flag, int64_t shape, ndt_context_t *ctx);
727
- NDTYPES_API ndt_t *ndt_record_new(enum ndt_variadic flag, int64_t shape, ndt_context_t *ctx);
728
- NDTYPES_API void ndt_del(ndt_t *t);
817
+ NDTYPES_API ndt_t *ndt_tuple_new(enum ndt_variadic flag, int64_t shape, bool opt, ndt_context_t *ctx);
818
+ NDTYPES_API ndt_t *ndt_record_new(enum ndt_variadic flag, int64_t shape, bool opt, ndt_context_t *ctx);
819
+ NDTYPES_API ndt_t *ndt_union_new(int64_t ntags, bool opt, ndt_context_t *ctx);
820
+ NDTYPES_API void ndt_incref(const ndt_t *t);
821
+ NDTYPES_API void ndt_decref(const ndt_t *t);
822
+ NDTYPES_API void ndt_move(const ndt_t **dst, const ndt_t *src);
729
823
 
730
824
 
731
825
  /*****************************************************************************/
@@ -733,71 +827,74 @@ NDTYPES_API void ndt_del(ndt_t *t);
733
827
  /*****************************************************************************/
734
828
 
735
829
  /* Special types */
736
- NDTYPES_API ndt_t *ndt_option(ndt_t *type);
737
- NDTYPES_API ndt_t *ndt_module(char *name, ndt_t *type, ndt_context_t *ctx);
738
- NDTYPES_API ndt_t *ndt_function(ndt_t * const *types, int64_t nargs, int64_t nin, int64_t nout, ndt_context_t *ctx);
830
+ NDTYPES_API const ndt_t *ndt_module(char *name, const ndt_t *type, ndt_context_t *ctx);
831
+ NDTYPES_API const ndt_t *ndt_function(const ndt_t **types, int64_t nargs, int64_t nin, int64_t nout, ndt_context_t *ctx);
739
832
 
740
833
  /* Any */
741
- NDTYPES_API ndt_t *ndt_any_kind(ndt_context_t *ctx);
834
+ NDTYPES_API const ndt_t *ndt_any_kind(bool opt, ndt_context_t *ctx);
742
835
 
743
836
  /* Dimensions */
744
- NDTYPES_API ndt_t *ndt_to_fortran(const ndt_t *type, ndt_context_t *ctx);
745
- NDTYPES_API ndt_t *ndt_fixed_dim(ndt_t *type, int64_t shape, int64_t step, ndt_context_t *ctx);
746
- NDTYPES_API ndt_t *ndt_fixed_dim_tag(ndt_t *type, enum ndt_contig tag, int64_t shape, int64_t step, ndt_context_t *ctx);
837
+ NDTYPES_API const ndt_t *ndt_to_fortran(const ndt_t *type, ndt_context_t *ctx);
838
+ NDTYPES_API const ndt_t *ndt_fixed_dim(const ndt_t *type, int64_t shape, int64_t step, ndt_context_t *ctx);
839
+ NDTYPES_API const ndt_t *ndt_fixed_dim_tag(const ndt_t *type, enum ndt_contig tag, int64_t shape, int64_t step, ndt_context_t *ctx);
747
840
 
748
- NDTYPES_API ndt_t *ndt_abstract_var_dim(ndt_t *type, ndt_context_t *ctx);
841
+ NDTYPES_API const ndt_t *ndt_abstract_var_dim(const ndt_t *type, bool opt, ndt_context_t *ctx);
749
842
  NDTYPES_API int64_t ndt_var_indices(int64_t *res_start, int64_t *res_step, const ndt_t *t,
750
843
  int64_t index, ndt_context_t *ctx);
844
+ NDTYPES_API int64_t ndt_var_indices_non_empty(int64_t *res_start, int64_t *res_step, const ndt_t *t,
845
+ int64_t index, ndt_context_t *ctx);
751
846
  NDTYPES_API ndt_slice_t *ndt_var_add_slice(int32_t *nslices, const ndt_t *t,
752
847
  int64_t start, int64_t stop, int64_t step,
753
848
  ndt_context_t *ctx);
754
- NDTYPES_API ndt_t *ndt_var_dim(ndt_t *type,
755
- enum ndt_offsets flag, int32_t noffsets, const int32_t *offsets,
756
- int32_t nslices, ndt_slice_t *slices,
757
- ndt_context_t *ctx);
849
+ NDTYPES_API const ndt_t *ndt_var_dim(const ndt_t *type, const ndt_offsets_t *offsets,
850
+ int32_t nslices, ndt_slice_t *slices, bool opt,
851
+ ndt_context_t *ctx);
852
+
853
+ NDTYPES_API const ndt_t *ndt_symbolic_dim(char *name, const ndt_t *type, ndt_context_t *ctx);
854
+ NDTYPES_API const ndt_t *ndt_symbolic_dim_tag(char *name, const ndt_t *type, enum ndt_contig tag, ndt_context_t *ctx);
855
+ NDTYPES_API const ndt_t *ndt_ellipsis_dim(char *name, const ndt_t *type, ndt_context_t *ctx);
856
+ NDTYPES_API const ndt_t *ndt_ellipsis_dim_tag(char *name, const ndt_t *type, enum ndt_contig tag, ndt_context_t *ctx);
758
857
 
759
- NDTYPES_API ndt_t *ndt_symbolic_dim(char *name, ndt_t *type, ndt_context_t *ctx);
760
- NDTYPES_API ndt_t *ndt_symbolic_dim_tag(char *name, ndt_t *type, enum ndt_contig tag, ndt_context_t *ctx);
761
- NDTYPES_API ndt_t *ndt_ellipsis_dim(char *name, ndt_t *type, ndt_context_t *ctx);
762
- NDTYPES_API ndt_t *ndt_ellipsis_dim_tag(char *name, ndt_t *type, enum ndt_contig tag, ndt_context_t *ctx);
858
+ NDTYPES_API const ndt_t *ndt_array(const ndt_t *type, bool opt, ndt_context_t *ctx);
763
859
 
764
860
  /* Dtypes */
765
- NDTYPES_API ndt_t *ndt_tuple(enum ndt_variadic flag, ndt_field_t *fields, int64_t shape,
766
- uint16_opt_t align, uint16_opt_t pack, ndt_context_t *ctx);
767
- NDTYPES_API ndt_t *ndt_record(enum ndt_variadic flag, ndt_field_t *fields, int64_t shape,
768
- uint16_opt_t align, uint16_opt_t pack, ndt_context_t *ctx);
861
+ NDTYPES_API const ndt_t *ndt_tuple(enum ndt_variadic flag, const ndt_field_t *fields, int64_t shape,
862
+ uint16_opt_t align, uint16_opt_t pack, bool opt, ndt_context_t *ctx);
863
+ NDTYPES_API const ndt_t *ndt_record(enum ndt_variadic flag, const ndt_field_t *fields, int64_t shape,
864
+ uint16_opt_t align, uint16_opt_t pack, bool opt, ndt_context_t *ctx);
865
+ NDTYPES_API const ndt_t *ndt_union(const ndt_field_t *fields, int64_t ntags, bool opt, ndt_context_t *ctx);
769
866
 
770
- NDTYPES_API ndt_t *ndt_ref(ndt_t *type, ndt_context_t *ctx);
771
- NDTYPES_API ndt_t *ndt_constr(char *name, ndt_t *type, ndt_context_t *ctx);
772
- NDTYPES_API ndt_t *ndt_nominal(char *name, ndt_t *type, ndt_context_t *ctx);
867
+ NDTYPES_API const ndt_t *ndt_ref(const ndt_t *type, bool opt, ndt_context_t *ctx);
868
+ NDTYPES_API const ndt_t *ndt_constr(char *name, const ndt_t *type, bool opt, ndt_context_t *ctx);
869
+ NDTYPES_API const ndt_t *ndt_nominal(char *name, const ndt_t *type, bool opt, ndt_context_t *ctx);
773
870
 
774
871
  /* Scalars */
775
- NDTYPES_API ndt_t *ndt_scalar_kind(ndt_context_t *ctx);
872
+ NDTYPES_API const ndt_t *ndt_scalar_kind(bool opt, ndt_context_t *ctx);
776
873
 
777
- NDTYPES_API ndt_t *ndt_categorical(ndt_value_t *types, int64_t ntypes, ndt_context_t *ctx);
874
+ NDTYPES_API const ndt_t *ndt_categorical(const ndt_value_t *types, int64_t ntypes, bool opt, ndt_context_t *ctx);
778
875
 
779
- NDTYPES_API ndt_t *ndt_fixed_string_kind(ndt_context_t *ctx);
780
- NDTYPES_API ndt_t *ndt_fixed_string(int64_t size, enum ndt_encoding encoding, ndt_context_t *ctx);
876
+ NDTYPES_API const ndt_t *ndt_fixed_string_kind(bool opt, ndt_context_t *ctx);
877
+ NDTYPES_API const ndt_t *ndt_fixed_string(int64_t size, enum ndt_encoding encoding, bool opt, ndt_context_t *ctx);
781
878
 
782
- NDTYPES_API ndt_t *ndt_fixed_bytes_kind(ndt_context_t *ctx);
783
- NDTYPES_API ndt_t *ndt_fixed_bytes(int64_t size, uint16_opt_t align, ndt_context_t *ctx);
879
+ NDTYPES_API const ndt_t *ndt_fixed_bytes_kind(bool opt, ndt_context_t *ctx);
880
+ NDTYPES_API const ndt_t *ndt_fixed_bytes(int64_t size, uint16_opt_t align, bool opt, ndt_context_t *ctx);
784
881
 
785
- NDTYPES_API ndt_t *ndt_string(ndt_context_t *ctx);
786
- NDTYPES_API ndt_t *ndt_bytes(uint16_opt_t target_align, ndt_context_t *ctx);
787
- NDTYPES_API ndt_t *ndt_char(enum ndt_encoding encoding, ndt_context_t *ctx);
882
+ NDTYPES_API const ndt_t *ndt_string(bool opt, ndt_context_t *ctx);
883
+ NDTYPES_API const ndt_t *ndt_bytes(uint16_opt_t target_align, bool opt, ndt_context_t *ctx);
884
+ NDTYPES_API const ndt_t *ndt_char(enum ndt_encoding encoding, bool opt, ndt_context_t *ctx);
788
885
 
789
- NDTYPES_API ndt_t *ndt_signed_kind(ndt_context_t *ctx);
790
- NDTYPES_API ndt_t *ndt_unsigned_kind(ndt_context_t *ctx);
791
- NDTYPES_API ndt_t *ndt_float_kind(ndt_context_t *ctx);
792
- NDTYPES_API ndt_t *ndt_complex_kind(ndt_context_t *ctx);
886
+ NDTYPES_API const ndt_t *ndt_signed_kind(uint32_t flags, ndt_context_t *ctx);
887
+ NDTYPES_API const ndt_t *ndt_unsigned_kind(uint32_t flags, ndt_context_t *ctx);
888
+ NDTYPES_API const ndt_t *ndt_float_kind(uint32_t flags, ndt_context_t *ctx);
889
+ NDTYPES_API const ndt_t *ndt_complex_kind(uint32_t flags, ndt_context_t *ctx);
793
890
 
794
- NDTYPES_API ndt_t *ndt_primitive(enum ndt tag, uint32_t flags, ndt_context_t *ctx);
795
- NDTYPES_API ndt_t *ndt_signed(int size, uint32_t flags, ndt_context_t *ctx);
796
- NDTYPES_API ndt_t *ndt_unsigned(int size, uint32_t flags, ndt_context_t *ctx);
797
- NDTYPES_API ndt_t *ndt_from_alias(enum ndt_alias tag, uint32_t flags, ndt_context_t *ctx);
891
+ NDTYPES_API const ndt_t *ndt_primitive(enum ndt tag, uint32_t flags, ndt_context_t *ctx);
892
+ NDTYPES_API const ndt_t *ndt_signed(int size, uint32_t flags, ndt_context_t *ctx);
893
+ NDTYPES_API const ndt_t *ndt_unsigned(int size, uint32_t flags, ndt_context_t *ctx);
894
+ NDTYPES_API const ndt_t *ndt_from_alias(enum ndt_alias tag, uint32_t flags, ndt_context_t *ctx);
798
895
 
799
896
  /* Type variable */
800
- NDTYPES_API ndt_t *ndt_typevar(char *name, ndt_context_t *ctx);
897
+ NDTYPES_API const ndt_t *ndt_typevar(char *name, ndt_context_t *ctx);
801
898
 
802
899
 
803
900
  /******************************************************************************/
@@ -810,14 +907,14 @@ NDTYPES_API ndt_t *ndt_typevar(char *name, ndt_context_t *ctx);
810
907
  * Metadata is read from the type string and managed by the type. This is
811
908
  * convenient but can waste a lot of space when offset arrays are large.
812
909
  */
813
- NDTYPES_API ndt_t *ndt_from_file(const char *name, ndt_context_t *ctx);
814
- NDTYPES_API ndt_t *ndt_from_string(const char *input, ndt_context_t *ctx);
815
- NDTYPES_API ndt_t *ndt_from_bpformat(const char *input, ndt_context_t *ctx);
910
+ NDTYPES_API const ndt_t *ndt_from_file(const char *name, ndt_context_t *ctx);
911
+ NDTYPES_API const ndt_t *ndt_from_string(const char *input, ndt_context_t *ctx);
912
+ NDTYPES_API const ndt_t *ndt_from_bpformat(const char *input, ndt_context_t *ctx);
816
913
  NDTYPES_API char *ndt_to_bpformat(const ndt_t *t, ndt_context_t *ctx);
817
914
  NDTYPES_API int ndt_to_nbformat(char **sig, char **dtype, const ndt_t *t, ndt_context_t *ctx);
818
915
 
819
916
  /* Unstable API */
820
- NDTYPES_API ndt_t *ndt_from_string_v(const char *input, ndt_context_t *ctx);
917
+ NDTYPES_API const ndt_t *ndt_from_string_v(const char *input, ndt_context_t *ctx);
821
918
 
822
919
 
823
920
  /*
@@ -825,13 +922,15 @@ NDTYPES_API ndt_t *ndt_from_string_v(const char *input, ndt_context_t *ctx);
825
922
  * The type still has pointers to the metadata. This scheme is used for sharing
826
923
  * offsets between copies or subtypes of a type.
827
924
  */
828
- NDTYPES_API ndt_t *ndt_from_file_fill_meta(ndt_meta_t *m, const char *name, ndt_context_t *ctx);
829
- NDTYPES_API ndt_t *ndt_from_string_fill_meta(ndt_meta_t *m, const char *input, ndt_context_t *ctx);
925
+ NDTYPES_API const ndt_t *ndt_from_file_fill_meta(ndt_meta_t *m, const char *name, ndt_context_t *ctx);
926
+ NDTYPES_API const ndt_t *ndt_from_string_fill_meta(ndt_meta_t *m, const char *input, ndt_context_t *ctx);
830
927
 
831
928
  /* Metadata is provided and managed by an external source. */
832
- NDTYPES_API ndt_t *ndt_from_metadata_and_dtype(const ndt_meta_t *m, const char *dtype, ndt_context_t *ctx);
929
+ NDTYPES_API const ndt_t *ndt_from_metadata_and_dtype(const ndt_meta_t *m, const char *dtype, ndt_context_t *ctx);
930
+ NDTYPES_API const ndt_t *ndt_from_metadata_opt_and_dtype(const ndt_meta_t *m, bool *opt, const ndt_t *dtype, ndt_context_t *ctx);
833
931
 
834
932
  NDTYPES_API ndt_meta_t *ndt_meta_new(ndt_context_t *ctx);
933
+ NDTYPES_API void ndt_meta_clear(ndt_meta_t *m);
835
934
  NDTYPES_API void ndt_meta_del(ndt_meta_t *m);
836
935
 
837
936
 
@@ -887,7 +986,17 @@ typedef struct {
887
986
  uint8_t *data;
888
987
  } ndt_bytes_t;
889
988
 
989
+ typedef struct {
990
+ int64_t shape;
991
+ char *data;
992
+ } ndt_array_t;
993
+
890
994
  typedef int64_t ndt_categorical_t;
891
995
 
892
996
 
997
+ #ifdef __cplusplus
998
+ } /* END extern "C" */
999
+ #endif
1000
+
1001
+
893
1002
  #endif /* NDTYPES_H */