ndtypes 0.2.0dev4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,68 @@
|
|
|
1
|
+
.. meta::
|
|
2
|
+
:robots: index,follow
|
|
3
|
+
:description: libndtypes documentation
|
|
4
|
+
|
|
5
|
+
.. sectionauthor:: Stefan Krah <skrah at bytereef.org>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Encodings
|
|
10
|
+
=========
|
|
11
|
+
|
|
12
|
+
Some types support encoding parameters.
|
|
13
|
+
|
|
14
|
+
.. code-block:: c
|
|
15
|
+
|
|
16
|
+
#include <ndtypes.h>
|
|
17
|
+
|
|
18
|
+
/* Encoding for characters and strings */
|
|
19
|
+
enum ndt_encoding {
|
|
20
|
+
Ascii,
|
|
21
|
+
Utf8,
|
|
22
|
+
Utf16,
|
|
23
|
+
Utf32,
|
|
24
|
+
Ucs2,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Functions
|
|
29
|
+
---------
|
|
30
|
+
|
|
31
|
+
.. topic:: ndt_encoding_from_string
|
|
32
|
+
|
|
33
|
+
.. code-block:: c
|
|
34
|
+
|
|
35
|
+
enum ndt_encoding ndt_encoding_from_string(const char *s, ndt_context_t *ctx);
|
|
36
|
+
|
|
37
|
+
Convert a string to the corresponding enum value. The caller must use
|
|
38
|
+
:func:`ndt_err_occurred` to check for errors.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
.. topic:: ndt_encoding_as_string
|
|
42
|
+
|
|
43
|
+
.. code-block:: c
|
|
44
|
+
|
|
45
|
+
const char *ndt_encoding_as_string(enum ndt_encoding encoding);
|
|
46
|
+
|
|
47
|
+
Convert an encoding to its string representation.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
.. topic:: ndt_sizeof_encoding
|
|
51
|
+
|
|
52
|
+
.. code-block:: c
|
|
53
|
+
|
|
54
|
+
size_t ndt_sizeof_encoding(enum ndt_encoding encoding);
|
|
55
|
+
|
|
56
|
+
Return the memory size of a single code point.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
.. topic:: ndt_alignof_encoding
|
|
60
|
+
|
|
61
|
+
.. code-block:: c
|
|
62
|
+
|
|
63
|
+
uint16_t ndt_alignof_encoding(enum ndt_encoding encoding);
|
|
64
|
+
|
|
65
|
+
Return the alignment of a single code point.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
.. meta::
|
|
2
|
+
:robots: index,follow
|
|
3
|
+
:description: libndtypes documentation
|
|
4
|
+
|
|
5
|
+
.. sectionauthor:: Stefan Krah <skrah at bytereef.org>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Fields and values
|
|
9
|
+
=================
|
|
10
|
+
|
|
11
|
+
Some API functions expect fields for creating tuple or record types or values
|
|
12
|
+
for creating categorical types.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Fields
|
|
16
|
+
------
|
|
17
|
+
|
|
18
|
+
.. topic:: uint16_opt
|
|
19
|
+
|
|
20
|
+
.. code-block:: c
|
|
21
|
+
|
|
22
|
+
enum ndt_option {
|
|
23
|
+
None,
|
|
24
|
+
Some
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
typedef struct {
|
|
28
|
+
enum ndt_option tag;
|
|
29
|
+
uint16_t Some;
|
|
30
|
+
} uint16_opt_t;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Due to the multitude of options in creating fields a number of functions take
|
|
34
|
+
a *uint16_opt_t* struct. If *tag* is *None*, no value has been specified
|
|
35
|
+
and the *Some* field is undefined.
|
|
36
|
+
|
|
37
|
+
If *tag* is *Some*, the value in the *Some* field has been explicitly given.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Functions
|
|
41
|
+
---------
|
|
42
|
+
|
|
43
|
+
.. topic:: ndt_field
|
|
44
|
+
|
|
45
|
+
.. code-block:: c
|
|
46
|
+
|
|
47
|
+
ndt_field_t *ndt_field(char *name, ndt_t *type, uint16_opt_t align,
|
|
48
|
+
uint16_opt_t pack, uint16_opt_t pad, ndt_context_t *ctx);
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
Create a new field. For tuples, *name* is :c:macro:`NULL`. The `align`
|
|
52
|
+
and `pack` options are mutually exclusive and have exactly the same
|
|
53
|
+
function as *gcc's* `aligned` and `packed` attributes when applied to
|
|
54
|
+
individual fields.
|
|
55
|
+
|
|
56
|
+
The `pad` field has no influence on the field layout. It is present to
|
|
57
|
+
enable sanity checks when an explicit number of padding bytes has been
|
|
58
|
+
specified (Example: PEP-3118).
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
.. topic:: ndt_field_del
|
|
62
|
+
|
|
63
|
+
.. code-block:: c
|
|
64
|
+
|
|
65
|
+
void ndt_field_del(ndt_field_t *field);
|
|
66
|
+
|
|
67
|
+
Deallocate a field.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
.. topic:: ndt_field_array_del
|
|
71
|
+
|
|
72
|
+
.. code-block:: c
|
|
73
|
+
|
|
74
|
+
void ndt_field_array_del(ndt_field_t *fields, int64_t shape);
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
Deallocate an array of fields.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Values
|
|
81
|
+
------
|
|
82
|
+
|
|
83
|
+
.. topic:: values
|
|
84
|
+
|
|
85
|
+
.. code-block:: c
|
|
86
|
+
|
|
87
|
+
/* Selected values for the categorical type. */
|
|
88
|
+
enum ndt_value {
|
|
89
|
+
ValBool,
|
|
90
|
+
ValInt64,
|
|
91
|
+
ValFloat64,
|
|
92
|
+
ValString,
|
|
93
|
+
ValNA,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
typedef struct {
|
|
97
|
+
enum ndt_value tag;
|
|
98
|
+
union {
|
|
99
|
+
bool ValBool;
|
|
100
|
+
int64_t ValInt64;
|
|
101
|
+
double ValFloat64;
|
|
102
|
+
char *ValString;
|
|
103
|
+
};
|
|
104
|
+
} ndt_value_t;
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
The categorical type contains values. Currently a small number of primitive
|
|
108
|
+
types are supported. It would be possible to use memory typed by *ndt_t* itself
|
|
109
|
+
either by introducing a circular relationship between libndtypes and container
|
|
110
|
+
libraries or by duplicating parts of a container library.
|
|
111
|
+
|
|
112
|
+
It remains to be seen if such an added complexity is useful.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
.. topic:: ndt_value_from_number
|
|
117
|
+
|
|
118
|
+
.. code-block:: c
|
|
119
|
+
|
|
120
|
+
ndt_value_t *ndt_value_from_number(enum ndt_value tag, char *v, ndt_context_t *ctx);
|
|
121
|
+
|
|
122
|
+
Construct a number or boolean value from a string. *tag* must be one of
|
|
123
|
+
:c:macro:`ValBool`, :c:macro:`ValInt64`, or :c:macro:`ValFloat64`.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
.. topic:: ndt_value_from_string
|
|
127
|
+
|
|
128
|
+
.. code-block:: c
|
|
129
|
+
|
|
130
|
+
ndt_value_t *ndt_value_from_string(char *v, ndt_context_t *ctx);
|
|
131
|
+
|
|
132
|
+
Construct a :c:macro:`ValString` value from a string.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
.. topic:: *ndt_value_na
|
|
136
|
+
|
|
137
|
+
.. code-block:: c
|
|
138
|
+
|
|
139
|
+
ndt_value_t *ndt_value_na(ndt_context_t *ctx);
|
|
140
|
+
|
|
141
|
+
Construct the :c:macro:`NA` value.
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
.. topic:: ndt_value_equal
|
|
145
|
+
|
|
146
|
+
.. code-block:: c
|
|
147
|
+
|
|
148
|
+
int ndt_value_equal(const ndt_value_t *x, const ndt_value_t *y);
|
|
149
|
+
|
|
150
|
+
Determine if two values are equal. :c:macro:`NA` compares not equal to
|
|
151
|
+
itself.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
.. topic:: ndt_value_mem_equal
|
|
155
|
+
|
|
156
|
+
.. code-block:: c
|
|
157
|
+
|
|
158
|
+
ndt_value_mem_equal(const ndt_value_t *x, const ndt_value_t *y);
|
|
159
|
+
|
|
160
|
+
Determine if two values are structurally equal. :c:macro:`NA` compares
|
|
161
|
+
equal to itself.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
.. topic:: ndt_value_compare
|
|
165
|
+
|
|
166
|
+
.. code-block:: c
|
|
167
|
+
|
|
168
|
+
int ndt_value_compare(const ndt_value_t *x, const ndt_value_t *y);
|
|
169
|
+
|
|
170
|
+
Compare values according to a sorting order. :c:macro:`NA` compares equal
|
|
171
|
+
to itself.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.. meta::
|
|
2
|
+
:robots: index,follow
|
|
3
|
+
:description: libndtypes documentation
|
|
4
|
+
|
|
5
|
+
.. sectionauthor:: Stefan Krah <skrah at bytereef.org>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Functions
|
|
9
|
+
=========
|
|
10
|
+
|
|
11
|
+
Most library functions are for creating types. The functions in this section
|
|
12
|
+
operate *on* types.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Copying
|
|
16
|
+
-------
|
|
17
|
+
|
|
18
|
+
.. topic:: ndt_copy
|
|
19
|
+
|
|
20
|
+
.. code-block:: c
|
|
21
|
+
|
|
22
|
+
ndt_t *ndt_copy(const ndt_t *t, ndt_context_t *ctx);
|
|
23
|
+
|
|
24
|
+
Create a copy of the argument. This is an important function, since types
|
|
25
|
+
should be immutable.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Equality
|
|
29
|
+
--------
|
|
30
|
+
|
|
31
|
+
.. topic:: ndt_equal
|
|
32
|
+
|
|
33
|
+
.. code-block:: c
|
|
34
|
+
|
|
35
|
+
int ndt_equal(const ndt_t *t, const ndt_t *u);
|
|
36
|
+
|
|
37
|
+
Return 1 if *t* and *u* are structurally equal, *0* otherwise.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Pattern matching
|
|
41
|
+
----------------
|
|
42
|
+
|
|
43
|
+
.. topic:: ndt_match
|
|
44
|
+
|
|
45
|
+
.. code-block:: c
|
|
46
|
+
|
|
47
|
+
int ndt_match(const ndt_t *p, const ndt_t *c, ndt_context_t *ctx);
|
|
48
|
+
|
|
49
|
+
Match concrete candidate *c* against the (possibly abstract) pattern *p*.
|
|
50
|
+
|
|
51
|
+
This is the main function used in type checking.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Type checking
|
|
56
|
+
-------------
|
|
57
|
+
|
|
58
|
+
.. topic:: ndt_typecheck
|
|
59
|
+
|
|
60
|
+
.. code-block:: c
|
|
61
|
+
|
|
62
|
+
ndt_t *ndt_typecheck(const ndt_t *f, const ndt_t *args, int *outer_dims, ndt_context_t *ctx);
|
|
63
|
+
|
|
64
|
+
Take a function type *f*, check if it can accept the concrete type *args*.
|
|
65
|
+
*args* must be a tuple type that contains the individual arguments.
|
|
66
|
+
|
|
67
|
+
The return value is the inferred return type.
|
|
68
|
+
|
|
69
|
+
Store the number of outer dimensions that need to be traversed before applying
|
|
70
|
+
the function kernel.
|
|
71
|
+
|
|
72
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
.. meta::
|
|
2
|
+
:robots: index, follow
|
|
3
|
+
:description: libndtypes documentation
|
|
4
|
+
:keywords: libndtypes, C, array computing
|
|
5
|
+
|
|
6
|
+
.. sectionauthor:: Stefan Krah <skrah at bytereef.org>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
libndtypes
|
|
10
|
+
----------
|
|
11
|
+
|
|
12
|
+
libndtypes implements the type part of a compiler frontend. It can describe
|
|
13
|
+
C types needed for array computing and additionally includes symbolic types
|
|
14
|
+
for dynamic type checking.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
libndtypes has the concept of abstract and concrete types. Concrete types
|
|
18
|
+
contain the exact data layout and all sizes that are required to access
|
|
19
|
+
subtypes or individual elements in memory.
|
|
20
|
+
|
|
21
|
+
Abstract types are for type checking and include functions, symbolic
|
|
22
|
+
dimensions and type variables. Module support is planned at a later stage.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Concrete types with rich layout information make it possible to write relatively
|
|
26
|
+
small container libraries that can traverse memory without type erasure.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
.. toctree::
|
|
30
|
+
|
|
31
|
+
init.rst
|
|
32
|
+
context.rst
|
|
33
|
+
types.rst
|
|
34
|
+
predicates.rst
|
|
35
|
+
functions.rst
|
|
36
|
+
typedef.rst
|
|
37
|
+
io.rst
|
|
38
|
+
encodings.rst
|
|
39
|
+
fields-values.rst
|
|
40
|
+
memory.rst
|
|
41
|
+
util.rst
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.. meta::
|
|
2
|
+
:robots: index,follow
|
|
3
|
+
:description: libndtypes documentation
|
|
4
|
+
|
|
5
|
+
.. sectionauthor:: Stefan Krah <skrah at bytereef.org>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Initialization and tables
|
|
9
|
+
=========================
|
|
10
|
+
|
|
11
|
+
libndtypes has global tables that need to be initialized and finalized.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
.. code-block:: c
|
|
15
|
+
|
|
16
|
+
int ndt_init(ndt_context_t *ctx);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
Initialize the global tables. This function must be called once at program
|
|
20
|
+
start before using any other libndtypes functions.
|
|
21
|
+
|
|
22
|
+
Return *0* on success and *-1* otherwise.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
.. code-block:: c
|
|
26
|
+
|
|
27
|
+
void ndt_finalize(void);
|
|
28
|
+
|
|
29
|
+
Deallocate the global tables. This function may be called once at program
|
|
30
|
+
end for the benefit of memory debuggers.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
.. code-block:: c
|
|
34
|
+
|
|
35
|
+
int ndt_typedef_add(const char *name, const ndt_t *type, ndt_context_t *ctx);
|
|
36
|
+
|
|
37
|
+
Add a type alias for *type* to the typedef table. *name* must be globally
|
|
38
|
+
unique. The function steals the *type* argument.
|
|
39
|
+
|
|
40
|
+
On error, deallocate *type* and return *-1*. Return *0* otherwise.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
.. code-block:: c
|
|
44
|
+
|
|
45
|
+
const ndt_t *ndt_typedef_find(const char *name, ndt_context_t *ctx);
|
|
46
|
+
|
|
47
|
+
Try to find the type associated with *name* in the typedef table. On success,
|
|
48
|
+
return a const pointer to the type, :c:macro:`NULL` otherwise.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
.. meta::
|
|
2
|
+
:robots: index,follow
|
|
3
|
+
:description: libndtypes documentation
|
|
4
|
+
|
|
5
|
+
.. sectionauthor:: Stefan Krah <skrah at bytereef.org>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Input/output
|
|
9
|
+
============
|
|
10
|
+
|
|
11
|
+
Functions for creating and displaying types.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Input
|
|
15
|
+
-----
|
|
16
|
+
|
|
17
|
+
.. topic:: ndt_from_file
|
|
18
|
+
|
|
19
|
+
.. code-block:: c
|
|
20
|
+
|
|
21
|
+
ndt_t *ndt_from_file(const char *name, ndt_context_t *ctx);
|
|
22
|
+
|
|
23
|
+
Create a type from a file that contains the datashape representation.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
.. topic:: ndt_from_string
|
|
27
|
+
|
|
28
|
+
.. code-block:: c
|
|
29
|
+
|
|
30
|
+
ndt_t *ndt_from_string(const char *input, ndt_context_t *ctx);
|
|
31
|
+
|
|
32
|
+
Create a type from a string in datashape syntax. This is the primary function
|
|
33
|
+
for creating types.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
.. topic:: ndt_from_metadata_and_dtype
|
|
37
|
+
|
|
38
|
+
.. code-block:: c
|
|
39
|
+
|
|
40
|
+
typedef struct {
|
|
41
|
+
int num_offset_arrays; /* number of offset arrays */
|
|
42
|
+
int32_t num_offsets[NDT_MAX_DIM]; /* lengths of the offset arrays */
|
|
43
|
+
int32_t *offset_arrays[NDT_MAX_DIM]; /* offset arrays */
|
|
44
|
+
} ndt_meta_t;
|
|
45
|
+
|
|
46
|
+
ndt_t *ndt_from_metadata_and_dtype(const ndt_meta_t *m, const char *dtype, ndt_context_t *ctx);
|
|
47
|
+
|
|
48
|
+
Create a concrete var dimension using the external offset arrays given
|
|
49
|
+
in the :c:macro:`ndt_meta_t` struct.
|
|
50
|
+
|
|
51
|
+
The application is responsible for keeping the offset arrays alive while the
|
|
52
|
+
type *and all copies of the type* exist.
|
|
53
|
+
|
|
54
|
+
This is not as difficult as it sounds. One approach that utilizes a resource
|
|
55
|
+
manager object is implemented in the Python ndtypes module.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
.. topic:: ndt_from_bpformat
|
|
59
|
+
|
|
60
|
+
.. code-block:: c
|
|
61
|
+
|
|
62
|
+
ndt_t *ndt_from_bpformat(const char *input, ndt_context_t *ctx);
|
|
63
|
+
|
|
64
|
+
Create a type from a buffer protocol format string (PEP-3118 syntax). This
|
|
65
|
+
is useful for translating dtypes in a `Py_buffer` struct.
|
|
66
|
+
|
|
67
|
+
The outer dimensions specified by the `Py_buffer` shape member need to
|
|
68
|
+
be created separately.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Output
|
|
72
|
+
------
|
|
73
|
+
|
|
74
|
+
.. topic:: ndt_as_string
|
|
75
|
+
|
|
76
|
+
.. code-block:: c
|
|
77
|
+
|
|
78
|
+
char *ndt_as_string(const ndt_t *t, ndt_context_t *ctx);
|
|
79
|
+
|
|
80
|
+
Convert *t* to its string representation. This currently omits some layout
|
|
81
|
+
details like alignment, packing or Fortran layout.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
.. topic:: ndt_indent
|
|
85
|
+
|
|
86
|
+
.. code-block:: c
|
|
87
|
+
|
|
88
|
+
char *ndt_indent(const ndt_t *t, ndt_context_t *ctx);
|
|
89
|
+
|
|
90
|
+
Same as :func:`ndt_as_string`, but indent the result.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
.. topic:: ndt_ast_repr
|
|
94
|
+
|
|
95
|
+
.. code-block:: c
|
|
96
|
+
|
|
97
|
+
char *ndt_ast_repr(const ndt_t *t, ndt_context_t *ctx);
|
|
98
|
+
|
|
99
|
+
Return the representation of the abstract syntax tree of the input type.
|
|
100
|
+
This representation includes all low level details.
|