ndtypes 0.2.0dev4 → 0.2.0dev5

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: 1e4f279735d63cdb4899d3df98a78dcde783ea64
4
- data.tar.gz: 48e2f95ae6030f6c333ffbf88d8b253f6950830b
3
+ metadata.gz: 7dde7a1b96db3ec81d383486bbc07eb83073290f
4
+ data.tar.gz: 84e6162b7e364d6254a6de3c0ba3518a92b73861
5
5
  SHA512:
6
- metadata.gz: 9f23ebcc82f55ddd54e2417a106e4ab0bf9804ee5c8e951e65f6366b4530bc60a6d0e1992ed5aad32d734ff709f62473e6ce6b9fe2a4ac8f4f8b6c7417fcf008
7
- data.tar.gz: 5006d479c176243f23e9956a25890b0caf3df0b1cee7a1546fccc7f1e8b64dd6bfad3b8dddfa796146e9a296cbb32904fe850e84465a77ec9968bd748fec8402
6
+ metadata.gz: 4d69c91b4bcb0a37b86b134f8c283d83d780681866082b52bcd50259163493ee88b4a134aee3f17143b499ee24ca35fa17d9e7d168a4144209cee79ae0e7370e
7
+ data.tar.gz: 03fbb84d4998cfd564a08ebe10d2641158516128e44cb280730cd5fb9d7826632f536a89cc031fae13b37c87662770ee7737af5dd87afab81ee78b311969674b
data/Rakefile CHANGED
@@ -107,7 +107,7 @@ task :clobber do |task|
107
107
  end
108
108
  end
109
109
 
110
- task :deploy do |task|
110
+ task :develop do |task|
111
111
  ext_ndtypes = "ext/ruby_ndtypes/ndtypes"
112
112
  puts "deleting previously created #{ext_ndtypes} directory..."
113
113
  FileUtils.rm_rf(ext_ndtypes)
@@ -17,10 +17,10 @@ Dir.chdir(File.join(File.dirname(__FILE__) + "/ndtypes")) do
17
17
  if unix?
18
18
  ["libndtypes", "libndtypes/compat", "libndtypes/serialize"].each do |f|
19
19
  Dir.chdir(f) do
20
- Dir.mkdir(".objs") unless Dir.exists? ".objs"
20
+ Dir.mkdir(".objs") unless Dir.exists? ".objs"
21
21
  end
22
22
  end
23
-
23
+
24
24
  system("./configure --prefix=#{File.expand_path("../")} --with-docs=no")
25
25
  system("make")
26
26
  system("make install")
@@ -30,11 +30,14 @@ Dir.chdir(File.join(File.dirname(__FILE__) + "/ndtypes")) do
30
30
  end
31
31
 
32
32
  $INSTALLFILES = [
33
- ["ruby_ndtypes.h", "$(archdir)"]
33
+ ["ruby_ndtypes.h", "$(archdir)"],
34
+ ["ndtypes.h", "$(archdir)"]
34
35
  ]
36
+
35
37
  binaries = File.expand_path(File.join(File.dirname(__FILE__) + "/lib/"))
36
38
  headers = File.expand_path(File.join(File.dirname(__FILE__) + "/include/"))
37
39
  $LOAD_PATH << File.expand_path(binaries)
40
+ append_ldflags("-Wl,-rpath #{binaries}")
38
41
 
39
42
  ["ndtypes"].each do |lib|
40
43
  find_library(lib, nil, binaries)
@@ -45,6 +48,10 @@ end
45
48
  have_header(header)
46
49
  end
47
50
 
51
+ FileUtils.copy_file File.expand_path(File.join(File.dirname(__FILE__) +
52
+ "/ruby_ndtypes.h")),
53
+ "#{headers}/ruby_ndtypes.h"
54
+
48
55
  dir_config("ndtypes", [headers], [binaries])
49
56
 
50
57
  basenames = %w{gc_guard ruby_ndtypes}
