Jazz 1.25.+
Loading...
Searching...
No Matches
types.h
1/* Jazz (c) 2018-2026 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques BasaldĂșa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques BasaldĂșa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include "src/include/jazz_platform.h"
36
37
38#include <map>
39#include <set>
40#include <chrono>
41#include <stdint.h>
42#include <string>
43
44
45#ifdef CATCH_TEST
46#ifndef INCLUDED_JAZZ_CATCH2
47#define INCLUDED_JAZZ_CATCH2
48
49#include "src/catch2/catch.hpp"
50
51#endif
52#endif
53
54
55#ifndef INCLUDED_JAZZ_ELEMENTS_TYPES
56#define INCLUDED_JAZZ_ELEMENTS_TYPES
57
58
64namespace jazz_elements
65{
66
67#define SHORT_NAME_SIZE 8
68#define NAME_SIZE 32
69#define NAME_LENGTH NAME_SIZE - 1
70#define ONE_MB (1024*1024)
71
78#define JAZZ_MAX_NUM_THREADS 64
79
80#define MAX_TENSOR_RANK 6
81#define MAX_CHECKS_4_MATCH 25
82#define MAX_ITEMS_IN_KIND 64
83
85#define CELL_TYPE__
86
87#define CELL_TYPE_UNDEFINED 0x000
88
89// 8 bit cell types
90#define CELL_TYPE_BYTE 0x001
91#define CELL_TYPE_BYTE_BOOLEAN 0x101
92#define CELL_TYPE_INT8 0x201
93
94// 16 bit cell types (Introduced for Bop-25)
95
96#define CELL_TYPE_INT16 0x002
97#define CELL_TYPE_UINT16 0x102
98#define CELL_TYPE_FLOAT16 0x202
99#define CELL_TYPE_BFLOAT16 0x302
100
101// 32 bit cell types
102#define CELL_TYPE_INTEGER 0x004
103#define CELL_TYPE_FACTOR 0x104
104#define CELL_TYPE_GRADE 0x204
105#define CELL_TYPE_BOOLEAN 0x304
106#define CELL_TYPE_SINGLE 0x404
107#define CELL_TYPE_STRING 0x504
108#define CELL_TYPE_UINT32 0x604
109
110// 64 bit cell types
111#define CELL_TYPE_LONG_INTEGER 0x008
112#define CELL_TYPE_TIME 0x108
113#define CELL_TYPE_DOUBLE 0x208
114#define CELL_TYPE_UINT64 0x308
115
116// 40 byte cell types
117#define CELL_TYPE_TUPLE 0x028
118#define CELL_TYPE_BLOCK_KIND 0x128
119#define CELL_TYPE_TUPLE_KIND 0x228
120#define CELL_TYPE_OBJECT_KIND 0x704
121
122// 48 byte cell types
123#define CELL_TYPE_INDEX 0x030
124
125// Special cell types (Used in onnx::AttributeProto::AttributeType)
126#define CELL_TYPE_ONNX_GRAPH 0x040
127#define CELL_TYPE_ONNX_TENSOR 0x140
128
129// NA values or empty string values for all cell_type values
130#define BYTE_BOOLEAN_NA 0x0ff
131#define BOOLEAN_NA 0x0ff
132#define FLOAT16_NA F16_NA
133#define BFLOAT16_NA BF16_NA
134#define INTEGER_NA INT_MIN
135#define SINGLE_NA F_NA
136#define STRING_NA 0
137#define STRING_EMPTY 1
138#define LONG_INTEGER_NA LLONG_MIN
139#define TIME_POINT_NA 0
140#define DOUBLE_NA R_NA
141
142#define SINGLE_NA_UINT32 F_NA_uint32
143#define DOUBLE_NA_UINT64 R_NA_uint64
144
146
147#define MIXED_TYPE_
148
149#define MIXED_TYPE_INVALID 0
150#define MIXED_TYPE_KIND 1
151#define MIXED_TYPE_TUPLE 2
152
154
155#define BLOCK_ATTRIB_
156
157#define BLOCK_ATTRIB_BLOCKTYPE 1
158#define BLOCK_ATTRIB_KIND_DEF 2
159#define BLOCK_ATTRIB_HOME 3
160#define BLOCK_ATTRIB_MIMETYPE 4
161#define BLOCK_ATTRIB_URL 5
162#define BLOCK_ATTRIB_LANGUAGE 6
163
164#define BLOCK_ATTRIB_BASE_BOP 100
165#define BLOCK_ATTRIB_BASE_MODELS 200
166
168
169#define SET_HAS_NA_
170
171#define SET_HAS_NA_FALSE 0
172#define SET_HAS_NA_TRUE 1
173#define SET_HAS_NA_AUTO 2
174
175
176typedef std::chrono::steady_clock::time_point TimePoint;
177
178
187typedef char Name[NAME_SIZE];
188typedef Name *pName;
189typedef char *pChar;
190
191
196struct TensorDim {
197 int dim[MAX_TENSOR_RANK];
198};
199
200
204 int name;
205 int rank;
206 int dim[MAX_TENSOR_RANK];
207 union {
210 };
211};
212
213
214typedef uint16_t ff_fp16;
215
216
218union Tensor {
219 uint8_t cell_byte[0];
220 int8_t cell_int8[0];
221 bool cell_bool[0];
222
223 int16_t cell_int16[0];
224 uint16_t cell_word[0];
226
227 int cell_int[0];
228 uint32_t cell_uint[0];
229 float cell_single[0];
230
231 long long cell_longint[0];
232 time_t cell_time[0];
233 uint64_t cell_ulongint[0];
234 double cell_double[0];
236};
237
238
239typedef std::string String;
240
241typedef std::set<String> Dimensions;
242
243typedef std::map<String, String> Index;
244
245
249 int size;
251 union {
252 struct {
253 int rank;
257 bool has_NA;
258 uint64_t hash64;
259
261
262 };
264 };
265};
267
268
284
285
295
296
297extern float F_NA;
298extern double R_NA;
299
300extern uint32_t F_NA_uint32;
301extern uint64_t R_NA_uint64;
302
303} // namespace jazz_elements
304
305#endif // ifndef INCLUDED_JAZZ_ELEMENTS_TYPES
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
BlockHeader * pBlockHeader
A pointer to a BlockHeader.
Definition types.h:266
std::string String
A standard string used in many other places in Jazz.
Definition types.h:239
double R_NA
NaN in double (binary R-compatible)
Definition types.cpp:58
std::set< String > Dimensions
An set::set with the dimension names returned by kind.dimensions()
Definition types.h:241
StringBuffer * pStringBuffer
A pointer to a StringBuffer.
Definition types.h:294
uint64_t R_NA_uint64
A binary exact copy of R_NA.
Definition types.cpp:63
char * pChar
A pointer to a char buffer.
Definition types.h:189
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:187
uint16_t ff_fp16
A future (C++23 declares std::float16_t) 16-bit floating point placeholder for float16 and bfloat16.
Definition types.h:214
Name * pName
A pointer to a Name.
Definition types.h:188
std::chrono::steady_clock::time_point TimePoint
A time point stored as 8 bytes.
Definition types.h:176
float F_NA
NaN in single.
Definition types.cpp:57
uint32_t F_NA_uint32
A binary exact copy of F_NA.
Definition types.cpp:62
StaticBlockHeader * pStaticBlockHeader
A pointer to a StaticBlockHeader.
Definition types.h:283
std::map< String, String > Index
An Index kept in RAM by Volatile implemented as an stdlib map (string, string)
Definition types.h:243
Header for a Movable Block (Tensor, Kind or Tuple) or a Dynamic Block (Index)
Definition types.h:247
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:260
int total_bytes
Total size of the block everything included.
Definition types.h:256
Index index
Any kind of Index.
Definition types.h:263
int size
The total number of cells in the tensor.
Definition types.h:249
TimePoint created
Timestamp when the block was created.
Definition types.h:250
bool has_NA
If true, at least one value in the tensor is a NA and block requires NA-aware arithmetic.
Definition types.h:257
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:248
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:254
uint64_t hash64
Hash of everything but the header.
Definition types.h:258
int rank
The number of dimensions.
Definition types.h:253
int num_attributes
Number of elements in the JazzAttributesMap.
Definition types.h:255
Header for an item (of a Kind or Tuple)
Definition types.h:202
int data_start
The data start of this tensor as an offset of &BlockHeader.tensor. (If is is a Tuple....
Definition types.h:208
int name
The name of this item as an offset in StringBuffer.
Definition types.h:204
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. For Kind: negative numbers are dimension names as -offset in StringBuffer.
Definition types.h:206
int rank
The number of dimensions.
Definition types.h:205
int cell_type
The type for the cells in the item. See CELL_TYPE_*.
Definition types.h:203
int item_size
During parsing of text blocks, this field is named item_size to temporarily hold the item size.
Definition types.h:209
A Binary Compatible BlockHeader without Index (and therefore constructors/destructors)
Definition types.h:270
int size
The total number of cells in the tensor.
Definition types.h:272
TimePoint created
Timestamp when the block was created.
Definition types.h:273
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:271
uint64_t hash64
Hash of everything but the header.
Definition types.h:279
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:281
int total_bytes
Total size of the block everything included.
Definition types.h:277
int num_attributes
Number of elements in the JazzAttributesMap.
Definition types.h:276
bool has_NA
If true, at least one value is a NA and block requires NA-aware arithmetic.
Definition types.h:278
int rank
The number of dimensions.
Definition types.h:274
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:275
Structure at the end of a Block, initially created with init_string_buffer()
Definition types.h:287
int last_idx
The index to the first free space after the last stored string.
Definition types.h:290
bool stop_check_4_match
When the StringBuffer is small, try to match existing indices of the same string to save RAM.
Definition types.h:288
int buffer_size
The size in bytes of buffer[].
Definition types.h:291
char buffer[]
The buffer where strings are stored starting with two zeroes for STRING_NA & STRING_EMPTY.
Definition types.h:292
bool alloc_failed
A previous call to get_string_offset() failed to alloc space for a string.
Definition types.h:289
The dimension of a tensor.
Definition types.h:196
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. The product of all * (cell_type & 0xff) < 2 Gb.
Definition types.h:197
A tensor of cell size 1, 4, 8 or sizeof(BlockHeader)
Definition types.h:218
double cell_double[0]
.. CELL_TYPE_DOUBLE
Definition types.h:234
ItemHeader cell_item[0]
.. An array of BlockHeader used by Kinds and Tuples
Definition types.h:235
int8_t cell_int8[0]
.. CELL_TYPE_INT8
Definition types.h:220
int16_t cell_int16[0]
.. CELL_TYPE_INT16
Definition types.h:223
time_t cell_time[0]
.. CELL_TYPE_TIME
Definition types.h:232
uint32_t cell_uint[0]
.. CELL_TYPE_UINT32 or CELL_TYPE_SINGLE or CELL_TYPE_BOOLEAN as 32 bit unsigned
Definition types.h:228
uint8_t cell_byte[0]
Cell size for CELL_TYPE_BYTE.
Definition types.h:219
uint64_t cell_ulongint[0]
.. CELL_TYPE_UINT64 or CELL_TYPE_DOUBLE or CELL_TYPE_TIME as 64 bit unsigned
Definition types.h:233
bool cell_bool[0]
.. CELL_TYPE_BYTE_BOOLEAN
Definition types.h:221
ff_fp16 cell_float16[0]
.. CELL_TYPE_FLOAT16 or CELL_TYPE_BFLOAT16
Definition types.h:225
int cell_int[0]
.. CELL_TYPE_INTEGER, CELL_TYPE_FACTOR, CELL_TYPE_GRADE, CELL_TYPE_BOOLEAN and CELL_TYPE_STRING
Definition types.h:227
uint16_t cell_word[0]
.. CELL_TYPE_UINT16
Definition types.h:224
long long cell_longint[0]
.. CELL_TYPE_LONG_INTEGER
Definition types.h:231
float cell_single[0]
.. CELL_TYPE_SINGLE
Definition types.h:229