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,319 @@
|
|
|
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
|
+
#include "pymacro.h"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/******************************************************************************/
|
|
38
|
+
/* Module */
|
|
39
|
+
/******************************************************************************/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
PyDoc_STRVAR(doc_module, "ndtypes module");
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/******************************************************************************/
|
|
47
|
+
/* ndt properties */
|
|
48
|
+
/******************************************************************************/
|
|
49
|
+
|
|
50
|
+
PyDoc_STRVAR(doc_align,
|
|
51
|
+
"\n\
|
|
52
|
+
Return the alignment specified by the type.\n\
|
|
53
|
+
\n\
|
|
54
|
+
>>> t = ndt(\"{a: 100000 * uint8, b: 200000 * uint8, align=512}\")\n\
|
|
55
|
+
>>> t.align\n\
|
|
56
|
+
512\n\
|
|
57
|
+
\n");
|
|
58
|
+
|
|
59
|
+
PyDoc_STRVAR(doc_datasize,
|
|
60
|
+
"\n\
|
|
61
|
+
Return the datasize required by the type. The type must be concrete.\n\
|
|
62
|
+
\n\
|
|
63
|
+
>>> t = ndt(\"10 * 2 * int64\")\n\
|
|
64
|
+
>>> t.datasize\n\
|
|
65
|
+
160\n\
|
|
66
|
+
>>>\n\
|
|
67
|
+
>>> t = ndt(\"10 * N * int64\")\n\
|
|
68
|
+
>>> t.datasize\n\
|
|
69
|
+
Traceback (most recent call last):\n\
|
|
70
|
+
File \"<stdin>\", line 1, in <module>\n\
|
|
71
|
+
TypeError: abstract type has no datasize\n\
|
|
72
|
+
\n");
|
|
73
|
+
|
|
74
|
+
PyDoc_STRVAR(doc_itemsize,
|
|
75
|
+
"\n\
|
|
76
|
+
Return the itemsize of the type. For types with ndim==0, itemsize==datasize.\n\
|
|
77
|
+
\n\
|
|
78
|
+
>>> t = ndt(\"2 * 10 * complex128\")\n\
|
|
79
|
+
>>> t.itemsize\n\
|
|
80
|
+
16\n\
|
|
81
|
+
\n");
|
|
82
|
+
|
|
83
|
+
PyDoc_STRVAR(doc_ndim,
|
|
84
|
+
"\n\
|
|
85
|
+
Return the number of dimensions of the type.\n\
|
|
86
|
+
\n\
|
|
87
|
+
>>> t = ndt(\"2 * 3 * 4 * 5 * complex64\")\n\
|
|
88
|
+
>>> t.ndim\n\
|
|
89
|
+
4\n\
|
|
90
|
+
\n");
|
|
91
|
+
|
|
92
|
+
PyDoc_STRVAR(doc_shape,
|
|
93
|
+
"\n\
|
|
94
|
+
Return the shape of the type. For NumPy compatibility, return the empty\n\
|
|
95
|
+
tuple if ndim==0.\n\
|
|
96
|
+
\n\
|
|
97
|
+
>>> t = ndt(\"2 * 3 * 4 * 5 * complex64\")\n\
|
|
98
|
+
>>> t.shape\n\
|
|
99
|
+
(2, 3, 4, 5)\n\
|
|
100
|
+
\n\
|
|
101
|
+
>>> t = ndt(\"int64\")\n\
|
|
102
|
+
>>> t.shape\n\
|
|
103
|
+
()\n\
|
|
104
|
+
\n");
|
|
105
|
+
|
|
106
|
+
PyDoc_STRVAR(doc_strides,
|
|
107
|
+
"\n\
|
|
108
|
+
Return the strides of the type. For NumPy compatibility, return the empty\n\
|
|
109
|
+
tuple if ndim==0. Internally, ndtypes uses steps instead of strides. The\n\
|
|
110
|
+
equality stride==step*itemsize always holds.\n\
|
|
111
|
+
\n\
|
|
112
|
+
>>> t = ndt(\"2 * 3 * 4 * 5 * complex64\")\n\
|
|
113
|
+
>>> t.strides\n\
|
|
114
|
+
(480, 160, 40, 8)\n\
|
|
115
|
+
\n\
|
|
116
|
+
>>> t = ndt(\"int64\")\n\
|
|
117
|
+
>>> t.strides\n\
|
|
118
|
+
()\n\
|
|
119
|
+
\n");
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/******************************************************************************/
|
|
123
|
+
/* ndt methods */
|
|
124
|
+
/******************************************************************************/
|
|
125
|
+
|
|
126
|
+
PyDoc_STRVAR(doc_ast_repr,
|
|
127
|
+
"ast_repr($self, /)\n--\n\n\
|
|
128
|
+
Return the string representation of the internal abstract syntax tree.\n\
|
|
129
|
+
\n\
|
|
130
|
+
>>> t = ndt(\"2 * {a: uint8, b: int32, pack=1}\")\n\
|
|
131
|
+
>>> print(t.ast_repr())\n\
|
|
132
|
+
FixedDim(\n\
|
|
133
|
+
Record(\n\
|
|
134
|
+
RecordField(\n\
|
|
135
|
+
name='a',\n\
|
|
136
|
+
type=Uint8(access=Concrete, ndim=0, datasize=1, align=1, flags=[]),\n\
|
|
137
|
+
offset=0, align=1, pad=0\n\
|
|
138
|
+
),\n\
|
|
139
|
+
RecordField(\n\
|
|
140
|
+
name='b',\n\
|
|
141
|
+
type=Int32(access=Concrete, ndim=0, datasize=4, align=4, flags=[]),\n\
|
|
142
|
+
offset=1, align=1, pad=0\n\
|
|
143
|
+
),\n\
|
|
144
|
+
access=Concrete, ndim=0, datasize=5, align=1, flags=[]\n\
|
|
145
|
+
),\n\
|
|
146
|
+
shape=2, itemsize=5, step=1,\n\
|
|
147
|
+
access=Concrete, ndim=1, datasize=10, align=1, flags=[]\n\
|
|
148
|
+
)\n\
|
|
149
|
+
\n");
|
|
150
|
+
|
|
151
|
+
PyDoc_STRVAR(doc_from_format,
|
|
152
|
+
"from_format($self, fmt, /)\n--\n\n\
|
|
153
|
+
Create a type from a buffer protocol format string.\n\
|
|
154
|
+
\n\
|
|
155
|
+
>>> ndt.from_format(\"T{B:a:L:b:}\")\n\
|
|
156
|
+
ndt(\"{a : uint8, b : uint64}\")\n\
|
|
157
|
+
\n");
|
|
158
|
+
|
|
159
|
+
PyDoc_STRVAR(doc_deserialize,
|
|
160
|
+
"deserialize($self, bytes, /)\n--\n\n\
|
|
161
|
+
Deserialize a bytes object to a type .\n\
|
|
162
|
+
\n\
|
|
163
|
+
>>> t = ndt(\"int64\")\n\
|
|
164
|
+
>>> b = t.serialize()\n\
|
|
165
|
+
>>> ndt.deserialize(b)\n\
|
|
166
|
+
ndt(\"int64\")\n\
|
|
167
|
+
\n");
|
|
168
|
+
|
|
169
|
+
PyDoc_STRVAR(doc_is_c_contiguous,
|
|
170
|
+
"is_c_contiguous($self, /)\n--\n\n\
|
|
171
|
+
Return True if the type is a C-contiguous array and False otherwise.\n\
|
|
172
|
+
\n\
|
|
173
|
+
>>> t = ndt(\"3 * 10 * float64\")\n\
|
|
174
|
+
>>> t.is_c_contiguous()\n\
|
|
175
|
+
True\n\
|
|
176
|
+
\n");
|
|
177
|
+
|
|
178
|
+
PyDoc_STRVAR(doc_is_f_contiguous,
|
|
179
|
+
"is_f_contiguous($self, /)\n--\n\n\
|
|
180
|
+
Return True if the type is a Fortran-contiguous array and False otherwise.\n\
|
|
181
|
+
\n\
|
|
182
|
+
>>> t = ndt(\"!3 * 10 * float64\")\n\
|
|
183
|
+
>>> t.is_c_contiguous()\n\
|
|
184
|
+
False\n\
|
|
185
|
+
>>> t.is_f_contiguous()\n\
|
|
186
|
+
True\n\
|
|
187
|
+
\n");
|
|
188
|
+
|
|
189
|
+
PyDoc_STRVAR(doc_isabstract,
|
|
190
|
+
"isabstract($self, /)\n--\n\n\
|
|
191
|
+
Return True if the type is abstract and False otherwise.\n\
|
|
192
|
+
\n\
|
|
193
|
+
>>> t = ndt(\"(int8, string)\")\n\
|
|
194
|
+
>>> t.isabstract()\n\
|
|
195
|
+
False\n\
|
|
196
|
+
\n\
|
|
197
|
+
>>> t = ndt(\"(int8, T)\")\n\
|
|
198
|
+
>>> t.isabstract()\n\
|
|
199
|
+
True\n\
|
|
200
|
+
\n");
|
|
201
|
+
|
|
202
|
+
PyDoc_STRVAR(doc_iscomplex,
|
|
203
|
+
"iscomplex($self, /)\n--\n\n\
|
|
204
|
+
Return True if the type is complex and False otherwise.\n\
|
|
205
|
+
\n\
|
|
206
|
+
>>> t = ndt(\"complex128\")\n\
|
|
207
|
+
>>> t.iscomplex()\n\
|
|
208
|
+
True\n\
|
|
209
|
+
\n");
|
|
210
|
+
|
|
211
|
+
PyDoc_STRVAR(doc_isconcrete,
|
|
212
|
+
"isconcrete($self, /)\n--\n\n\
|
|
213
|
+
Return True if the type is concrete and False otherwise.\n\
|
|
214
|
+
\n\
|
|
215
|
+
>>> t = ndt(\"2 * int64\")\n\
|
|
216
|
+
>>> t.isconcrete()\n\
|
|
217
|
+
True\n\
|
|
218
|
+
>>>\n\
|
|
219
|
+
>>> t = ndt(\"N * int64\")\n\
|
|
220
|
+
>>> t.isconcrete()\n\
|
|
221
|
+
False\n\
|
|
222
|
+
\n");
|
|
223
|
+
|
|
224
|
+
PyDoc_STRVAR(doc_isfloat,
|
|
225
|
+
"isfloat($self, /)\n--\n\n\
|
|
226
|
+
Return True if the type is a float type and False otherwise.\n\
|
|
227
|
+
\n\
|
|
228
|
+
>>> ndt(\"float16\").isfloat()\n\
|
|
229
|
+
True\n\
|
|
230
|
+
>>> ndt(\"float32\").isfloat()\n\
|
|
231
|
+
True\n\
|
|
232
|
+
>>> ndt(\"float64\").isfloat()\n\
|
|
233
|
+
True\n\
|
|
234
|
+
\n");
|
|
235
|
+
|
|
236
|
+
PyDoc_STRVAR(doc_isoptional,
|
|
237
|
+
"isoptional($self, /)\n--\n\n\
|
|
238
|
+
Return True if the type is optional and False otherwise. Optional types\n\
|
|
239
|
+
support missing values (NA).\n\
|
|
240
|
+
\n\
|
|
241
|
+
>>> ndt(\"bytes\").isoptional()\n\
|
|
242
|
+
False\n\
|
|
243
|
+
>>> ndt(\"?bytes\").isoptional()\n\
|
|
244
|
+
True\n\
|
|
245
|
+
\n");
|
|
246
|
+
|
|
247
|
+
PyDoc_STRVAR(doc_isscalar,
|
|
248
|
+
"isscalar($self, /)\n--\n\n\
|
|
249
|
+
Return True if the type is a scalar and False otherwise.\n\
|
|
250
|
+
\n\
|
|
251
|
+
>>> ndt(\"uint32\").isscalar()\n\
|
|
252
|
+
True\n\
|
|
253
|
+
>>> ndt(\"2 * uint32\").isscalar()\n\
|
|
254
|
+
False\n\
|
|
255
|
+
\n");
|
|
256
|
+
|
|
257
|
+
PyDoc_STRVAR(doc_issigned,
|
|
258
|
+
"issigned($self, /)\n--\n\n\
|
|
259
|
+
Return True if the type is a signed integer and False otherwise.\n\
|
|
260
|
+
\n\
|
|
261
|
+
>>> ndt(\"int8\").issigned()\n\
|
|
262
|
+
True\n\
|
|
263
|
+
\n");
|
|
264
|
+
|
|
265
|
+
PyDoc_STRVAR(doc_isunsigned,
|
|
266
|
+
"isunsigned($self, /)\n--\n\n\
|
|
267
|
+
Return True if the type is an unsigned integer and False otherwise.\n\
|
|
268
|
+
\n\
|
|
269
|
+
>>> ndt(\"uint8\").isunsigned()\n\
|
|
270
|
+
True\n\
|
|
271
|
+
\n");
|
|
272
|
+
|
|
273
|
+
PyDoc_STRVAR(doc_match,
|
|
274
|
+
"match($self, pattern, candidate, /)\n--\n\n\
|
|
275
|
+
Determine whether the concrete candidate type matches the (possibly abstract)\n\
|
|
276
|
+
pattern type. Used in type checking.\n\
|
|
277
|
+
\n\
|
|
278
|
+
>>> p = ndt(\"N * M * int64\")\n\
|
|
279
|
+
>>> c1 = ndt(\"2 * 3 * int64\")\n\
|
|
280
|
+
>>> c2 = ndt(\"2 * 3 * int8\")\n\
|
|
281
|
+
>>>\n\
|
|
282
|
+
>>> p.match(c1)\n\
|
|
283
|
+
True\n\
|
|
284
|
+
>>> p.match(c2)\n\
|
|
285
|
+
False\n\
|
|
286
|
+
\n");
|
|
287
|
+
|
|
288
|
+
PyDoc_STRVAR(doc_pformat,
|
|
289
|
+
"pformat($self, /)\n--\n\n\
|
|
290
|
+
Return a formatted string representation.\n\
|
|
291
|
+
\n\
|
|
292
|
+
>>> t = ndt(\"{a: {x: uint8, y: int64}, b: (string, bytes)}\")\n\
|
|
293
|
+
>>> t.pformat()\n\
|
|
294
|
+
'{\\n a : {\\n x : uint8,\\n y : int64\\n },\\n b : (string, bytes)\\n}'\n\
|
|
295
|
+
\n");
|
|
296
|
+
|
|
297
|
+
PyDoc_STRVAR(doc_pprint,
|
|
298
|
+
"pprint($self, /)\n--\n\n\
|
|
299
|
+
Print a formatted string representation to stdout.\n\
|
|
300
|
+
\n\
|
|
301
|
+
>>> t = ndt(\"{a: {x: uint8, y: int64}, b: (string, bytes)}\")\n\
|
|
302
|
+
>>> t.pprint()\n\
|
|
303
|
+
{\n\
|
|
304
|
+
a : {\n\
|
|
305
|
+
x : uint8,\n\
|
|
306
|
+
y : int64\n\
|
|
307
|
+
},\n\
|
|
308
|
+
b : (string, bytes)\n\
|
|
309
|
+
}\n\
|
|
310
|
+
\n");
|
|
311
|
+
|
|
312
|
+
PyDoc_STRVAR(doc_serialize,
|
|
313
|
+
"serialize($self, /)\n--\n\n\
|
|
314
|
+
Serialize a type to a bytes format.\n\
|
|
315
|
+
\n\
|
|
316
|
+
>>> t = ndt(\"int64\")\n\
|
|
317
|
+
>>> t.serialize()\n\
|
|
318
|
+
b'\\x1a\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x08\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x08\\x00'\n\
|
|
319
|
+
\n");
|
|
@@ -0,0 +1,154 @@
|
|
|
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 PYNDTYPES_H
|
|
35
|
+
#define PYNDTYPES_H
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
extern "C" {
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#include <Python.h>
|
|
42
|
+
#include "ndtypes.h"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/****************************************************************************/
|
|
46
|
+
/* ndt object */
|
|
47
|
+
/****************************************************************************/
|
|
48
|
+
|
|
49
|
+
/* Exposed here for the benefit of Numba. The API should not be regarded
|
|
50
|
+
stable across versions. */
|
|
51
|
+
|
|
52
|
+
typedef struct {
|
|
53
|
+
PyObject_HEAD
|
|
54
|
+
PyObject *rbuf; /* resource buffer */
|
|
55
|
+
ndt_t *ndt; /* type */
|
|
56
|
+
} NdtObject;
|
|
57
|
+
|
|
58
|
+
#define NDT(v) (((NdtObject *)v)->ndt)
|
|
59
|
+
#define RBUF(v) (((NdtObject *)v)->rbuf)
|
|
60
|
+
#define RBUF_NDT_META(v) (((ResourceBufferObject *)(((NdtObject *)v)->rbuf))->m)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/****************************************************************************/
|
|
64
|
+
/* Capsule API */
|
|
65
|
+
/****************************************************************************/
|
|
66
|
+
|
|
67
|
+
#define Ndt_CheckExact_INDEX 0
|
|
68
|
+
#define Ndt_CheckExact_RETURN int
|
|
69
|
+
#define Ndt_CheckExact_ARGS (const PyObject *)
|
|
70
|
+
|
|
71
|
+
#define Ndt_Check_INDEX 1
|
|
72
|
+
#define Ndt_Check_RETURN int
|
|
73
|
+
#define Ndt_Check_ARGS (const PyObject *)
|
|
74
|
+
|
|
75
|
+
#define CONST_NDT_INDEX 2
|
|
76
|
+
#define CONST_NDT_RETURN const ndt_t *
|
|
77
|
+
#define CONST_NDT_ARGS (const PyObject *)
|
|
78
|
+
|
|
79
|
+
#define Ndt_SetError_INDEX 3
|
|
80
|
+
#define Ndt_SetError_RETURN PyObject *
|
|
81
|
+
#define Ndt_SetError_ARGS (ndt_context_t *)
|
|
82
|
+
|
|
83
|
+
#define Ndt_CopySubtree_INDEX 4
|
|
84
|
+
#define Ndt_CopySubtree_RETURN PyObject *
|
|
85
|
+
#define Ndt_CopySubtree_ARGS (const PyObject *, const ndt_t *)
|
|
86
|
+
|
|
87
|
+
#define Ndt_MoveSubtree_INDEX 5
|
|
88
|
+
#define Ndt_MoveSubtree_RETURN PyObject *
|
|
89
|
+
#define Ndt_MoveSubtree_ARGS (const PyObject *, ndt_t *)
|
|
90
|
+
|
|
91
|
+
#define Ndt_FromType_INDEX 6
|
|
92
|
+
#define Ndt_FromType_RETURN PyObject *
|
|
93
|
+
#define Ndt_FromType_ARGS (ndt_t *)
|
|
94
|
+
|
|
95
|
+
#define Ndt_FromObject_INDEX 7
|
|
96
|
+
#define Ndt_FromObject_RETURN PyObject *
|
|
97
|
+
#define Ndt_FromObject_ARGS (PyObject *)
|
|
98
|
+
|
|
99
|
+
#define NDTYPES_MAX_API 8
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
#ifdef NDTYPES_MODULE
|
|
103
|
+
static Ndt_CheckExact_RETURN Ndt_CheckExact Ndt_CheckExact_ARGS;
|
|
104
|
+
static Ndt_Check_RETURN Ndt_Check Ndt_Check_ARGS;
|
|
105
|
+
static CONST_NDT_RETURN CONST_NDT CONST_NDT_ARGS;
|
|
106
|
+
static Ndt_SetError_RETURN Ndt_SetError Ndt_SetError_ARGS;
|
|
107
|
+
static Ndt_CopySubtree_RETURN Ndt_CopySubtree Ndt_CopySubtree_ARGS;
|
|
108
|
+
static Ndt_MoveSubtree_RETURN Ndt_MoveSubtree Ndt_MoveSubtree_ARGS;
|
|
109
|
+
static Ndt_FromType_RETURN Ndt_FromType Ndt_FromType_ARGS;
|
|
110
|
+
static Ndt_FromObject_RETURN Ndt_FromObject Ndt_FromObject_ARGS;
|
|
111
|
+
#else
|
|
112
|
+
static void **_ndtypes_api;
|
|
113
|
+
|
|
114
|
+
#define Ndt_CheckExact \
|
|
115
|
+
(*(Ndt_CheckExact_RETURN (*)Ndt_CheckExact_ARGS) _ndtypes_api[Ndt_CheckExact_INDEX])
|
|
116
|
+
|
|
117
|
+
#define Ndt_Check \
|
|
118
|
+
(*(Ndt_Check_RETURN (*)Ndt_Check_ARGS) _ndtypes_api[Ndt_Check_INDEX])
|
|
119
|
+
|
|
120
|
+
#define CONST_NDT \
|
|
121
|
+
(*(CONST_NDT_RETURN (*)CONST_NDT_ARGS) _ndtypes_api[CONST_NDT_INDEX])
|
|
122
|
+
|
|
123
|
+
#define Ndt_SetError \
|
|
124
|
+
(*(Ndt_SetError_RETURN (*)Ndt_SetError_ARGS) _ndtypes_api[Ndt_SetError_INDEX])
|
|
125
|
+
|
|
126
|
+
#define Ndt_CopySubtree \
|
|
127
|
+
(*(Ndt_CopySubtree_RETURN (*)Ndt_CopySubtree_ARGS) _ndtypes_api[Ndt_CopySubtree_INDEX])
|
|
128
|
+
|
|
129
|
+
#define Ndt_MoveSubtree \
|
|
130
|
+
(*(Ndt_MoveSubtree_RETURN (*)Ndt_MoveSubtree_ARGS) _ndtypes_api[Ndt_MoveSubtree_INDEX])
|
|
131
|
+
|
|
132
|
+
#define Ndt_FromType \
|
|
133
|
+
(*(Ndt_FromType_RETURN (*)Ndt_FromType_ARGS) _ndtypes_api[Ndt_FromType_INDEX])
|
|
134
|
+
|
|
135
|
+
#define Ndt_FromObject \
|
|
136
|
+
(*(Ndt_FromObject_RETURN (*)Ndt_FromObject_ARGS) _ndtypes_api[Ndt_FromObject_INDEX])
|
|
137
|
+
|
|
138
|
+
static int
|
|
139
|
+
import_ndtypes(void)
|
|
140
|
+
{
|
|
141
|
+
_ndtypes_api = (void **)PyCapsule_Import("ndtypes._ndtypes._API", 0);
|
|
142
|
+
if (_ndtypes_api == NULL) {
|
|
143
|
+
return -1;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
#endif
|
|
149
|
+
|
|
150
|
+
#ifdef __cplusplus
|
|
151
|
+
}
|
|
152
|
+
#endif
|
|
153
|
+
|
|
154
|
+
#endif /* PYNDTYPES_H */
|