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.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +50 -0
  3. data/Gemfile +2 -0
  4. data/History.md +0 -0
  5. data/README.md +19 -0
  6. data/Rakefile +125 -0
  7. data/ext/ruby_ndtypes/extconf.rb +55 -0
  8. data/ext/ruby_ndtypes/gc_guard.c +36 -0
  9. data/ext/ruby_ndtypes/gc_guard.h +12 -0
  10. data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
  11. data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
  12. data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
  13. data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
  14. data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
  15. data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
  16. data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
  17. data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
  18. data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
  19. data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
  20. data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
  21. data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
  22. data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
  23. data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
  24. data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
  25. data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
  26. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
  27. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
  28. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
  29. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
  30. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
  31. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
  32. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
  33. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
  34. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
  35. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
  36. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
  37. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
  38. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
  39. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
  40. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
  41. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
  42. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
  43. data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
  44. data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
  45. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
  46. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
  47. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
  48. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
  49. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
  50. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
  51. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
  52. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
  53. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
  54. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
  55. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
  56. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
  57. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
  58. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
  59. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
  60. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
  61. data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
  62. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
  63. data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
  64. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
  65. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
  66. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
  67. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
  68. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
  69. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
  70. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
  71. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
  72. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
  73. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
  74. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
  75. data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
  76. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
  77. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
  78. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
  79. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
  80. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
  81. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
  82. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
  83. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
  84. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
  85. data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
  86. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
  87. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
  88. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
  89. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
  90. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
  91. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
  92. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
  93. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
  94. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
  95. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
  96. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
  97. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
  98. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
  99. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
  100. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
  101. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
  102. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
  103. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
  104. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
  105. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
  106. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
  107. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
  108. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
  109. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
  110. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
  111. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
  112. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
  113. data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
  114. data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
  115. data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
  116. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
  117. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
  118. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
  119. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
  120. data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
  121. data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
  122. data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
  123. data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
  124. data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
  125. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
  126. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
  127. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
  128. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
  129. data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
  130. data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
  131. data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
  132. data/lib/ndtypes.rb +45 -0
  133. data/lib/ndtypes/errors.rb +2 -0
  134. data/lib/ndtypes/version.rb +6 -0
  135. data/ndtypes.gemspec +47 -0
  136. data/spec/gc_table_spec.rb +10 -0
  137. data/spec/ndtypes_spec.rb +289 -0
  138. data/spec/spec_helper.rb +241 -0
  139. metadata +242 -0