@@ -0,0 +1,893 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2017-2018, plures
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ #ifndef NDTYPES_H
35
+ #define NDTYPES_H
36
+
37
+
38
+ #include <stdio.h>
39
+ #include <stdlib.h>
40
+ #include <stdint.h>
41
+ #include <limits.h>
42
+ #include <stdbool.h>
43
+ #include <stddef.h>
44
+ #include <complex.h>
45
+
46
+
47
+ #if SIZE_MAX > ULLONG_MAX
48
+ #error "need SIZE_MAX <= ULLONG_MAX"
49
+ #endif
50
+
51
+ #if SIZE_MAX == UINT32_MAX
52
+ typedef int32_t ndt_ssize_t;
53
+ #define PRI_ndt_ssize PRIi32
54
+ #elif SIZE_MAX == UINT64_MAX
55
+ typedef int64_t ndt_ssize_t;
56
+ #define PRI_ndt_ssize PRIi64
57
+ #else
58
+ #error "need SIZE_MAX == UINT32_MAX or SIZE_MAX == UINT64_MAX"
59
+ #endif
60
+
61
+ #ifdef _MSC_VER
62
+ #if defined (NDT_EXPORT)
63
+ #define NDTYPES_API __declspec(dllexport)
64
+ #elif defined(NDT_IMPORT)
65
+ #define NDTYPES_API __declspec(dllimport)
66
+ #else
67
+ #define NDTYPES_API
68
+ #endif
69
+
70
+ typedef _Dcomplex ndt_complex128_t;
71
+ typedef _Fcomplex ndt_complex64_t;
72
+ #define alignof __alignof
73
+ #define alignas(n) __declspec(align(n))
74
+ #define MAX_ALIGN 8
75
+ #define NDT_SYS_BIG_ENDIAN 0
76
+ #else
77
+ #define NDTYPES_API
78
+
79
+ #if !defined(__APPLE__) && !defined(__STDC_IEC_559__)
80
+ #error "ndtypes requires IEEE floating point arithmetic"
81
+ #endif
82
+ #include <stdalign.h>
83
+ typedef double complex ndt_complex128_t;
84
+ typedef float complex ndt_complex64_t;
85
+ #define MAX_ALIGN (alignof(max_align_t))
86
+ #define NDT_SYS_BIG_ENDIAN 0
87
+ #endif
88
+
89
+ #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \
90
+ defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER)
91
+ #define NDT_PRAGMA(x) _Pragma(x)
92
+ #define NDT_HIDE_SYMBOLS_START "GCC visibility push(hidden)"
93
+ #define NDT_HIDE_SYMBOLS_END "GCC visibility pop"
94
+ #else
95
+ #define NDT_PRAGMA(x)
96
+ #define NDT_HIDE_SYMBOLS_START
97
+ #define NDT_HIDE_SYMBOLS_END
98
+ #endif
99
+
100
+
101
+ /*****************************************************************************/
102
+ /* Datashape */
103
+ /*****************************************************************************/
104
+
105
+ #define NDT_MAX_DIM 128
106
+ #define NDT_MAX_ARGS 128
107
+
108
+ #define NDT_LITTLE_ENDIAN 0x00000001U
109
+ #define NDT_BIG_ENDIAN 0x00000002U
110
+ #define NDT_OPTION 0x00000004U
111
+ #define NDT_SUBTREE_OPTION 0x00000008U
112
+ #define NDT_ELLIPSIS 0x00000010U
113
+
114
+
115
+ /* Types: ndt_t */
116
+ typedef struct _ndt ndt_t;
117
+ typedef struct _ndt_context ndt_context_t;
118
+
119
+
120
+ /* Internal option type */
121
+ enum ndt_option {
122
+ None,
123
+ Some
124
+ };
125
+
126
+ typedef struct {
127
+ enum ndt_option tag;
128
+ char Some;
129
+ } char_opt_t;
130
+
131
+ typedef struct {
132
+ enum ndt_option tag;
133
+ int64_t Some;
134
+ } int64_opt_t;
135
+
136
+ typedef struct {
137
+ enum ndt_option tag;
138
+ uint16_t Some;
139
+ } uint16_opt_t;
140
+
141
+
142
+ /* Flag for variadic tuples and records */
143
+ enum ndt_variadic {
144
+ Nonvariadic,
145
+ Variadic
146
+ };
147
+
148
+ /* Ownership flag for var dim offsets */
149
+ enum ndt_offsets {
150
+ InternalOffsets,
151
+ ExternalOffsets,
152
+ };
153
+
154
+ /*
155
+ * Collect offsets during parsing for transferring ownership to an external
156
+ * resource manager later.
157
+ *
158
+ * The arrays are addressed by t->ndim-1, where t->ndim > 0. It follows that
159
+ * offsets[0] are the offsets of the innermost dimension and offsets[ndims-1]
160
+ * the offsets of the outermost dimension.
161
+ */
162
+ 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 */
166
+ } ndt_meta_t;
167
+
168
+
169
+ /* Encoding for characters and strings */
170
+ enum ndt_encoding {
171
+ Ascii,
172
+ Utf8,
173
+ Utf16,
174
+ Utf32,
175
+ Ucs2,
176
+ };
177
+
178
+
179
+ /* Datashape kinds */
180
+ enum ndt {
181
+ /* Name space */
182
+ Module,
183
+
184
+ /* Function */
185
+ Function,
186
+
187
+ /* Any */
188
+ AnyKind,
189
+ FixedDim,
190
+ VarDim,
191
+ SymbolicDim,
192
+ EllipsisDim,
193
+
194
+ /* Dtype */
195
+ Tuple,
196
+ Record,
197
+ Ref,
198
+ Constr,
199
+ Nominal,
200
+
201
+ /* Scalar */
202
+ ScalarKind,
203
+ Categorical,
204
+
205
+ FixedStringKind,
206
+ FixedString,
207
+
208
+ FixedBytesKind,
209
+ FixedBytes,
210
+
211
+ String,
212
+ Bytes,
213
+ Char,
214
+
215
+ /* Primitive */
216
+ Bool,
217
+
218
+ SignedKind,
219
+ Int8,
220
+ Int16,
221
+ Int32,
222
+ Int64,
223
+
224
+ UnsignedKind,
225
+ Uint8,
226
+ Uint16,
227
+ Uint32,
228
+ Uint64,
229
+
230
+ FloatKind,
231
+ Float16,
232
+ Float32,
233
+ Float64,
234
+
235
+ ComplexKind,
236
+ Complex32,
237
+ Complex64,
238
+ Complex128,
239
+
240
+ /* Dtype variable */
241
+ Typevar,
242
+ };
243
+
244
+ enum ndt_alias {
245
+ Size,
246
+ Intptr,
247
+ Uintptr
248
+ };
249
+
250
+ /* Protect access to concrete type fields. */
251
+ enum ndt_access {
252
+ Abstract,
253
+ Concrete
254
+ };
255
+
256
+ /*
257
+ * Require C or Fortran contiguity in abstract signatures. For concrete types
258
+ * the field is irrelevant and set to RequireNA.
259
+ */
260
+ enum ndt_contig {
261
+ RequireNA,
262
+ RequireC,
263
+ RequireF
264
+ };
265
+
266
+ /* Tuple or record field, used in the parser. */
267
+ typedef struct {
268
+ enum ndt_access access;
269
+ char *name;
270
+ ndt_t *type;
271
+ struct {
272
+ uint16_t align;
273
+ bool explicit_align;
274
+ uint16_t pad;
275
+ bool explicit_pad;
276
+ } Concrete;
277
+ } ndt_field_t;
278
+
279
+ /* Selected values for the categorical type. */
280
+ enum ndt_value {
281
+ ValBool,
282
+ ValInt64,
283
+ ValFloat64,
284
+ ValString,
285
+ ValNA,
286
+ };
287
+
288
+ typedef struct {
289
+ enum ndt_value tag;
290
+ union {
291
+ bool ValBool;
292
+ int64_t ValInt64;
293
+ double ValFloat64;
294
+ char *ValString;
295
+ };
296
+ } ndt_value_t;
297
+
298
+ typedef struct {
299
+ int64_t start;
300
+ int64_t stop;
301
+ int64_t step;
302
+ } ndt_slice_t;
303
+
304
+ /*
305
+ * Constraint support for function signatures. A constraint needs to specify:
306
+ *
307
+ * 1) The symbols in the function arguments and return value(s) that are
308
+ * needed to decide the constraint.
309
+ * 2) ndt_typecheck() resolves the 'nin' incoming symbols and passes their
310
+ * shape values in the 'shapes' array. It then calls the constraint
311
+ * function.
312
+ * 3) The constraint function can look at the incoming shapes as well
313
+ * as the incoming function arguments (usually xnd_t).
314
+ * 4) The function then needs to decide whether the constraint is met; if so,
315
+ * it must fill in 'nout' shapes for the return symbols (if any).
316
+ * 5) ndt_typecheck() uses the resolved 'nout' shapes to update the symbol
317
+ * table and now has sufficient information to compute the return type.
318
+ */
319
+ #define NDT_MAX_SYMBOLS 16
320
+ typedef int (* ndt_func_constraint_t)(int64_t *shapes, const void *args, ndt_context_t *ctx);
321
+
322
+ typedef struct {
323
+ ndt_func_constraint_t f;
324
+ int nin;
325
+ int nout;
326
+ const char *symbols[NDT_MAX_SYMBOLS];
327
+ } ndt_constraint_t;
328
+
329
+ /* Object features for the Nominal type. */
330
+ typedef bool (* ndt_init_t)(void *dest, const void *src, ndt_context_t *);
331
+ typedef bool (* ndt_tdef_constraint_t)(const void *, ndt_context_t *);
332
+ typedef void *(* ndt_repr_t)(const void *, ndt_context_t *);
333
+
334
+ typedef struct {
335
+ ndt_init_t init;
336
+ ndt_tdef_constraint_t constraint;
337
+ ndt_repr_t repr;
338
+ } ndt_methods_t;
339
+
340
+
341
+ /* Datashape type */
342
+ struct _ndt {
343
+ /* Always defined */
344
+ enum ndt tag;
345
+ enum ndt_access access;
346
+ uint32_t flags;
347
+ int ndim;
348
+ /* Undefined if the type is abstract */
349
+ int64_t datasize;
350
+ uint16_t align;
351
+
352
+ /* Abstract */
353
+ union {
354
+ struct {
355
+ char *name;
356
+ ndt_t *type;
357
+ } Module;
358
+
359
+ struct {
360
+ bool elemwise;
361
+ int64_t nin;
362
+ int64_t nout;
363
+ int64_t nargs;
364
+ ndt_t **types;
365
+ } Function;
366
+
367
+ struct {
368
+ enum ndt_contig tag;
369
+ int64_t shape;
370
+ ndt_t *type;
371
+ } FixedDim;
372
+
373
+ struct {
374
+ ndt_t *type;
375
+ } VarDim;
376
+
377
+ struct {
378
+ enum ndt_contig tag;
379
+ char *name;
380
+ ndt_t *type;
381
+ } SymbolicDim;
382
+
383
+ struct {
384
+ enum ndt_contig tag;
385
+ char *name;
386
+ ndt_t *type;
387
+ } EllipsisDim;
388
+
389
+ struct {
390
+ enum ndt_variadic flag;
391
+ int64_t shape;
392
+ ndt_t **types;
393
+ } Tuple;
394
+
395
+ struct {
396
+ enum ndt_variadic flag;
397
+ int64_t shape;
398
+ char **names;
399
+ ndt_t **types;
400
+ } Record;
401
+
402
+ struct {
403
+ ndt_t *type;
404
+ } Ref;
405
+
406
+ struct {
407
+ char *name;
408
+ ndt_t *type;
409
+ } Constr;
410
+
411
+ struct {
412
+ char *name;
413
+ ndt_t *type;
414
+ const ndt_methods_t *meth;
415
+ } Nominal;
416
+
417
+ struct {
418
+ int64_t ntypes;
419
+ ndt_value_t *types;
420
+ } Categorical;
421
+
422
+ struct {
423
+ int64_t size;
424
+ enum ndt_encoding encoding;
425
+ } FixedString;
426
+
427
+ struct {
428
+ int64_t size;
429
+ uint16_t align;
430
+ } FixedBytes;
431
+
432
+ struct {
433
+ uint16_t target_align;
434
+ } Bytes;
435
+
436
+ struct {
437
+ enum ndt_encoding encoding;
438
+ } Char;
439
+
440
+ struct {
441
+ char *name;
442
+ } Typevar;
443
+ };
444
+
445
+ /* Concrete */
446
+ struct {
447
+ union {
448
+ struct {
449
+ int64_t itemsize;
450
+ int64_t step;
451
+ } FixedDim;
452
+
453
+ struct {
454
+ enum ndt_offsets flag;
455
+ int64_t itemsize;
456
+ int32_t noffsets;
457
+ const int32_t *offsets;
458
+ int nslices;
459
+ ndt_slice_t *slices;
460
+ } VarDim;
461
+
462
+ struct {
463
+ int64_t *offset;
464
+ uint16_t *align;
465
+ uint16_t *pad;
466
+ } Tuple;
467
+
468
+ struct {
469
+ int64_t *offset;
470
+ uint16_t *align;
471
+ uint16_t *pad;
472
+ } Record;
473
+ };
474
+ } Concrete;
475
+
476
+ alignas(MAX_ALIGN) char extra[];
477
+ };
478
+
479
+
480
+ /*****************************************************************************/
481
+ /* Context and error handling */
482
+ /*****************************************************************************/
483
+
484
+ #define NDT_Dynamic 0x00000001U
485
+
486
+ #define NDT_STATIC_CONTEXT(name) \
487
+ ndt_context_t name = { .flags=0, .err=NDT_Success, .msg=ConstMsg, .ConstMsg="Success" }
488
+
489
+ enum ndt_error {
490
+ NDT_Success,
491
+ NDT_ValueError,
492
+ NDT_TypeError,
493
+ NDT_InvalidArgumentError,
494
+ NDT_NotImplementedError,
495
+ NDT_IndexError,
496
+ NDT_LexError,
497
+ NDT_ParseError,
498
+ NDT_OSError,
499
+ NDT_RuntimeError,
500
+ NDT_MemoryError
501
+ };
502
+
503
+ enum ndt_msg {
504
+ ConstMsg,
505
+ DynamicMsg
506
+ };
507
+
508
+ struct _ndt_context {
509
+ uint32_t flags;
510
+ enum ndt_error err;
511
+ enum ndt_msg msg;
512
+ union {
513
+ const char *ConstMsg;
514
+ char *DynamicMsg;
515
+ };
516
+ };
517
+
518
+ NDTYPES_API ndt_context_t *ndt_context_new(void);
519
+ NDTYPES_API void ndt_context_del(ndt_context_t *ctx);
520
+
521
+ NDTYPES_API void ndt_err_format(ndt_context_t *ctx, enum ndt_error err, const char *fmt, ...);
522
+ NDTYPES_API int ndt_err_occurred(const ndt_context_t *ctx);
523
+ NDTYPES_API void ndt_err_clear(ndt_context_t *ctx);
524
+ NDTYPES_API void *ndt_memory_error(ndt_context_t *ctx);
525
+
526
+ NDTYPES_API const char *ndt_err_as_string(enum ndt_error err);
527
+ NDTYPES_API const char *ndt_context_msg(ndt_context_t *ctx);
528
+ NDTYPES_API void ndt_err_fprint(FILE *fp, ndt_context_t *ctx);
529
+
530
+ /* Unstable API */
531
+ NDTYPES_API void ndt_err_append(ndt_context_t *ctx, const char *msg);
532
+
533
+
534
+ /******************************************************************************/
535
+ /* Array conversions and properties */
536
+ /******************************************************************************/
537
+
538
+ /* This may go into xnd at some point. */
539
+ typedef struct {
540
+ int ndim;
541
+ int64_t itemsize;
542
+ int64_t shape[NDT_MAX_DIM];
543
+ int64_t strides[NDT_MAX_DIM];
544
+ int64_t steps[NDT_MAX_DIM];
545
+ } ndt_ndarray_t;
546
+
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 */
554
+
555
+ typedef struct {
556
+ uint32_t flags;
557
+ int nout;
558
+ int nbroadcast;
559
+ int outer_dims;
560
+ ndt_t *out[NDT_MAX_ARGS];
561
+ ndt_t *broadcast[NDT_MAX_ARGS];
562
+ } ndt_apply_spec_t;
563
+
564
+ NDTYPES_API extern const ndt_apply_spec_t ndt_apply_spec_empty;
565
+
566
+ NDTYPES_API ndt_apply_spec_t *ndt_apply_spec_new(ndt_context_t *ctx);
567
+ NDTYPES_API void ndt_apply_spec_clear(ndt_apply_spec_t *spec);
568
+ NDTYPES_API void ndt_apply_spec_del(ndt_apply_spec_t *spec);
569
+ 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);
572
+
573
+ NDTYPES_API void ndt_select_kernel_strategy(ndt_apply_spec_t *spec, const ndt_t *sig,
574
+ const ndt_t *in[], int nin);
575
+
576
+
577
+ /*****************************************************************************/
578
+ /* Utilities */
579
+ /*****************************************************************************/
580
+
581
+ /* String and formatting utilities */
582
+ NDTYPES_API char *ndt_strdup(const char *s, ndt_context_t *ctx);
583
+ NDTYPES_API char *ndt_asprintf(ndt_context_t *ctx, const char *fmt, ...);
584
+
585
+ /* Type functions (unstable API) */
586
+ NDTYPES_API const ndt_t *ndt_dtype(const ndt_t *t);
587
+ NDTYPES_API const ndt_t *ndt_hidden_dtype(const ndt_t *t);
588
+ 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
+ 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);
592
+
593
+
594
+ /*****************************************************************************/
595
+ /* Fields and values */
596
+ /*****************************************************************************/
597
+
598
+ /* Fields */
599
+ NDTYPES_API ndt_field_t *ndt_field(char *name, ndt_t *type, uint16_opt_t align,
600
+ uint16_opt_t pack, uint16_opt_t pad, ndt_context_t *ctx);
601
+ NDTYPES_API void ndt_field_del(ndt_field_t *field);
602
+ NDTYPES_API void ndt_field_array_del(ndt_field_t *fields, int64_t shape);
603
+
604
+ /* Typed values */
605
+ 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);
607
+
608
+ NDTYPES_API ndt_value_t *ndt_value_from_number(enum ndt_value tag, char *v, ndt_context_t *ctx);
609
+ NDTYPES_API ndt_value_t *ndt_value_from_string(char *v, ndt_context_t *ctx);
610
+ NDTYPES_API ndt_value_t *ndt_value_na(ndt_context_t *ctx);
611
+ NDTYPES_API int ndt_value_equal(const ndt_value_t *x, const ndt_value_t *y);
612
+ NDTYPES_API int ndt_value_mem_equal(const ndt_value_t *x, const ndt_value_t *y);
613
+ NDTYPES_API int ndt_value_compare(const ndt_value_t *x, const ndt_value_t *y);
614
+
615
+ /* 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);
618
+
619
+
620
+ /*****************************************************************************/
621
+ /* Encodings */
622
+ /*****************************************************************************/
623
+
624
+ NDTYPES_API enum ndt_encoding ndt_encoding_from_string(const char *s, ndt_context_t *ctx);
625
+ NDTYPES_API const char *ndt_encoding_as_string(enum ndt_encoding encoding);
626
+ NDTYPES_API size_t ndt_sizeof_encoding(enum ndt_encoding encoding);
627
+ NDTYPES_API uint16_t ndt_alignof_encoding(enum ndt_encoding encoding);
628
+
629
+
630
+ /*****************************************************************************/
631
+ /* Predicates */
632
+ /*****************************************************************************/
633
+
634
+ NDTYPES_API int ndt_is_abstract(const ndt_t *t);
635
+ NDTYPES_API int ndt_is_concrete(const ndt_t *t);
636
+
637
+ NDTYPES_API int ndt_is_optional(const ndt_t *t);
638
+ NDTYPES_API int ndt_subtree_is_optional(const ndt_t *t);
639
+
640
+ NDTYPES_API int ndt_is_ndarray(const ndt_t *t);
641
+ NDTYPES_API int ndt_is_c_contiguous(const ndt_t *t);
642
+ NDTYPES_API int ndt_is_f_contiguous(const ndt_t *t);
643
+ NDTYPES_API int ndt_really_fortran(const ndt_t *t);
644
+
645
+ NDTYPES_API int ndt_is_scalar(const ndt_t *t);
646
+ NDTYPES_API int ndt_is_signed(const ndt_t *t);
647
+ NDTYPES_API int ndt_is_unsigned(const ndt_t *t);
648
+ NDTYPES_API int ndt_is_float(const ndt_t *t);
649
+ NDTYPES_API int ndt_is_complex(const ndt_t *t);
650
+
651
+ NDTYPES_API int ndt_endian_is_set(const ndt_t *t);
652
+ NDTYPES_API int ndt_is_little_endian(const ndt_t *t);
653
+ NDTYPES_API int ndt_is_big_endian(const ndt_t *t);
654
+
655
+
656
+ /*****************************************************************************/
657
+ /* Functions */
658
+ /*****************************************************************************/
659
+
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);
664
+
665
+ NDTYPES_API int ndt_equal(const ndt_t *t, const ndt_t *u);
666
+ NDTYPES_API int ndt_match(const ndt_t *p, const ndt_t *c, ndt_context_t *ctx);
667
+ NDTYPES_API int ndt_typecheck(ndt_apply_spec_t *spec, const ndt_t *sig,
668
+ const ndt_t *in[], const int nin,
669
+ const ndt_constraint_t *c, const void *args,
670
+ ndt_context_t *ctx);
671
+ 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);
674
+
675
+ NDTYPES_API int64_t ndt_itemsize(const ndt_t *t);
676
+
677
+
678
+ /*****************************************************************************/
679
+ /* Input/Output */
680
+ /*****************************************************************************/
681
+
682
+ /*** String to primitive conversion ***/
683
+ NDTYPES_API bool ndt_strtobool(const char *v, ndt_context_t *ctx);
684
+ NDTYPES_API char ndt_strtochar(const char *v, ndt_context_t *ctx);
685
+ NDTYPES_API long ndt_strtol(const char *v, long min, long max, ndt_context_t *ctx);
686
+ NDTYPES_API long long ndt_strtoll(const char *v, long long min, long long max, ndt_context_t *ctx);
687
+ NDTYPES_API unsigned long ndt_strtoul(const char *v, unsigned long max, ndt_context_t *ctx);
688
+ NDTYPES_API unsigned long long ndt_strtoull(const char *v, unsigned long long max, ndt_context_t *ctx);
689
+ NDTYPES_API float ndt_strtof(const char *v, ndt_context_t *ctx);
690
+ NDTYPES_API double ndt_strtod(const char *v, ndt_context_t *ctx);
691
+
692
+ /*** Type to string conversion ***/
693
+ NDTYPES_API char *ndt_as_string(const ndt_t *t, ndt_context_t *ctx);
694
+ NDTYPES_API char *ndt_list_as_string(const ndt_t *types[], int64_t len, ndt_context_t *ctx);
695
+ NDTYPES_API char *ndt_indent(const ndt_t *t, ndt_context_t *ctx);
696
+ NDTYPES_API char *ndt_ast_repr(const ndt_t *t, ndt_context_t *ctx);
697
+
698
+ 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);
701
+
702
+
703
+ /*****************************************************************************/
704
+ /* Typedef */
705
+ /*****************************************************************************/
706
+
707
+ typedef struct {
708
+ const ndt_t *type;
709
+ ndt_methods_t meth;
710
+ } ndt_typedef_t;
711
+
712
+ /* 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);
714
+ NDTYPES_API const ndt_typedef_t *ndt_typedef_find(const char *name, ndt_context_t *ctx);
715
+
716
+ NDTYPES_API int ndt_typedef(const char *name, ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
717
+ NDTYPES_API int ndt_typedef_from_string(const char *name, const char *type, const ndt_methods_t *m, ndt_context_t *ctx);
718
+
719
+
720
+ /*****************************************************************************/
721
+ /* Allocate types */
722
+ /*****************************************************************************/
723
+
724
+ NDTYPES_API ndt_t *ndt_new(enum ndt tag, ndt_context_t *ctx);
725
+ 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);
729
+
730
+
731
+ /*****************************************************************************/
732
+ /* Construct types */
733
+ /*****************************************************************************/
734
+
735
+ /* 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);
739
+
740
+ /* Any */
741
+ NDTYPES_API ndt_t *ndt_any_kind(ndt_context_t *ctx);
742
+
743
+ /* 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);
747
+
748
+ NDTYPES_API ndt_t *ndt_abstract_var_dim(ndt_t *type, ndt_context_t *ctx);
749
+ NDTYPES_API int64_t ndt_var_indices(int64_t *res_start, int64_t *res_step, const ndt_t *t,
750
+ int64_t index, ndt_context_t *ctx);
751
+ NDTYPES_API ndt_slice_t *ndt_var_add_slice(int32_t *nslices, const ndt_t *t,
752
+ int64_t start, int64_t stop, int64_t step,
753
+ 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);
758
+
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);
763
+
764
+ /* 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);
769
+
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);
773
+
774
+ /* Scalars */
775
+ NDTYPES_API ndt_t *ndt_scalar_kind(ndt_context_t *ctx);
776
+
777
+ NDTYPES_API ndt_t *ndt_categorical(ndt_value_t *types, int64_t ntypes, ndt_context_t *ctx);
778
+
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);
781
+
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);
784
+
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);
788
+
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);
793
+
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);
798
+
799
+ /* Type variable */
800
+ NDTYPES_API ndt_t *ndt_typevar(char *name, ndt_context_t *ctx);
801
+
802
+
803
+ /******************************************************************************/
804
+ /* Parsing */
805
+ /******************************************************************************/
806
+
807
+ /* Metadata is currently limited to var-dimension offsets. */
808
+
809
+ /*
810
+ * Metadata is read from the type string and managed by the type. This is
811
+ * convenient but can waste a lot of space when offset arrays are large.
812
+ */
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);
816
+ NDTYPES_API char *ndt_to_bpformat(const ndt_t *t, ndt_context_t *ctx);
817
+ NDTYPES_API int ndt_to_nbformat(char **sig, char **dtype, const ndt_t *t, ndt_context_t *ctx);
818
+
819
+ /* Unstable API */
820
+ NDTYPES_API ndt_t *ndt_from_string_v(const char *input, ndt_context_t *ctx);
821
+
822
+
823
+ /*
824
+ * Metadata is read from the type string and extracted for external management.
825
+ * The type still has pointers to the metadata. This scheme is used for sharing
826
+ * offsets between copies or subtypes of a type.
827
+ */
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);
830
+
831
+ /* 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);
833
+
834
+ NDTYPES_API ndt_meta_t *ndt_meta_new(ndt_context_t *ctx);
835
+ NDTYPES_API void ndt_meta_del(ndt_meta_t *m);
836
+
837
+
838
+ /******************************************************************************/
839
+ /* Library initialization and tables */
840
+ /******************************************************************************/
841
+
842
+ NDTYPES_API int ndt_init(ndt_context_t *ctx);
843
+ NDTYPES_API void ndt_finalize(void);
844
+
845
+
846
+ /******************************************************************************/
847
+ /* Error Macros */
848
+ /******************************************************************************/
849
+
850
+ #define ndt_internal_error(msg) \
851
+ do { \
852
+ fprintf(stderr, "%s:%d: internal error: %s\n", __FILE__, __LINE__, msg); \
853
+ abort(); \
854
+ } while (0)
855
+
856
+ #define ndt_warn(msg) \
857
+ do { \
858
+ fprintf(stderr, "%s:%d: warning: %s\n", __FILE__, __LINE__, msg); \
859
+ } while (0)
860
+
861
+
862
+ /******************************************************************************/
863
+ /* Memory handling */
864
+ /******************************************************************************/
865
+
866
+ NDTYPES_API extern void *(* ndt_mallocfunc)(size_t size);
867
+ NDTYPES_API extern void *(* ndt_callocfunc)(size_t nmemb, size_t size);
868
+ NDTYPES_API extern void *(* ndt_reallocfunc)(void *ptr, size_t size);
869
+ NDTYPES_API extern void (* ndt_freefunc)(void *ptr);
870
+
871
+ NDTYPES_API void *ndt_alloc(int64_t nmemb, int64_t size);
872
+ NDTYPES_API void *ndt_alloc_size(size_t size);
873
+ NDTYPES_API void *ndt_calloc(int64_t nmemb, int64_t size);
874
+ NDTYPES_API void *ndt_realloc(void *ptr, int64_t nmemb, int64_t size);
875
+ NDTYPES_API void ndt_free(void *ptr);
876
+
877
+ NDTYPES_API void *ndt_aligned_calloc(uint16_t alignment, int64_t size);
878
+ NDTYPES_API void ndt_aligned_free(void *ptr);
879
+
880
+
881
+ /******************************************************************************/
882
+ /* Low level details */
883
+ /******************************************************************************/
884
+
885
+ typedef struct {
886
+ int64_t size;
887
+ uint8_t *data;
888
+ } ndt_bytes_t;
889
+
890
+ typedef int64_t ndt_categorical_t;
891
+
892
+
893
+ #endif /* NDTYPES_H */
@@ -0,0 +1,37 @@
1
+ /* File containing headers for Ruby ndtypes wrapper.
2
+ *
3
+ * Author: Sameer Deshmukh (@v0dro)
4
+ */
5
+
6
+ #ifndef RUBY_NDTYPES_H
7
+ #define RUBY_NDTYPES_H
8
+
9
+ #if defined(__cplusplus)
10
+ extern "C" {
11
+ } /* satisfy cc-mode */
12
+ #endif
13
+
14
+ #include "ruby.h"
15
+ #include "ndtypes.h"
16
+
17
+ /* Public interface for ndtypes. */
18
+ typedef struct NdtObject NdtObject;
19
+ extern VALUE cNDTypes;
20
+
21
+ int rb_ndtypes_check_type(VALUE obj);
22
+ NdtObject * rb_ndtypes_get_ndt_object(VALUE obj);
23
+ VALUE rb_ndtypes_make_ndt_object(NdtObject *ndt_p);
24
+ VALUE rb_ndtypes_wrap_ndt_object(void);
25
+ const ndt_t * rb_ndtypes_const_ndt(VALUE ndt);
26
+ VALUE rb_ndtypes_move_subtree(VALUE src, ndt_t *t);
27
+ VALUE rb_ndtypes_from_object(VALUE type);
28
+ VALUE rb_ndtypes_set_error(ndt_context_t *ctx);
29
+ VALUE rb_ndtypes_from_type(ndt_t *type);
30
+
31
+ #define INT2BOOL(t) (t ? Qtrue : Qfalse)
32
+
33
+ #if defined(__cplusplus)
34
+ } /* extern "C" { */
35
+ #endif
36
+
37
+ #endif /* RUBY_NDTYPES_H */
Binary file
@@ -0,0 +1 @@
1
+ ext/ruby_ndtypes/lib/libndtypes.so.0.2.0dev3
@@ -0,0 +1 @@
1
+ ext/ruby_ndtypes/lib/libndtypes.so.0.2.0dev3
@@ -1,6 +1,6 @@
1
1
  class NDTypes
