ndtypes 0.2.0dev4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +2 -0
- data/History.md +0 -0
- data/README.md +19 -0
- data/Rakefile +125 -0
- data/ext/ruby_ndtypes/extconf.rb +55 -0
- data/ext/ruby_ndtypes/gc_guard.c +36 -0
- data/ext/ruby_ndtypes/gc_guard.h +12 -0
- data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
- data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
- data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
- data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
- data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
- data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
- data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
- data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
- data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
- data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
- data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
- data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
- data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
- data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
- data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
- data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
- data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
- data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
- data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
- data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
- data/lib/ndtypes.rb +45 -0
- data/lib/ndtypes/errors.rb +2 -0
- data/lib/ndtypes/version.rb +6 -0
- data/ndtypes.gemspec +47 -0
- data/spec/gc_table_spec.rb +10 -0
- data/spec/ndtypes_spec.rb +289 -0
- data/spec/spec_helper.rb +241 -0
- metadata +242 -0
@@ -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 @NDT_SYS_BIG_ENDIAN@
|
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 */
|