ndtypes 0.2.0dev5 → 0.2.0dev6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +12 -0
- data/Rakefile +8 -0
- data/ext/ruby_ndtypes/GPATH +0 -0
- data/ext/ruby_ndtypes/GRTAGS +0 -0
- data/ext/ruby_ndtypes/GTAGS +0 -0
- data/ext/ruby_ndtypes/extconf.rb +1 -1
- data/ext/ruby_ndtypes/include/ndtypes.h +231 -122
- data/ext/ruby_ndtypes/include/ruby_ndtypes.h +1 -1
- data/ext/ruby_ndtypes/lib/libndtypes.a +0 -0
- data/ext/ruby_ndtypes/lib/libndtypes.so.0.2.0dev3 +0 -0
- data/ext/ruby_ndtypes/ndtypes/Makefile +87 -0
- data/ext/ruby_ndtypes/ndtypes/config.h +68 -0
- data/ext/ruby_ndtypes/ndtypes/config.log +477 -0
- data/ext/ruby_ndtypes/ndtypes/config.status +1027 -0
- data/ext/ruby_ndtypes/ndtypes/doc/_static/style.css +7 -0
- data/ext/ruby_ndtypes/ndtypes/doc/_templates/layout.html +2 -0
- data/ext/ruby_ndtypes/ndtypes/doc/conf.py +40 -4
- data/ext/ruby_ndtypes/ndtypes/doc/images/xndlogo.png +0 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +1 -1
- data/ext/ruby_ndtypes/ndtypes/doc/requirements.txt +2 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile +287 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +20 -4
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +22 -3
- data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +1 -1
- data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile +73 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +246 -229
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +15 -11
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +38 -28
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +91 -91
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +1 -1
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +4 -3
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +8 -7
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +2 -2
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/context.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +263 -182
- data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +67 -7
- data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +1112 -1000
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +69 -58
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +150 -99
- data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +185 -15
- data/ext/ruby_ndtypes/ndtypes/libndtypes/io.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +301 -276
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +1 -1
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +9 -4
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.a +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so +1 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so.0 +1 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so.0.2.0dev3 +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +729 -228
- data/ext/ruby_ndtypes/ndtypes/libndtypes/match.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +768 -403
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h +1002 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +231 -122
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +176 -84
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +26 -14
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +57 -35
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/primitive.c +420 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/primitive.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +8 -8
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +1 -1
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile +48 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +200 -116
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +46 -4
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +58 -27
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +1 -1
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +3 -5
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +12 -4
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile +55 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +8 -8
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +5 -5
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +274 -172
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +24 -4
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +2 -2
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +14 -14
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +32 -30
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +37 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +36 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +16 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +5 -5
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +706 -253
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_unify.c +132 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/unify.c +703 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/unify.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +335 -127
- data/ext/ruby_ndtypes/ndtypes/libndtypes/util.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +2 -2
- data/ext/ruby_ndtypes/ndtypes/libndtypes/values.o +0 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +88 -71
- data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +0 -1
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +10 -13
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +395 -314
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.a +0 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so +1 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0 +1 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0.2.0dev3 +0 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/ndtypes.h +1002 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +15 -33
- data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +340 -132
- data/ext/ruby_ndtypes/ndtypes/setup.py +11 -2
- data/ext/ruby_ndtypes/ruby_ndtypes.c +364 -241
- data/ext/ruby_ndtypes/ruby_ndtypes.h +1 -1
- data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +0 -1
- data/lib/ndtypes.rb +11 -0
- data/lib/ndtypes/version.rb +2 -2
- data/lib/ruby_ndtypes.so +0 -0
- data/ndtypes.gemspec +3 -0
- data/spec/ndtypes_spec.rb +6 -0
- metadata +98 -4
- data/ext/ruby_ndtypes/gc_guard.c +0 -36
- data/ext/ruby_ndtypes/gc_guard.h +0 -12
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0.2.0dev3
|
@@ -0,0 +1 @@
|
|
1
|
+
ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0.2.0dev3
|
Binary file
|
@@ -0,0 +1,1002 @@
|
|
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
|
+
#ifdef __cplusplus
|
39
|
+
extern "C" {
|
40
|
+
#endif
|
41
|
+
|
42
|
+
#include <stdio.h>
|
43
|
+
#include <stdlib.h>
|
44
|
+
#include <limits.h>
|
45
|
+
#include <stdbool.h>
|
46
|
+
#include <stddef.h>
|
47
|
+
|
48
|
+
#ifdef __cplusplus
|
49
|
+
#include <cstdint>
|
50
|
+
#else
|
51
|
+
#include <stdint.h>
|
52
|
+
#include <inttypes.h>
|
53
|
+
#include <complex.h>
|
54
|
+
#endif
|
55
|
+
|
56
|
+
|
57
|
+
#if SIZE_MAX > ULLONG_MAX
|
58
|
+
#error "need SIZE_MAX <= ULLONG_MAX"
|
59
|
+
#endif
|
60
|
+
|
61
|
+
#if SIZE_MAX == UINT32_MAX
|
62
|
+
typedef int32_t ndt_ssize_t;
|
63
|
+
#define PRI_ndt_ssize PRIi32
|
64
|
+
#elif SIZE_MAX == UINT64_MAX
|
65
|
+
typedef int64_t ndt_ssize_t;
|
66
|
+
#define PRI_ndt_ssize PRIi64
|
67
|
+
#else
|
68
|
+
#error "need SIZE_MAX == UINT32_MAX or SIZE_MAX == UINT64_MAX"
|
69
|
+
#endif
|
70
|
+
|
71
|
+
#ifdef _MSC_VER
|
72
|
+
#if defined (NDT_EXPORT)
|
73
|
+
#define NDTYPES_API __declspec(dllexport)
|
74
|
+
#elif defined(NDT_IMPORT)
|
75
|
+
#define NDTYPES_API __declspec(dllimport)
|
76
|
+
#else
|
77
|
+
#define NDTYPES_API
|
78
|
+
#endif
|
79
|
+
|
80
|
+
#define alignof __alignof
|
81
|
+
#define alignas(n) __declspec(align(n))
|
82
|
+
#define MAX_ALIGN 8
|
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
|
92
|
+
#else
|
93
|
+
#define NDTYPES_API
|
94
|
+
|
95
|
+
#if !defined(__APPLE__) && !defined(__STDC_IEC_559__)
|
96
|
+
#error "ndtypes requires IEEE floating point arithmetic"
|
97
|
+
#endif
|
98
|
+
#include <stdalign.h>
|
99
|
+
|
100
|
+
#define MAX_ALIGN (alignof(max_align_t))
|
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
|
111
|
+
#endif
|
112
|
+
|
113
|
+
#if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \
|
114
|
+
defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER)
|
115
|
+
#define NDT_PRAGMA(x) _Pragma(x)
|
116
|
+
#define NDT_HIDE_SYMBOLS_START "GCC visibility push(hidden)"
|
117
|
+
#define NDT_HIDE_SYMBOLS_END "GCC visibility pop"
|
118
|
+
#else
|
119
|
+
#define NDT_PRAGMA(x)
|
120
|
+
#define NDT_HIDE_SYMBOLS_START
|
121
|
+
#define NDT_HIDE_SYMBOLS_END
|
122
|
+
#endif
|
123
|
+
|
124
|
+
|
125
|
+
/*****************************************************************************/
|
126
|
+
/* Datashape */
|
127
|
+
/*****************************************************************************/
|
128
|
+
|
129
|
+
#define NDT_MAX_DIM 128
|
130
|
+
#define NDT_MAX_ARGS 128
|
131
|
+
|
132
|
+
#define NDT_OPTION 0x00000001U
|
133
|
+
#define NDT_SUBTREE_OPTION 0x00000002U
|
134
|
+
#define NDT_LITTLE_ENDIAN 0x00000004U
|
135
|
+
#define NDT_BIG_ENDIAN 0x00000008U
|
136
|
+
#define NDT_ELLIPSIS 0x00000010U
|
137
|
+
#define NDT_POINTER 0x00000020U
|
138
|
+
#define NDT_REF 0x00000040U
|
139
|
+
#define NDT_CHAR 0x00000080U
|
140
|
+
|
141
|
+
|
142
|
+
/* Types: ndt_t */
|
143
|
+
typedef struct _ndt ndt_t;
|
144
|
+
typedef struct _ndt_context ndt_context_t;
|
145
|
+
|
146
|
+
|
147
|
+
/* Internal option type */
|
148
|
+
enum ndt_option {
|
149
|
+
None,
|
150
|
+
Some
|
151
|
+
};
|
152
|
+
|
153
|
+
typedef struct {
|
154
|
+
enum ndt_option tag;
|
155
|
+
char Some;
|
156
|
+
} char_opt_t;
|
157
|
+
|
158
|
+
typedef struct {
|
159
|
+
enum ndt_option tag;
|
160
|
+
int64_t Some;
|
161
|
+
} int64_opt_t;
|
162
|
+
|
163
|
+
typedef struct {
|
164
|
+
enum ndt_option tag;
|
165
|
+
uint16_t Some;
|
166
|
+
} uint16_opt_t;
|
167
|
+
|
168
|
+
|
169
|
+
/* Flag for variadic tuples and records */
|
170
|
+
enum ndt_variadic {
|
171
|
+
Nonvariadic,
|
172
|
+
Variadic
|
173
|
+
};
|
174
|
+
|
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 */
|
182
|
+
};
|
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
|
+
|
189
|
+
/*
|
190
|
+
* The arrays are addressed by t->ndim-1, where t->ndim > 0. It follows that
|
191
|
+
* offsets[0] are the offsets of the innermost dimension and offsets[ndims-1]
|
192
|
+
* the offsets of the outermost dimension.
|
193
|
+
*/
|
194
|
+
typedef struct {
|
195
|
+
int ndims; /* number of offset structs */
|
196
|
+
ndt_offsets_t *offsets[NDT_MAX_DIM]; /* offset structs */
|
197
|
+
} ndt_meta_t;
|
198
|
+
|
199
|
+
/* Encoding for characters and strings */
|
200
|
+
enum ndt_encoding {
|
201
|
+
Ascii,
|
202
|
+
Utf8,
|
203
|
+
Ucs2,
|
204
|
+
Utf16,
|
205
|
+
Utf32,
|
206
|
+
};
|
207
|
+
|
208
|
+
|
209
|
+
/* Datashape kinds */
|
210
|
+
enum ndt {
|
211
|
+
/* Name space */
|
212
|
+
Module,
|
213
|
+
|
214
|
+
/* Function */
|
215
|
+
Function,
|
216
|
+
|
217
|
+
/* Any */
|
218
|
+
AnyKind,
|
219
|
+
FixedDim,
|
220
|
+
VarDim,
|
221
|
+
VarDimElem,
|
222
|
+
SymbolicDim,
|
223
|
+
EllipsisDim,
|
224
|
+
|
225
|
+
/* Dtype */
|
226
|
+
Array,
|
227
|
+
Tuple,
|
228
|
+
Record,
|
229
|
+
Union,
|
230
|
+
Ref,
|
231
|
+
Constr,
|
232
|
+
Nominal,
|
233
|
+
|
234
|
+
/* Scalar */
|
235
|
+
ScalarKind,
|
236
|
+
Categorical,
|
237
|
+
|
238
|
+
FixedStringKind,
|
239
|
+
FixedString,
|
240
|
+
|
241
|
+
FixedBytesKind,
|
242
|
+
FixedBytes,
|
243
|
+
|
244
|
+
String,
|
245
|
+
Bytes,
|
246
|
+
Char,
|
247
|
+
|
248
|
+
/* Primitive */
|
249
|
+
Bool,
|
250
|
+
|
251
|
+
SignedKind,
|
252
|
+
Int8,
|
253
|
+
Int16,
|
254
|
+
Int32,
|
255
|
+
Int64,
|
256
|
+
|
257
|
+
UnsignedKind,
|
258
|
+
Uint8,
|
259
|
+
Uint16,
|
260
|
+
Uint32,
|
261
|
+
Uint64,
|
262
|
+
|
263
|
+
FloatKind,
|
264
|
+
BFloat16,
|
265
|
+
Float16,
|
266
|
+
Float32,
|
267
|
+
Float64,
|
268
|
+
|
269
|
+
ComplexKind,
|
270
|
+
BComplex32,
|
271
|
+
Complex32,
|
272
|
+
Complex64,
|
273
|
+
Complex128,
|
274
|
+
|
275
|
+
/* Dtype variable */
|
276
|
+
Typevar,
|
277
|
+
};
|
278
|
+
|
279
|
+
enum ndt_alias {
|
280
|
+
Size,
|
281
|
+
Intptr,
|
282
|
+
Uintptr
|
283
|
+
};
|
284
|
+
|
285
|
+
/* Protect access to concrete type fields. */
|
286
|
+
enum ndt_access {
|
287
|
+
Abstract,
|
288
|
+
Concrete
|
289
|
+
};
|
290
|
+
|
291
|
+
/*
|
292
|
+
* Require C or Fortran contiguity in abstract signatures. For concrete types
|
293
|
+
* the field is irrelevant and set to RequireNA.
|
294
|
+
*/
|
295
|
+
enum ndt_contig {
|
296
|
+
RequireNA,
|
297
|
+
RequireC,
|
298
|
+
RequireF
|
299
|
+
};
|
300
|
+
|
301
|
+
/* Tuple or record field, used in the parser. */
|
302
|
+
typedef struct {
|
303
|
+
enum ndt_access access;
|
304
|
+
char *name;
|
305
|
+
const ndt_t *type;
|
306
|
+
struct {
|
307
|
+
uint16_t align;
|
308
|
+
bool explicit_align;
|
309
|
+
uint16_t pad;
|
310
|
+
bool explicit_pad;
|
311
|
+
} Concrete;
|
312
|
+
} ndt_field_t;
|
313
|
+
|
314
|
+
/* Selected values for the categorical type. */
|
315
|
+
enum ndt_value {
|
316
|
+
ValBool,
|
317
|
+
ValInt64,
|
318
|
+
ValFloat64,
|
319
|
+
ValString,
|
320
|
+
ValNA,
|
321
|
+
};
|
322
|
+
|
323
|
+
typedef struct {
|
324
|
+
enum ndt_value tag;
|
325
|
+
union {
|
326
|
+
bool ValBool;
|
327
|
+
int64_t ValInt64;
|
328
|
+
double ValFloat64;
|
329
|
+
char *ValString;
|
330
|
+
};
|
331
|
+
} ndt_value_t;
|
332
|
+
|
333
|
+
typedef struct {
|
334
|
+
int64_t start;
|
335
|
+
int64_t stop;
|
336
|
+
int64_t step;
|
337
|
+
} ndt_slice_t;
|
338
|
+
|
339
|
+
/*
|
340
|
+
* Constraint support for function signatures. A constraint needs to specify:
|
341
|
+
*
|
342
|
+
* 1) The symbols in the function arguments and return value(s) that are
|
343
|
+
* needed to decide the constraint.
|
344
|
+
* 2) ndt_typecheck() resolves the 'nin' incoming symbols and passes their
|
345
|
+
* shape values in the 'shapes' array. It then calls the constraint
|
346
|
+
* function.
|
347
|
+
* 3) The constraint function can look at the incoming shapes as well
|
348
|
+
* as the incoming function arguments (usually xnd_t).
|
349
|
+
* 4) The function then needs to decide whether the constraint is met; if so,
|
350
|
+
* it must fill in 'nout' shapes for the return symbols (if any).
|
351
|
+
* 5) ndt_typecheck() uses the resolved 'nout' shapes to update the symbol
|
352
|
+
* table and now has sufficient information to compute the return type.
|
353
|
+
*/
|
354
|
+
#define NDT_MAX_SYMBOLS 16
|
355
|
+
typedef int (* ndt_func_constraint_t)(int64_t *shapes, const void *args, ndt_context_t *ctx);
|
356
|
+
|
357
|
+
typedef struct {
|
358
|
+
ndt_func_constraint_t f;
|
359
|
+
int nin;
|
360
|
+
int nout;
|
361
|
+
const char *symbols[NDT_MAX_SYMBOLS];
|
362
|
+
} ndt_constraint_t;
|
363
|
+
|
364
|
+
/* Object features for the Nominal type. */
|
365
|
+
typedef bool (* ndt_init_t)(void *dest, const void *src, ndt_context_t *);
|
366
|
+
typedef bool (* ndt_tdef_constraint_t)(const void *, ndt_context_t *);
|
367
|
+
typedef void *(* ndt_repr_t)(const void *, ndt_context_t *);
|
368
|
+
|
369
|
+
typedef struct {
|
370
|
+
ndt_init_t init;
|
371
|
+
ndt_tdef_constraint_t constraint;
|
372
|
+
ndt_repr_t repr;
|
373
|
+
} ndt_methods_t;
|
374
|
+
|
375
|
+
|
376
|
+
/* Datashape type */
|
377
|
+
struct _ndt {
|
378
|
+
/* Always defined */
|
379
|
+
enum ndt tag;
|
380
|
+
enum ndt_access access;
|
381
|
+
uint32_t flags;
|
382
|
+
int ndim;
|
383
|
+
/* Undefined if the type is abstract */
|
384
|
+
int64_t datasize;
|
385
|
+
uint16_t align;
|
386
|
+
|
387
|
+
/* Abstract */
|
388
|
+
union {
|
389
|
+
struct {
|
390
|
+
char *name;
|
391
|
+
const ndt_t *type;
|
392
|
+
} Module;
|
393
|
+
|
394
|
+
struct {
|
395
|
+
bool elemwise;
|
396
|
+
int64_t nin;
|
397
|
+
int64_t nout;
|
398
|
+
int64_t nargs;
|
399
|
+
const ndt_t **types;
|
400
|
+
} Function;
|
401
|
+
|
402
|
+
struct {
|
403
|
+
enum ndt_contig tag;
|
404
|
+
int64_t shape;
|
405
|
+
const ndt_t *type;
|
406
|
+
} FixedDim;
|
407
|
+
|
408
|
+
struct {
|
409
|
+
const ndt_t *type;
|
410
|
+
} VarDim;
|
411
|
+
|
412
|
+
struct {
|
413
|
+
const ndt_t *type;
|
414
|
+
int64_t index;
|
415
|
+
} VarDimElem;
|
416
|
+
|
417
|
+
struct {
|
418
|
+
enum ndt_contig tag;
|
419
|
+
char *name;
|
420
|
+
const ndt_t *type;
|
421
|
+
} SymbolicDim;
|
422
|
+
|
423
|
+
struct {
|
424
|
+
enum ndt_contig tag;
|
425
|
+
char *name;
|
426
|
+
const ndt_t *type;
|
427
|
+
} EllipsisDim;
|
428
|
+
|
429
|
+
struct {
|
430
|
+
enum ndt_variadic flag;
|
431
|
+
int64_t shape;
|
432
|
+
const ndt_t **types;
|
433
|
+
} Tuple;
|
434
|
+
|
435
|
+
struct {
|
436
|
+
enum ndt_variadic flag;
|
437
|
+
int64_t shape;
|
438
|
+
char **names;
|
439
|
+
const ndt_t **types;
|
440
|
+
} Record;
|
441
|
+
|
442
|
+
struct {
|
443
|
+
int64_t ntags;
|
444
|
+
char **tags;
|
445
|
+
const ndt_t **types;
|
446
|
+
} Union;
|
447
|
+
|
448
|
+
struct {
|
449
|
+
const ndt_t *type;
|
450
|
+
} Ref;
|
451
|
+
|
452
|
+
struct {
|
453
|
+
char *name;
|
454
|
+
const ndt_t *type;
|
455
|
+
} Constr;
|
456
|
+
|
457
|
+
struct {
|
458
|
+
char *name;
|
459
|
+
const ndt_t *type;
|
460
|
+
const ndt_methods_t *meth;
|
461
|
+
} Nominal;
|
462
|
+
|
463
|
+
struct {
|
464
|
+
int64_t ntypes;
|
465
|
+
const ndt_value_t *types;
|
466
|
+
} Categorical;
|
467
|
+
|
468
|
+
struct {
|
469
|
+
int64_t size;
|
470
|
+
enum ndt_encoding encoding;
|
471
|
+
} FixedString;
|
472
|
+
|
473
|
+
struct {
|
474
|
+
int64_t size;
|
475
|
+
uint16_t align;
|
476
|
+
} FixedBytes;
|
477
|
+
|
478
|
+
struct {
|
479
|
+
uint16_t target_align;
|
480
|
+
} Bytes;
|
481
|
+
|
482
|
+
struct {
|
483
|
+
int64_t itemsize;
|
484
|
+
const ndt_t *type;
|
485
|
+
} Array;
|
486
|
+
|
487
|
+
struct {
|
488
|
+
enum ndt_encoding encoding;
|
489
|
+
} Char;
|
490
|
+
|
491
|
+
struct {
|
492
|
+
char *name;
|
493
|
+
} Typevar;
|
494
|
+
};
|
495
|
+
|
496
|
+
/* Concrete */
|
497
|
+
struct {
|
498
|
+
union {
|
499
|
+
struct {
|
500
|
+
int64_t itemsize;
|
501
|
+
int64_t step;
|
502
|
+
} FixedDim;
|
503
|
+
|
504
|
+
struct {
|
505
|
+
int64_t itemsize;
|
506
|
+
const ndt_offsets_t *offsets;
|
507
|
+
int nslices;
|
508
|
+
ndt_slice_t *slices;
|
509
|
+
} VarDim;
|
510
|
+
|
511
|
+
struct {
|
512
|
+
int64_t *offset;
|
513
|
+
uint16_t *align;
|
514
|
+
uint16_t *pad;
|
515
|
+
} Tuple;
|
516
|
+
|
517
|
+
struct {
|
518
|
+
int64_t *offset;
|
519
|
+
uint16_t *align;
|
520
|
+
uint16_t *pad;
|
521
|
+
} Record;
|
522
|
+
};
|
523
|
+
} Concrete;
|
524
|
+
|
525
|
+
/* Reference counting */
|
526
|
+
ATOMIC_INT64 refcnt;
|
527
|
+
|
528
|
+
/* Extra space */
|
529
|
+
alignas(MAX_ALIGN) char extra[];
|
530
|
+
};
|
531
|
+
|
532
|
+
|
533
|
+
/*****************************************************************************/
|
534
|
+
/* Context and error handling */
|
535
|
+
/*****************************************************************************/
|
536
|
+
|
537
|
+
#define NDT_Dynamic 0x00000001U
|
538
|
+
|
539
|
+
#define NDT_STATIC_CONTEXT(name) \
|
540
|
+
ndt_context_t name = { .flags=0, .err=NDT_Success, .msg=ConstMsg, .ConstMsg="Success" }
|
541
|
+
|
542
|
+
enum ndt_error {
|
543
|
+
NDT_Success,
|
544
|
+
NDT_ValueError,
|
545
|
+
NDT_TypeError,
|
546
|
+
NDT_InvalidArgumentError,
|
547
|
+
NDT_NotImplementedError,
|
548
|
+
NDT_IndexError,
|
549
|
+
NDT_LexError,
|
550
|
+
NDT_ParseError,
|
551
|
+
NDT_OSError,
|
552
|
+
NDT_RuntimeError,
|
553
|
+
NDT_MemoryError
|
554
|
+
};
|
555
|
+
|
556
|
+
enum ndt_msg {
|
557
|
+
ConstMsg,
|
558
|
+
DynamicMsg
|
559
|
+
};
|
560
|
+
|
561
|
+
struct _ndt_context {
|
562
|
+
uint32_t flags;
|
563
|
+
enum ndt_error err;
|
564
|
+
enum ndt_msg msg;
|
565
|
+
union {
|
566
|
+
const char *ConstMsg;
|
567
|
+
char *DynamicMsg;
|
568
|
+
};
|
569
|
+
};
|
570
|
+
|
571
|
+
NDTYPES_API ndt_context_t *ndt_context_new(void);
|
572
|
+
NDTYPES_API void ndt_context_del(ndt_context_t *ctx);
|
573
|
+
|
574
|
+
NDTYPES_API void ndt_err_format(ndt_context_t *ctx, enum ndt_error err, const char *fmt, ...);
|
575
|
+
NDTYPES_API int ndt_err_occurred(const ndt_context_t *ctx);
|
576
|
+
NDTYPES_API void ndt_err_clear(ndt_context_t *ctx);
|
577
|
+
NDTYPES_API void *ndt_memory_error(ndt_context_t *ctx);
|
578
|
+
|
579
|
+
NDTYPES_API const char *ndt_err_as_string(enum ndt_error err);
|
580
|
+
NDTYPES_API const char *ndt_context_msg(ndt_context_t *ctx);
|
581
|
+
NDTYPES_API void ndt_err_fprint(FILE *fp, ndt_context_t *ctx);
|
582
|
+
|
583
|
+
/* Unstable API */
|
584
|
+
NDTYPES_API void ndt_err_append(ndt_context_t *ctx, const char *msg);
|
585
|
+
|
586
|
+
|
587
|
+
/******************************************************************************/
|
588
|
+
/* Array conversions and properties */
|
589
|
+
/******************************************************************************/
|
590
|
+
|
591
|
+
/* This may go into xnd at some point. */
|
592
|
+
typedef struct {
|
593
|
+
int ndim;
|
594
|
+
int64_t itemsize;
|
595
|
+
int64_t shape[NDT_MAX_DIM];
|
596
|
+
int64_t strides[NDT_MAX_DIM];
|
597
|
+
int64_t steps[NDT_MAX_DIM];
|
598
|
+
} ndt_ndarray_t;
|
599
|
+
|
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
|
+
|
626
|
+
|
627
|
+
typedef struct {
|
628
|
+
uint32_t flags;
|
629
|
+
int outer_dims;
|
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];
|
634
|
+
} ndt_apply_spec_t;
|
635
|
+
|
636
|
+
NDTYPES_API extern const ndt_apply_spec_t ndt_apply_spec_empty;
|
637
|
+
|
638
|
+
NDTYPES_API ndt_apply_spec_t *ndt_apply_spec_new(ndt_context_t *ctx);
|
639
|
+
NDTYPES_API void ndt_apply_spec_clear(ndt_apply_spec_t *spec);
|
640
|
+
NDTYPES_API void ndt_apply_spec_del(ndt_apply_spec_t *spec);
|
641
|
+
NDTYPES_API const char *ndt_apply_flags_as_string(const ndt_apply_spec_t *spec);
|
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);
|
644
|
+
|
645
|
+
NDTYPES_API int ndt_select_kernel_strategy(ndt_apply_spec_t *spec, ndt_context_t *ctx);
|
646
|
+
|
647
|
+
|
648
|
+
/*****************************************************************************/
|
649
|
+
/* Utilities */
|
650
|
+
/*****************************************************************************/
|
651
|
+
|
652
|
+
/* String and formatting utilities */
|
653
|
+
NDTYPES_API char *ndt_strdup(const char *s, ndt_context_t *ctx);
|
654
|
+
NDTYPES_API char *ndt_asprintf(ndt_context_t *ctx, const char *fmt, ...);
|
655
|
+
|
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);
|
660
|
+
NDTYPES_API const ndt_t *ndt_dtype(const ndt_t *t);
|
661
|
+
NDTYPES_API const ndt_t *ndt_hidden_dtype(const ndt_t *t);
|
662
|
+
NDTYPES_API int ndt_dims_dtype(const ndt_t *dims[NDT_MAX_DIM], const ndt_t **dtype, const ndt_t *t);
|
663
|
+
NDTYPES_API int ndt_as_ndarray(ndt_ndarray_t *a, const 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);
|
666
|
+
|
667
|
+
|
668
|
+
/*****************************************************************************/
|
669
|
+
/* Fields and values */
|
670
|
+
/*****************************************************************************/
|
671
|
+
|
672
|
+
/* Fields */
|
673
|
+
NDTYPES_API ndt_field_t *ndt_field(char *name, const ndt_t *type, uint16_opt_t align,
|
674
|
+
uint16_opt_t pack, uint16_opt_t pad, ndt_context_t *ctx);
|
675
|
+
NDTYPES_API void ndt_field_del(ndt_field_t *field);
|
676
|
+
NDTYPES_API void ndt_field_array_del(ndt_field_t *fields, int64_t shape);
|
677
|
+
|
678
|
+
/* Typed values */
|
679
|
+
NDTYPES_API void ndt_value_del(ndt_value_t *mem);
|
680
|
+
NDTYPES_API void ndt_value_array_del(const ndt_value_t *types, int64_t ntypes);
|
681
|
+
|
682
|
+
NDTYPES_API ndt_value_t *ndt_value_from_number(enum ndt_value tag, char *v, ndt_context_t *ctx);
|
683
|
+
NDTYPES_API ndt_value_t *ndt_value_from_string(char *v, ndt_context_t *ctx);
|
684
|
+
NDTYPES_API ndt_value_t *ndt_value_na(ndt_context_t *ctx);
|
685
|
+
NDTYPES_API int ndt_value_equal(const ndt_value_t *x, const ndt_value_t *y);
|
686
|
+
NDTYPES_API int ndt_value_mem_equal(const ndt_value_t *x, const ndt_value_t *y);
|
687
|
+
NDTYPES_API int ndt_value_compare(const ndt_value_t *x, const ndt_value_t *y);
|
688
|
+
|
689
|
+
/* Type array */
|
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);
|
692
|
+
|
693
|
+
|
694
|
+
/*****************************************************************************/
|
695
|
+
/* Encodings */
|
696
|
+
/*****************************************************************************/
|
697
|
+
|
698
|
+
NDTYPES_API enum ndt_encoding ndt_encoding_from_string(const char *s, ndt_context_t *ctx);
|
699
|
+
NDTYPES_API const char *ndt_encoding_as_string(enum ndt_encoding encoding);
|
700
|
+
NDTYPES_API size_t ndt_sizeof_encoding(enum ndt_encoding encoding);
|
701
|
+
NDTYPES_API uint16_t ndt_alignof_encoding(enum ndt_encoding encoding);
|
702
|
+
|
703
|
+
|
704
|
+
/*****************************************************************************/
|
705
|
+
/* Predicates */
|
706
|
+
/*****************************************************************************/
|
707
|
+
|
708
|
+
NDTYPES_API bool ndt_is_static(const ndt_t *t);
|
709
|
+
NDTYPES_API bool ndt_is_static_tag(enum ndt tag);
|
710
|
+
|
711
|
+
NDTYPES_API int ndt_is_abstract(const ndt_t *t);
|
712
|
+
NDTYPES_API int ndt_is_concrete(const ndt_t *t);
|
713
|
+
|
714
|
+
NDTYPES_API int ndt_is_optional(const ndt_t *t);
|
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);
|
718
|
+
|
719
|
+
NDTYPES_API int ndt_is_ndarray(const ndt_t *t);
|
720
|
+
NDTYPES_API int ndt_is_c_contiguous(const ndt_t *t);
|
721
|
+
NDTYPES_API int ndt_is_f_contiguous(const ndt_t *t);
|
722
|
+
NDTYPES_API int ndt_really_fortran(const ndt_t *t);
|
723
|
+
|
724
|
+
NDTYPES_API int ndt_is_var_contiguous(const ndt_t *t);
|
725
|
+
|
726
|
+
NDTYPES_API int ndt_is_scalar(const ndt_t *t);
|
727
|
+
NDTYPES_API int ndt_is_signed(const ndt_t *t);
|
728
|
+
NDTYPES_API int ndt_is_unsigned(const ndt_t *t);
|
729
|
+
NDTYPES_API int ndt_is_float(const ndt_t *t);
|
730
|
+
NDTYPES_API int ndt_is_complex(const ndt_t *t);
|
731
|
+
|
732
|
+
NDTYPES_API int ndt_endian_is_set(const ndt_t *t);
|
733
|
+
NDTYPES_API int ndt_is_little_endian(const ndt_t *t);
|
734
|
+
NDTYPES_API int ndt_is_big_endian(const ndt_t *t);
|
735
|
+
|
736
|
+
|
737
|
+
/*****************************************************************************/
|
738
|
+
/* Functions */
|
739
|
+
/*****************************************************************************/
|
740
|
+
|
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
|
+
|
749
|
+
|
750
|
+
NDTYPES_API int ndt_equal(const ndt_t *t, const ndt_t *u);
|
751
|
+
NDTYPES_API int ndt_match(const ndt_t *p, const ndt_t *c, ndt_context_t *ctx);
|
752
|
+
NDTYPES_API int ndt_typecheck(ndt_apply_spec_t *spec, const ndt_t *sig,
|
753
|
+
const ndt_t *types[], const int64_t li[],
|
754
|
+
const int nin, const int nout, bool check_broadcast,
|
755
|
+
const ndt_constraint_t *c, const void *args,
|
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);
|
760
|
+
NDTYPES_API int ndt_fast_binary_fixed_typecheck(ndt_apply_spec_t *spec, const ndt_t *sig,
|
761
|
+
const ndt_t *types[], const int nin, const int nout,
|
762
|
+
const bool check_broadcast, ndt_context_t *ctx);
|
763
|
+
|
764
|
+
NDTYPES_API int64_t ndt_itemsize(const ndt_t *t);
|
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
|
+
|
769
|
+
|
770
|
+
/*****************************************************************************/
|
771
|
+
/* Input/Output */
|
772
|
+
/*****************************************************************************/
|
773
|
+
|
774
|
+
/*** String to primitive conversion ***/
|
775
|
+
NDTYPES_API bool ndt_strtobool(const char *v, ndt_context_t *ctx);
|
776
|
+
NDTYPES_API char ndt_strtochar(const char *v, ndt_context_t *ctx);
|
777
|
+
NDTYPES_API long ndt_strtol(const char *v, long min, long max, ndt_context_t *ctx);
|
778
|
+
NDTYPES_API long long ndt_strtoll(const char *v, long long min, long long max, ndt_context_t *ctx);
|
779
|
+
NDTYPES_API unsigned long ndt_strtoul(const char *v, unsigned long max, ndt_context_t *ctx);
|
780
|
+
NDTYPES_API unsigned long long ndt_strtoull(const char *v, unsigned long long max, ndt_context_t *ctx);
|
781
|
+
NDTYPES_API float ndt_strtof(const char *v, ndt_context_t *ctx);
|
782
|
+
NDTYPES_API double ndt_strtod(const char *v, ndt_context_t *ctx);
|
783
|
+
|
784
|
+
/*** Type to string conversion ***/
|
785
|
+
NDTYPES_API char *ndt_as_string(const ndt_t *t, ndt_context_t *ctx);
|
786
|
+
NDTYPES_API char *ndt_list_as_string(const ndt_t *types[], int64_t len, ndt_context_t *ctx);
|
787
|
+
NDTYPES_API char *ndt_indent(const ndt_t *t, ndt_context_t *ctx);
|
788
|
+
NDTYPES_API char *ndt_ast_repr(const ndt_t *t, ndt_context_t *ctx);
|
789
|
+
|
790
|
+
NDTYPES_API int64_t ndt_serialize(char **dest, const ndt_t * const t, ndt_context_t *ctx);
|
791
|
+
NDTYPES_API const ndt_t *ndt_deserialize(const char * const ptr, int64_t len, ndt_context_t *ctx);
|
792
|
+
|
793
|
+
|
794
|
+
/*****************************************************************************/
|
795
|
+
/* Typedef */
|
796
|
+
/*****************************************************************************/
|
797
|
+
|
798
|
+
typedef struct {
|
799
|
+
const ndt_t *type;
|
800
|
+
ndt_methods_t meth;
|
801
|
+
} ndt_typedef_t;
|
802
|
+
|
803
|
+
/* Typedef for nominal types */
|
804
|
+
NDTYPES_API int ndt_typedef_add(const char *name, const ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
|
805
|
+
NDTYPES_API const ndt_typedef_t *ndt_typedef_find(const char *name, ndt_context_t *ctx);
|
806
|
+
|
807
|
+
NDTYPES_API int ndt_typedef(const char *name, const ndt_t *type, const ndt_methods_t *m, ndt_context_t *ctx);
|
808
|
+
NDTYPES_API int ndt_typedef_from_string(const char *name, const char *type, const ndt_methods_t *m, ndt_context_t *ctx);
|
809
|
+
|
810
|
+
|
811
|
+
/*****************************************************************************/
|
812
|
+
/* Allocate types */
|
813
|
+
/*****************************************************************************/
|
814
|
+
|
815
|
+
NDTYPES_API ndt_t *ndt_new(enum ndt tag, uint32_t flags, ndt_context_t *ctx);
|
816
|
+
NDTYPES_API ndt_t *ndt_function_new(int64_t nargs, ndt_context_t *ctx);
|
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);
|
823
|
+
|
824
|
+
|
825
|
+
/*****************************************************************************/
|
826
|
+
/* Construct types */
|
827
|
+
/*****************************************************************************/
|
828
|
+
|
829
|
+
/* Special types */
|
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);
|
832
|
+
|
833
|
+
/* Any */
|
834
|
+
NDTYPES_API const ndt_t *ndt_any_kind(bool opt, ndt_context_t *ctx);
|
835
|
+
|
836
|
+
/* Dimensions */
|
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);
|
840
|
+
|
841
|
+
NDTYPES_API const ndt_t *ndt_abstract_var_dim(const ndt_t *type, bool opt, ndt_context_t *ctx);
|
842
|
+
NDTYPES_API int64_t ndt_var_indices(int64_t *res_start, int64_t *res_step, const ndt_t *t,
|
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);
|
846
|
+
NDTYPES_API ndt_slice_t *ndt_var_add_slice(int32_t *nslices, const ndt_t *t,
|
847
|
+
int64_t start, int64_t stop, int64_t step,
|
848
|
+
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);
|
857
|
+
|
858
|
+
NDTYPES_API const ndt_t *ndt_array(const ndt_t *type, bool opt, ndt_context_t *ctx);
|
859
|
+
|
860
|
+
/* Dtypes */
|
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);
|
866
|
+
|
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);
|
870
|
+
|
871
|
+
/* Scalars */
|
872
|
+
NDTYPES_API const ndt_t *ndt_scalar_kind(bool opt, ndt_context_t *ctx);
|
873
|
+
|
874
|
+
NDTYPES_API const ndt_t *ndt_categorical(const ndt_value_t *types, int64_t ntypes, bool opt, ndt_context_t *ctx);
|
875
|
+
|
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);
|
878
|
+
|
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);
|
881
|
+
|
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);
|
885
|
+
|
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);
|
890
|
+
|
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);
|
895
|
+
|
896
|
+
/* Type variable */
|
897
|
+
NDTYPES_API const ndt_t *ndt_typevar(char *name, ndt_context_t *ctx);
|
898
|
+
|
899
|
+
|
900
|
+
/******************************************************************************/
|
901
|
+
/* Parsing */
|
902
|
+
/******************************************************************************/
|
903
|
+
|
904
|
+
/* Metadata is currently limited to var-dimension offsets. */
|
905
|
+
|
906
|
+
/*
|
907
|
+
* Metadata is read from the type string and managed by the type. This is
|
908
|
+
* convenient but can waste a lot of space when offset arrays are large.
|
909
|
+
*/
|
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);
|
913
|
+
NDTYPES_API char *ndt_to_bpformat(const ndt_t *t, ndt_context_t *ctx);
|
914
|
+
NDTYPES_API int ndt_to_nbformat(char **sig, char **dtype, const ndt_t *t, ndt_context_t *ctx);
|
915
|
+
|
916
|
+
/* Unstable API */
|
917
|
+
NDTYPES_API const ndt_t *ndt_from_string_v(const char *input, ndt_context_t *ctx);
|
918
|
+
|
919
|
+
|
920
|
+
/*
|
921
|
+
* Metadata is read from the type string and extracted for external management.
|
922
|
+
* The type still has pointers to the metadata. This scheme is used for sharing
|
923
|
+
* offsets between copies or subtypes of a type.
|
924
|
+
*/
|
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);
|
927
|
+
|
928
|
+
/* Metadata is provided and managed by an external source. */
|
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);
|
931
|
+
|
932
|
+
NDTYPES_API ndt_meta_t *ndt_meta_new(ndt_context_t *ctx);
|
933
|
+
NDTYPES_API void ndt_meta_clear(ndt_meta_t *m);
|
934
|
+
NDTYPES_API void ndt_meta_del(ndt_meta_t *m);
|
935
|
+
|
936
|
+
|
937
|
+
/******************************************************************************/
|
938
|
+
/* Library initialization and tables */
|
939
|
+
/******************************************************************************/
|
940
|
+
|
941
|
+
NDTYPES_API int ndt_init(ndt_context_t *ctx);
|
942
|
+
NDTYPES_API void ndt_finalize(void);
|
943
|
+
|
944
|
+
|
945
|
+
/******************************************************************************/
|
946
|
+
/* Error Macros */
|
947
|
+
/******************************************************************************/
|
948
|
+
|
949
|
+
#define ndt_internal_error(msg) \
|
950
|
+
do { \
|
951
|
+
fprintf(stderr, "%s:%d: internal error: %s\n", __FILE__, __LINE__, msg); \
|
952
|
+
abort(); \
|
953
|
+
} while (0)
|
954
|
+
|
955
|
+
#define ndt_warn(msg) \
|
956
|
+
do { \
|
957
|
+
fprintf(stderr, "%s:%d: warning: %s\n", __FILE__, __LINE__, msg); \
|
958
|
+
} while (0)
|
959
|
+
|
960
|
+
|
961
|
+
/******************************************************************************/
|
962
|
+
/* Memory handling */
|
963
|
+
/******************************************************************************/
|
964
|
+
|
965
|
+
NDTYPES_API extern void *(* ndt_mallocfunc)(size_t size);
|
966
|
+
NDTYPES_API extern void *(* ndt_callocfunc)(size_t nmemb, size_t size);
|
967
|
+
NDTYPES_API extern void *(* ndt_reallocfunc)(void *ptr, size_t size);
|
968
|
+
NDTYPES_API extern void (* ndt_freefunc)(void *ptr);
|
969
|
+
|
970
|
+
NDTYPES_API void *ndt_alloc(int64_t nmemb, int64_t size);
|
971
|
+
NDTYPES_API void *ndt_alloc_size(size_t size);
|
972
|
+
NDTYPES_API void *ndt_calloc(int64_t nmemb, int64_t size);
|
973
|
+
NDTYPES_API void *ndt_realloc(void *ptr, int64_t nmemb, int64_t size);
|
974
|
+
NDTYPES_API void ndt_free(void *ptr);
|
975
|
+
|
976
|
+
NDTYPES_API void *ndt_aligned_calloc(uint16_t alignment, int64_t size);
|
977
|
+
NDTYPES_API void ndt_aligned_free(void *ptr);
|
978
|
+
|
979
|
+
|
980
|
+
/******************************************************************************/
|
981
|
+
/* Low level details */
|
982
|
+
/******************************************************************************/
|
983
|
+
|
984
|
+
typedef struct {
|
985
|
+
int64_t size;
|
986
|
+
uint8_t *data;
|
987
|
+
} ndt_bytes_t;
|
988
|
+
|
989
|
+
typedef struct {
|
990
|
+
int64_t shape;
|
991
|
+
char *data;
|
992
|
+
} ndt_array_t;
|
993
|
+
|
994
|
+
typedef int64_t ndt_categorical_t;
|
995
|
+
|
996
|
+
|
997
|
+
#ifdef __cplusplus
|
998
|
+
} /* END extern "C" */
|
999
|
+
#endif
|
1000
|
+
|
1001
|
+
|
1002
|
+
#endif /* NDTYPES_H */
|