@@ -0,0 +1,124 @@
1
+ .. meta::
2
+ :robots: index,follow
3
+ :description: libndtypes documentation
4
+
5
+ .. sectionauthor:: Stefan Krah <skrah at bytereef.org>
6
+
7
+
8
+ Memory handling
9
+ ===============
10
+
11
+ Type allocation and deallocation
12
+ --------------------------------
13
+
14
+ .. code-block:: c
15
+
16
+ ndt_t *ndt_new(enum ndt tag, ndt_context_t *ctx);
17
+
18
+ Allocate a new type according to *tag* with the common fields initialized to
19
+ the default values.
20
+
21
+ Most types need additional initialization, so this function is rarely used
22
+ on its own.
23
+
24
+
25
+ .. code-block:: c
26
+
27
+ ndt_t *ndt_tuple_new(enum ndt_variadic flag, int64_t shape, ndt_context_t *ctx);
28
+ ndt_t *ndt_record_new(enum ndt_variadic flag, int64_t shape, ndt_context_t *ctx);
29
+
30
+ Allocate a new tuple or record type. Because of their internal complexity
31
+ these types have dedicated allocation functions.
32
+
33
+ As above, the functions are never used outside of wrapper functions.
34
+
35
+
36
+ .. code-block:: c
37
+
38
+ void ndt_del(ndt_t *t);
39
+
40
+ Deallocate a type. *t* may be :c:macro:`NULL`. This function is meant to
41
+ be used by applications directly.
42
+
43
+
44
+ Custom allocators
45
+ -----------------
46
+
47
+ .. code-block:: c
48
+
49
+ extern void *(* ndt_mallocfunc)(size_t size);
50
+ extern void *(* ndt_callocfunc)(size_t nmemb, size_t size);
51
+ extern void *(* ndt_reallocfunc)(void *ptr, size_t size);
52
+ extern void (* ndt_freefunc)(void *ptr);
53
+
54
+ libndtypes allows applications to set custom allocators at program start.
55
+ By default these global variables are set to the usual libc allocators.
56
+
57
+
58
+ Allocation/deallocation
59
+ -----------------------
60
+
61
+ .. code-block:: c
62
+
63
+ void *ndt_alloc(int64_t nmemb, int64_t size);
64
+
65
+ Allocate *nmemb \* size* bytes, using the function set in the custom allocator.
66
+
67
+ Overflow in the multiplication is checked. Return :c:macro:`NULL` on overflow
68
+ or if the allocation fails.
69
+
70
+
71
+ .. code-block:: c
72
+
73
+ void *ndt_alloc_size(size_t size);
74
+
75
+ Allocate *size* bytes, using the function set in the custom allocator.
76
+
77
+ Return :c:macro:`NULL` on overflow or if the allocation fails.
78
+
79
+
80
+ .. code-block:: c
81
+
82
+ void *ndt_calloc(int64_t nmemb, int64_t size);
83
+
84
+ Allocate *nmemb \* size* zero-initialized bytes, using the function set in the custom
85
+ allocator.
86
+
87
+ Return :c:macro:`NULL` if the allocation fails.
88
+
89
+
90
+ .. code-block:: c
91
+
92
+ void *ndt_realloc(void *ptr, int64_t nmemb, int64_t size);
93
+
94
+ Reallocate *ptr* to use *nmemb \* size* bytes.
95
+
96
+ Return :c:macro:`NULL` on overflow or if the allocation fails. As usual, *ptr*
97
+ is still valid after failure.
98
+
99
+
100
+ .. code-block:: c
101
+
102
+ void ndt_free(void *ptr);
103
+
104
+ Free a pointer allocated by one of the above functions. *ptr* may be
105
+ :c:macro:`NULL` if the custom allocator allows this -- the C Standard
106
+ requires :func:`free` to accept :c:macro:`NULL`.
107
+
108
+
109
+ Aligned allocation/deallocation
110
+ -------------------------------
111
+
112
+ .. code-block:: c
113
+
114
+ void *ndt_aligned_calloc(uint16_t alignment, int64_t size);
115
+
116
+ Allocate *size* bytes with a guaranteed *alignment*.
117
+
118
+
119
+ .. code-block:: c
120
+
121
+ void ndt_aligned_free(void *ptr);
122
+
123
+ Free a pointer that was allocated by :func:`ndt_aligned_calloc`. *ptr*
124
+ may be :c:macro:`NULL`.
@@ -0,0 +1,110 @@
1
+ .. meta::
2
+ :robots: index,follow
3
+ :description: libndtypes documentation
4
+
5
+ .. sectionauthor:: Stefan Krah <skrah at bytereef.org>
6
+
7
+
8
+ Predicates
9
+ ==========
10
+
11
+ libndtypes has a number of type predicates.
12
+
13
+
14
+ .. topic:: ndt_is_abstract
15
+ .. topic:: ndt_is_concrete
16
+
17
+ .. code-block:: c
18
+
19
+ int ndt_is_abstract(const ndt_t *t);
20
+ int ndt_is_concrete(const ndt_t *t);
21
+
22
+ Determine whether a type is abstract or concrete. These functions need
23
+ to be called to check whether the concrete type fields are defined.
24
+
25
+
26
+ .. topic:: ndt_is_optional
27
+
28
+ .. code-block:: c
29
+
30
+ int ndt_is_optional(const ndt_t *t);
31
+
32
+ Check if a type is optional.
33
+
34
+
35
+ .. topic:: ndt_subtree_is_optional
36
+
37
+ .. code-block:: c
38
+
39
+ int ndt_subtree_is_optional(const ndt_t *t);
40
+
41
+ Check if a subtree of a type is optional. This is useful for deciding if
42
+ bitmaps need to be allocated for subtrees.
43
+
44
+
45
+ .. topic:: ndt_is_ndarray
46
+
47
+ .. code-block:: c
48
+
49
+ int ndt_is_ndarray(const ndt_t *t);
50
+
51
+ Check if a type describes an n-dimensional (n > 0) array of fixed dimensions.
52
+
53
+
54
+ .. topic:: ndt_is_c_contiguous
55
+ .. topic:: ndt_is_f_contiguous
56
+
57
+ .. code-block:: c
58
+
59
+ int ndt_is_c_contiguous(const ndt_t *t);
60
+ int ndt_is_f_contiguous(const ndt_t *t);
61
+
62
+ Check if a type is an n-dimensional (n > 0) contiguous C or Fortran
63
+ array. Currently this returns 0 for scalars.
64
+
65
+
66
+ .. topic:: ndt_is_scalar
67
+
68
+ .. code-block:: c
69
+
70
+ int ndt_is_scalar(const ndt_t *t);
71
+
72
+ Check if a type is a scalar.
73
+
74
+
75
+ .. topic:: ndt_is_signed
76
+ .. topic:: ndt_is_unsigned
77
+ .. topic:: ndt_is_float
78
+ .. topic:: ndt_is_complex
79
+
80
+ .. code-block:: c
81
+
82
+ int ndt_is_signed(const ndt_t *t);
83
+ int ndt_is_unsigned(const ndt_t *t);
84
+ int ndt_is_float(const ndt_t *t);
85
+ int ndt_is_complex(const ndt_t *t);
86
+
87
+ Check if a type is signed, unsigned, float or complex.
88
+
89
+
90
+ .. topic:: ndt_endian_is_set
91
+
92
+ .. code-block:: c
93
+
94
+ int ndt_endian_is_set(const ndt_t *t);
95
+
96
+ Check whether the endianness of a type is explicitly set.
97
+
98
+
99
+ .. topic:: ndt_is_little_endian
100
+ .. topic:: ndt_is_big_endian
101
+
102
+ .. code-block:: c
103
+
104
+ int ndt_is_little_endian(const ndt_t *t);
105
+ int ndt_is_big_endian(const ndt_t *t);
106
+
107
+ Check whether a type is big or little endian. Use the native order
108
+ if no endian flag is set.
109
+
110
+
@@ -0,0 +1,31 @@
1
+ .. meta::
2
+ :robots: index,follow
3
+ :description: libndtypes documentation
4
+
5
+ .. sectionauthor:: Stefan Krah <skrah at bytereef.org>
6
+
7
+
8
+ Typedef
9
+ =======
10
+
11
+ libndtypes has a global lookup table for type aliases. These aliases are
12
+ treated as nominal types in pattern matching.
13
+
14
+
15
+ .. code-block:: c
16
+
17
+ int ndt_init(ndt_context_t *ctx);
18
+
19
+ This function must be called at program start to initialize the typedef
20
+ table.
21
+
22
+
23
+ .. code-block:: c
24
+
25
+ int ndt_typedef(const char *name, ndt_t *type, ndt_context_t *ctx);
26
+
27
+ Create a nominal type alias for *type*. The function steals the *type*
28
+ argument.
29
+
30
+
31
+
@@ -0,0 +1,594 @@
1
+ .. meta::
2
+ :robots: index,follow
3
+ :description: libndtypes documentation
4
+
5
+ .. sectionauthor:: Stefan Krah <skrah at bytereef.org>
6
+
7
+
8
+ Types
9
+ =====
10
+
11
+ Types are implemented as a tagged union. For the defined type enum values
12
+ it is best to refer to :c:macro:`ndtypes.h` directly or to search the constructor
13
+ functions below.
14
+
15
+
16
+ Abstract and concrete types
17
+ ---------------------------
18
+
19
+ .. topic:: abstract_concrete
20
+
21
+ .. code-block:: c
22
+
23
+ /* Protect access to concrete type fields. */
24
+ enum ndt_access {
25
+ Abstract,
26
+ Concrete
27
+ };
28
+
29
+ An important concept in libndtypes are abstract and concrete types.
30
+
31
+ Abstract types can have symbolic values like dimension or type variables
32
+ and are used for type checking.
33
+
34
+ Concrete types additionally have full memory layout information like
35
+ alignment and data size.
36
+
37
+ In order to protect against accidental access to undefined concrete fields, types
38
+ have the *ndt_access* field that is set to *Abstract* or *Concrete*.
39
+
40
+
41
+ Flags
42
+ -----
43
+
44
+ .. code-block:: c
45
+
46
+ /* flags */
47
+ #define NDT_LITTLE_ENDIAN 0x00000001U
48
+ #define NDT_BIG_ENDIAN 0x00000002U
49
+ #define NDT_OPTION 0x00000004U
50
+ #define NDT_SUBTREE_OPTION 0x00000008U
51
+ #define NDT_ELLIPSIS 0x00000010U
52
+
53
+ The endian flags are set if a type has explicit endianness. If native order
54
+ is used, they are unset.
55
+
56
+ :c:macro:`NDT_OPTION` is set if a type itself is optional.
57
+
58
+ :c:macro:`NDT_SUBTREE_OPTION` is set if any subtree of a type is optional.
59
+
60
+ :c:macro:`NDT_ELLIPSIS` is set if the tail of a dimension sequence contains
61
+ an ellipsis dimension. The flag is not propagated to an outer array with
62
+ a dtype that contains an inner array with an ellipsis.
63
+
64
+
65
+ Common fields
66
+ -------------
67
+
68
+ .. topic:: common_fields
69
+
70
+ .. code-block:: c
71
+
72
+ struct _ndt {
73
+ /* Always defined */
74
+ enum ndt tag;
75
+ enum ndt_access access;
76
+ uint32_t flags;
77
+ int ndim;
78
+ /* Undefined if the type is abstract */
79
+ int64_t datasize;
80
+ uint16_t align;
81
+ ...
82
+ };
83
+
84
+ *tag*, *access* and *flags* are explained above. Every type has an *ndim* field
85
+ even when it is not an array, in which case *ndim* is zero.
86
+
87
+ The *datasize* and *align* fields are defined for concrete types.
88
+
89
+
90
+ Abstract fields
91
+ ---------------
92
+
93
+ .. topic:: abstract_fields
94
+
95
+ .. code-block:: c
96
+
97
+ union {
98
+ ...
99
+
100
+ struct {
101
+ int64_t shape;
102
+ ndt_t *type;
103
+ } FixedDim;
104
+
105
+ ...
106
+
107
+ };
108
+
109
+ These fields are always defined for both abstract and concrete types.
110
+ :c:macro:`FixedDim` is just an example field. Refer to :c:macro:`ndtypes.h`
111
+ directly for the complete set of fields.
112
+
113
+
114
+ Concrete fields
115
+ ---------------
116
+
117
+ .. topic:: concrete_fields
118
+
119
+ .. code-block:: c
120
+
121
+ struct {
122
+ union {
123
+ struct {
124
+ int64_t itemsize;
125
+ int64_t step;
126
+ } FixedDim;
127
+
128
+ ...
129
+
130
+ };
131
+ } Concrete;
132
+
133
+ These fields are only defined for concrete types. For internal reasons
134
+ (facilitating copying etc.) they are initialized to zero for abstract
135
+ types.
136
+
137
+
138
+ Type constructor functions
139
+ --------------------------
140
+
141
+ All functions in this section steal their arguments. On success, heap
142
+ allocated memory like *type* and *name* arguments belong to the return
143
+ value.
144
+
145
+ On error, all arguments are deallocated within the respective functions.
146
+
147
+
148
+ Special types
149
+ --------------
150
+
151
+ The types in this section all have some property that makes them different
152
+ from the regular types.
153
+
154
+ .. topic:: ndt_option
155
+
156
+ .. code-block:: c
157
+
158
+ ndt_t *ndt_option(ndt_t *type);
159
+
160
+ This constructor is unique in that it does *not* create a new type with an
161
+ :c:macro:`Option` tag, but sets the :c:macro:`NDT_OPTION` flag of its argument.
162
+
163
+ The reason is that having a separate :c:macro:`Option` tag complicates the
164
+ type traversal when using libndtypes.
165
+
166
+ The function returns its argument and cannot fail.
167
+
168
+
169
+ .. topic:: ndt_module
170
+
171
+ .. code-block:: c
172
+
173
+ ndt_t *ndt_module(char *name, ndt_t *type, ndt_context_t *ctx);
174
+
175
+ The module type is for implementing type name spaces and is always abstract.
176
+ Used in type checking.
177
+
178
+
179
+ .. topic:: ndt_function
180
+
181
+ .. code-block:: c
182
+
183
+ ndt_t *ndt_function(ndt_t *ret, ndt_t *pos, ndt_t *kwds, ndt_context_t *ctx);
184
+
185
+ The function type is used for declaring function signatures.
186
+ Used in type checking.
187
+
188
+
189
+ .. topic:: ndt_void
190
+
191
+ .. code-block:: c
192
+
193
+ ndt_t *ndt_void(ndt_context_t *ctx)
194
+
195
+ Currently only used as the empty return value in function signatures.
196
+
197
+
198
+ Any type
199
+ --------
200
+
201
+ .. topic:: ndt_any
202
+
203
+ .. code-block:: c
204
+
205
+ ndt_t *ndt_any_kind(ndt_context_t *ctx);
206
+
207
+ Constructs the abstract *Any* type. Used in type checking.
208
+
209
+
210
+ Dimension types
211
+ ---------------
212
+
213
+ .. code-block:: c
214
+
215
+ ndt_t *ndt_fixed_dim(ndt_t *type, int64_t shape, int64_t step, ndt_context_t *ctx);
216
+
217
+ *type* is either a dtype or the tail of the dimension list.
218
+
219
+ *shape* is the dimension size and must be a natural number.
220
+
221
+ *step* is the amount to add to the linear index in order to move to
222
+ the next dimension element. *step* may be negative.
223
+
224
+
225
+ If *step* is :c:macro:`INT64_MAX`, the steps are computed from the dimensions
226
+ shapes and the resulting array is C-contiguous. This is the regular case.
227
+
228
+ If *step* is given, it is used without further checks. This is mostly useful
229
+ for slicing. The computed datasize is the minimum datasize such that all index
230
+ combinations are within the bounds of the allocated memory.
231
+
232
+
233
+ .. topic:: ndt_to_fortran
234
+
235
+ .. code-block:: c
236
+
237
+ ndt_t *ndt_to_fortran(const ndt_t *type, ndt_context_t *ctx);
238
+
239
+ Convert a C-contiguous chain of fixed dimensions to Fortran order.
240
+
241
+
242
+
243
+ .. topic:: ndt_abstract_var_dim
244
+
245
+ .. code-block:: c
246
+
247
+ ndt_t *ndt_abstract_var_dim(ndt_t *type, ndt_context_t *ctx);
248
+
249
+ Create an abstract *var* dimension for pattern matching.
250
+
251
+
252
+
253
+ .. topic:: ndt_var_dim
254
+
255
+ .. code-block:: c
256
+
257
+ /* Ownership flag for var dim offsets */
258
+ enum ndt_offsets {
259
+ InternalOffsets,
260
+ ExternalOffsets,
261
+ };
262
+
263
+ ndt_t *ndt_var_dim(ndt_t *type,
264
+ enum ndt_offsets flag, int32_t noffsets, const int32_t *offsets,
265
+ int32_t nslices, ndt_slice_t *slices,
266
+ ndt_context_t *ctx);
267
+
268
+
269
+ Create a concrete *var* dimension. Variable dimensions are offset-based
270
+ and use the same addressing scheme as the Arrow data format.
271
+
272
+ Offset arrays can be very large, so copying must be avoided. For ease of
273
+ use, libndtypes supports creating offset arrays from a datashape string.
274
+ In that case, *flag* must be set to :c:macro:`InternalOffsets` and the offsets
275
+ are managed by the type.
276
+
277
+ However, in the most common case offsets are generated and managed elsewhere.
278
+ In that case, *flag* must be set to :c:macro:`ExternalOffsets`.
279
+
280
+
281
+ The offset-based scheme makes it hard to store a sliced var dimension or
282
+ repeatedly slice a var dimension. This would require additional shape
283
+ arrays that are as large as the offset arrays.
284
+
285
+ Instead, var dimensions have the concept of a slice stack that stores
286
+ all slices that need to be applied to a var dimension.
287
+
288
+ Accessing elements recomputes the (start, stop, step) triples that result
289
+ from applying the entire slice stack.
290
+
291
+ The *nslices* and *slices* arguments are used to provide this stack. For
292
+ an unsliced var dimension these arguments must be *0* and *NULL*.
293
+
294
+
295
+
296
+ .. topic:: ndt_symbolic_dim
297
+
298
+ .. code-block:: c
299
+
300
+ ndt_t *ndt_symbolic_dim(char *name, ndt_t *type, ndt_context_t *ctx);
301
+
302
+ Create a dimension variable for pattern matching. The variable stands for
303
+ a fixed dimension.
304
+
305
+
306
+
307
+ .. topic:: ndt_ellipsis_dim
308
+
309
+ .. code-block:: c
310
+
311
+ ndt_ellipsis_dim(char *name, ndt_t *type, ndt_context_t *ctx);
312
+
313
+ Create an ellipsis dimension for pattern matching. If *name* is non-NULL,
314
+ a named ellipsis variable is created.
315
+
316
+ In pattern matching, multiple named ellipsis variables always stand for
317
+ the exact same sequence of dimensions.
318
+
319
+ By contrast, multiple unnamed ellipses stand for any sequence of dimensions
320
+ that can be broadcast together.
321
+
322
+
323
+ Container types
324
+ ---------------
325
+
326
+ .. topic:: ndt_tuple
327
+
328
+ .. code-block:: c
329
+
330
+ ndt_t *ndt_tuple(enum ndt_variadic flag, ndt_field_t *fields, int64_t shape,
331
+ uint16_opt_t align, uint16_opt_t pack, ndt_context_t *ctx);
332
+
333
+ Construct a tuple type. *fields* is the field sequence, *shape* the length
334
+ of the tuple.
335
+
336
+ *align* and *pack* are mutually exclusive and have the exact same meaning
337
+ as gcc's *aligned* and *packed* attributes applied to an entire struct.
338
+
339
+ Either of these may only be given if no field has an *align* or *pack*
340
+ attribute.
341
+
342
+
343
+ .. topic:: ndt_record
344
+
345
+ .. code-block:: c
346
+
347
+ ndt_t *ndt_record(enum ndt_variadic flag, ndt_field_t *fields, int64_t shape,
348
+ uint16_opt_t align, uint16_opt_t pack, ndt_context_t *ctx);
349
+
350
+ Construct a record (struct) type. *fields* is the field sequence, *shape*
351
+ the length of the record.
352
+
353
+ *align* and *pack* are mutually exclusive and have the exact same meaning
354
+ as gcc's *aligned* and *packed* attributes applied to an entire struct.
355
+
356
+ Either of these may only be given if no field has an *align* or *pack*
357
+ attribute.
358
+
359
+
360
+ .. topic:: ndt_ref
361
+
362
+ .. code-block:: c
363
+
364
+ ndt_t *ndt_ref(ndt_t *type, ndt_context_t *ctx);
365
+
366
+ Construct a reference type. References are pointers whose contents (the values
367
+ pointed to) are addressed transparently.
368
+
369
+
370
+ .. topic:: ndt_constr
371
+
372
+ .. code-block:: c
373
+
374
+ ndt_t *ndt_constr(char *name, ndt_t *type, ndt_context_t *ctx);
375
+
376
+ Create a constructor type. Constructor types are equal if their names
377
+ and types are equal.
378
+
379
+
380
+ .. topic:: ndt_nominal
381
+
382
+ .. code-block:: c
383
+
384
+ ndt_t *ndt_nominal(char *name, ndt_t *type, ndt_context_t *ctx);
385
+
386
+ Same as constructor, but the type is stored in a lookup table. Comparisons
387
+ and pattern matching are only by name. The name is globally unique.
388
+
389
+
390
+ Scalars
391
+ -------
392
+
393
+ .. topic:: ndt_scalar_kind
394
+
395
+ .. code-block:: c
396
+
397
+ ndt_t *ndt_scalar_kind(ndt_context_t *ctx);
398
+
399
+ Create a scalar kind type for pattern matching.
400
+
401
+
402
+ Categorical
403
+ -----------
404
+
405
+ .. topic:: ndt_categorical
406
+
407
+ .. code-block:: c
408
+
409
+ ndt_t *ndt_categorical(ndt_value_t *types, int64_t ntypes, ndt_context_t *ctx);
410
+
411
+ Create a categorical type. The categories are given as an array of typed
412
+ values.
413
+
414
+
415
+
416
+ Fixed string and fixed bytes
417
+ ----------------------------
418
+
419
+ .. topic:: ndt_fixed_string_kind
420
+
421
+ .. code-block:: c
422
+
423
+ ndt_t *ndt_fixed_string_kind(ndt_context_t *ctx);
424
+
425
+ Create a fixed string kind symbolic type for pattern matching.
426
+
427
+
428
+
429
+ .. topic:: ndt_fixed_string
430
+
431
+ .. code-block:: c
432
+
433
+ ndt_t *ndt_fixed_string(int64_t len, enum ndt_encoding encoding, ndt_context_t *ctx);
434
+
435
+ Create a fixed string type. *len is the length in code points, for *encoding* refer
436
+ to the encodings section.
437
+
438
+
439
+ .. topic:: ndt_fixed_bytes_kind
440
+
441
+ .. code-block:: c
442
+
443
+ ndt_t *ndt_fixed_bytes(int64_t size, uint16_opt_t align, ndt_context_t *ctx);
444
+
445
+ Create a fixed bytes kind symbolic type for pattern matching.
446
+
447
+
448
+
449
+ .. topic:: ndt_fixed_bytes
450
+
451
+ .. code-block:: c
452
+
453
+ ndt_t *ndt_fixed_bytes(int64_t size, uint16_opt_t align, ndt_context_t *ctx);
454
+
455
+ Create a fixed bytes type with size *size* and alignment *align*.
456
+
457
+
458
+ String, bytes, char
459
+ -------------------
460
+
461
+ .. topic:: ndt_string
462
+
463
+ .. code-block:: c
464
+
465
+ ndt_t *ndt_string(ndt_context_t *ctx);
466
+
467
+ Create a string type. The value representation in memory is a pointer to a
468
+ :c:macro:`NUL`-terminated UTF-8 string.
469
+
470
+
471
+ .. topic:: ndt_bytes
472
+
473
+ .. code-block:: c
474
+
475
+ ndt_t *ndt_bytes(uint16_opt_t target_align, ndt_context_t *ctx);
476
+
477
+ Create a bytes type. The value representation in memory is a struct containing
478
+ an :c:macro:`int64_t` *size* field and a pointer to :c:macro:`uint8_t`.
479
+
480
+ The alignment of the pointer value is *target_align*.
481
+
482
+
483
+
484
+ .. topic:: ndt_char
485
+
486
+ .. code-block:: c
487
+
488
+ ndt_t *ndt_char(enum ndt_encoding encoding, ndt_context_t *ctx);
489
+
490
+ Create a char type with a specific *encoding*. Encodings apart from UTF-32
491
+ may be removed in the future, since single UTF-8 chars etc. have no real
492
+ meaning and arrays of UTF-8 chars can be represented by the fixed string type.
493
+
494
+
495
+ Integer kinds
496
+ -------------
497
+
498
+ .. topic:: ndt_signed_kind
499
+
500
+ .. code-block:: c
501
+
502
+ ndt_t *ndt_signed_kind(ndt_context_t *ctx);
503
+
504
+ Create a symbolic signed kind type for pattern matching.
505
+
506
+
507
+ .. topic:: ndt_unsigned_kind
508
+
509
+ .. code-block:: c
510
+
511
+ ndt_t *ndt_unsigned_kind(ndt_context_t *ctx);
512
+
513
+ Create a symbolic unsigned kind type for pattern matching.
514
+
515
+
516
+ .. topic:: ndt_float_kind
517
+
518
+ .. code-block:: c
519
+
520
+ ndt_t *ndt_float_kind(ndt_context_t *ctx);
521
+
522
+ Create a symbolic float kind type for pattern matching.
523
+
524
+
525
+ .. topic:: ndt_complex_kind
526
+
527
+ .. code-block:: c
528
+
529
+ ndt_t *ndt_complex_kind(ndt_context_t *ctx);
530
+
531
+ Create a symbolic complex kind type for pattern matching.
532
+
533
+
534
+ Numbers
535
+ -------
536
+
537
+ .. topic:: ndt_primitive
538
+
539
+ .. code-block:: c
540
+
541
+ ndt_t *ndt_primitive(enum ndt tag, uint32_t flags, ndt_context_t *ctx);
542
+
543
+ Create a number type according to the given enum value. *flags* can be
544
+ :c:macro:`NDT_LITTLE_ENDIAN` or :c:macro:`NDT_BIG_ENDIAN`.
545
+
546
+ If no endian flag is given, native order is assumed.
547
+
548
+
549
+ .. topic:: ndt_signed
550
+
551
+ .. code-block:: c
552
+
553
+ ndt_t *ndt_signed(int size, uint32_t flags, ndt_context_t *ctx);
554
+
555
+ Create a signed fixed width integer according to *size*. *flags* as above.
556
+
557
+
558
+ .. topic:: ndt_unsigned
559
+
560
+ .. code-block:: c
561
+
562
+ ndt_t *ndt_unsigned(int size, uint32_t flags, ndt_context_t *ctx);
563
+
564
+ Create an unsigned fixed width integer according to *size*. *flags* as above.
565
+
566
+
567
+ .. topic:: ndt_from_alias
568
+
569
+ .. code-block:: c
570
+
571
+ enum ndt_alias {
572
+ Size,
573
+ Intptr,
574
+ Uintptr
575
+ };
576
+
577
+ ndt_t *ndt_from_alias(enum ndt_alias tag, uint32_t flags, ndt_context_t *ctx);
578
+
579
+ Create a fixed width integer type from an alias. Sizes are platform dependent.
580
+
581
+
582
+ Type variables
583
+ --------------
584
+
585
+ .. topic:: ndt_typevar
586
+
587
+ .. code-block:: c
588
+
589
+ ndt_t *ndt_typevar(char *name, ndt_context_t *ctx);
590
+
591
+ Create a type variable for pattern matching.
592
+
593
+
594
+