2
2
  # VERSION number should be the version of libxnd this is built against.
3
- VERSION = "0.2.0dev4"
3
+ VERSION = "0.2.0dev5"
4
4
  # git commit of the version.
5
5
  COMMIT = "7c4cda117f7081d66c8a23bb604b78c01aea1b77"
6
6
  end
Binary file
data/ndtypes.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.unshift File.expand_path("../lib", __FILE__)
3
3
 
4
4
  require 'ndtypes/version.rb'
5
5
 
6
- def get_files
6
+ def self.get_files
7
7
  files = []
8
8
  ['ext', 'lib', 'spec'].each do |folder|
9
9
  files.concat Dir.glob "#{folder}/**/*"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndtypes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0dev4
4
+ version: 0.2.0dev5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Deshmukh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-23 00:00:00.000000000 Z
11
+ date: 2018-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -83,6 +83,12 @@ files:
83
83
  - ext/ruby_ndtypes/extconf.rb
84
84
  - ext/ruby_ndtypes/gc_guard.c
85
85
  - ext/ruby_ndtypes/gc_guard.h
86
+ - ext/ruby_ndtypes/include/ndtypes.h
87
+ - ext/ruby_ndtypes/include/ruby_ndtypes.h
88
+ - ext/ruby_ndtypes/lib/libndtypes.a
89
+ - ext/ruby_ndtypes/lib/libndtypes.so
90
+ - ext/ruby_ndtypes/lib/libndtypes.so.0
91
+ - ext/ruby_ndtypes/lib/libndtypes.so.0.2.0dev3
86
92
  - ext/ruby_ndtypes/ndtypes/AUTHORS.txt
87
93
  - ext/ruby_ndtypes/ndtypes/INSTALL.txt
88
94
  - ext/ruby_ndtypes/ndtypes/LICENSE.txt
@@ -208,6 +214,7 @@ files:
208
214
  - lib/ndtypes.rb
209
215
  - lib/ndtypes/errors.rb
210
216
  - lib/ndtypes/version.rb
217
+ - lib/ruby_ndtypes.so
211
218
  - ndtypes.gemspec
212
219
  - spec/gc_table_spec.rb
213
220
  - spec/ndtypes_spec.rb