Jazz 1.25.+
Loading...
Searching...
No Matches
types.h
1/* Jazz (c) 2018-2025 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_ITEM 0x028
118#define CELL_TYPE_KIND_ITEM 0x128
119
120// 48 byte cell types
121#define CELL_TYPE_INDEX 0x030
122
123// Special cell types (Used in onnx::AttributeProto::AttributeType)
124#define CELL_TYPE_ONNX_GRAPH 0x040
125#define CELL_TYPE_ONNX_TENSOR 0x140
126
127// NA values or empty string values for all cell_type values
128#define BYTE_BOOLEAN_NA 0x0ff
129#define BOOLEAN_NA 0x0ff
130#define FLOAT16_NA F16_NA
131#define BFLOAT16_NA BF16_NA
132#define INTEGER_NA INT_MIN
133#define SINGLE_NA F_NA
134#define STRING_NA 0
135#define STRING_EMPTY 1
136#define LONG_INTEGER_NA LLONG_MIN
137#define TIME_POINT_NA 0
138#define DOUBLE_NA R_NA
139
140#define SINGLE_NA_UINT32 F_NA_uint32
141#define DOUBLE_NA_UINT64 R_NA_uint64
142
144
145#define MIXED_TYPE_
146
147#define MIXED_TYPE_INVALID 0
148#define MIXED_TYPE_KIND 1
149#define MIXED_TYPE_TUPLE 2
150
152
153#define BLOCK_ATTRIB_
154
155#define BLOCK_ATTRIB_BLOCKTYPE 1
156#define BLOCK_ATTRIB_SOURCE 2
157#define BLOCK_ATTRIB_DEST 3
158#define BLOCK_ATTRIB_MIMETYPE 4
159#define BLOCK_ATTRIB_URL 5
160#define BLOCK_ATTRIB_LANGUAGE 6
161//TODO: The BLOCK_ATTRIB_ from bop are yet to be defined.
162#define BLOCK_ATTRIB_SNIPSTATE 7
163#define BLOCK_ATTRIB_SNIPVERS 8
164
166#define SET_HAS_NA_
167
168#define SET_HAS_NA_FALSE 0
169#define SET_HAS_NA_TRUE 1
170#define SET_HAS_NA_AUTO 2
171
172
173typedef std::chrono::steady_clock::time_point TimePoint;
174
175
184typedef char Name[NAME_SIZE];
185typedef Name *pName;
186typedef char *pChar;
187
188
193struct TensorDim {
194 int dim[MAX_TENSOR_RANK];
195};
196
197
201 int name;
202 int rank;
203 int dim[MAX_TENSOR_RANK];
204 union {
207 };
208};
209
210
211typedef uint16_t ff_fp16;
212
213
215union Tensor {
216 uint8_t cell_byte[0];
217 int8_t cell_int8[0];
218 bool cell_bool[0];
219
220 int16_t cell_int16[0];
221 uint16_t cell_word[0];
223
224 int cell_int[0];
225 uint32_t cell_uint[0];
226 float cell_single[0];
227
228 long long cell_longint[0];
229 time_t cell_time[0];
230 uint64_t cell_ulongint[0];
231 double cell_double[0];
233};
234
235
236typedef std::set<std::string> Dimensions;
237
238
239typedef std::map<std::string, std::string> Index;
240
241
245 int size;
247 union {
248 struct {
249 int rank;
253 bool has_NA;
254 uint64_t hash64;
255
257
258 };
260 };
261};
263
264
280
281
291
292
293extern float F_NA;
294extern double R_NA;
295
296} // namespace jazz_elements
297
298#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:262
double R_NA
NaN in double (binary R-compatible)
Definition types.cpp:57
StringBuffer * pStringBuffer
A pointer to a StringBuffer.
Definition types.h:290
std::map< std::string, std::string > Index
An Index kept in RAM by Volatile implemented as an stdlib map (string, string)
Definition types.h:239
std::set< std::string > Dimensions
An set::set with the dimension names returned by kind.dimensions()
Definition types.h:236
char * pChar
A pointer to a char buffer.
Definition types.h:186
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:184
uint16_t ff_fp16
A future (C++23 declares std::float16_t) 16-bit floating point placeholder for float16 and bfloat16.
Definition types.h:211
Name * pName
A pointer to a Name.
Definition types.h:185
std::chrono::steady_clock::time_point TimePoint
A time point stored as 8 bytes.
Definition types.h:173
float F_NA
NaN in single.
Definition types.cpp:56
StaticBlockHeader * pStaticBlockHeader
A pointer to a StaticBlockHeader.
Definition types.h:279
Header for a Movable Block (Tensor, Kind or Tuple) or a Dynamic Block (Index)
Definition types.h:243
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:256
int total_bytes
Total size of the block everything included.
Definition types.h:252
Index index
Any kind of Index.
Definition types.h:259
int size
The total number of cells in the tensor.
Definition types.h:245
TimePoint created
Timestamp when the block was created.
Definition types.h:246
bool has_NA
If true, at least one value in the tensor is a NA and block requires NA-aware arithmetic.
Definition types.h:253
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:244
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:250
uint64_t hash64
Hash of everything but the header.
Definition types.h:254
int rank
The number of dimensions.
Definition types.h:249
int num_attributes
Number of elements in the JazzAttributesMap.
Definition types.h:251
Header for an item (of a Kind or Tuple)
Definition types.h:199
int data_start
The data start of this tensor as an offset of &BlockHeader.tensor. (If is is a Tuple....
Definition types.h:205
int name
The name of this item as an offset in StringBuffer.
Definition types.h:201
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. For Kind: negative numbers are dimension names as -offset in StringBuffer.
Definition types.h:203
int rank
The number of dimensions.
Definition types.h:202
int cell_type
The type for the cells in the item. See CELL_TYPE_*.
Definition types.h:200
int item_size
During parsing of text blocks, this field is named item_size to temporarily hold the item size.
Definition types.h:206
A Binary Compatible BlockHeader without Index (and therefore constructors/destructors)
Definition types.h:266
int size
The total number of cells in the tensor.
Definition types.h:268
TimePoint created
Timestamp when the block was created.
Definition types.h:269
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:267
uint64_t hash64
Hash of everything but the header.
Definition types.h:275
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:277
int total_bytes
Total size of the block everything included.
Definition types.h:273
int num_attributes
Number of elements in the JazzAttributesMap.
Definition types.h:272
bool has_NA
If true, at least one value is a NA and block requires NA-aware arithmetic.
Definition types.h:274
int rank
The number of dimensions.
Definition types.h:270
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:271
Structure at the end of a Block, initially created with init_string_buffer()
Definition types.h:283
int last_idx
The index to the first free space after the last stored string.
Definition types.h:286
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:284
int buffer_size
The size in bytes of buffer[].
Definition types.h:287
char buffer[]
The buffer where strings are stored starting with two zeroes for STRING_NA & STRING_EMPTY.
Definition types.h:288
bool alloc_failed
A previous call to get_string_offset() failed to alloc space for a string.
Definition types.h:285
The dimension of a tensor.
Definition types.h:193
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. The product of all * (cell_type & 0xff) < 2 Gb.
Definition types.h:194
A tensor of cell size 1, 4, 8 or sizeof(BlockHeader)
Definition types.h:215
double cell_double[0]
.. CELL_TYPE_DOUBLE
Definition types.h:231
ItemHeader cell_item[0]
.. An array of BlockHeader used by Kinds and Tuples
Definition types.h:232
int8_t cell_int8[0]
.. CELL_TYPE_INT8
Definition types.h:217
int16_t cell_int16[0]
.. CELL_TYPE_INT16
Definition types.h:220
time_t cell_time[0]
.. CELL_TYPE_TIME
Definition types.h:229
uint32_t cell_uint[0]
.. CELL_TYPE_UINT32 or CELL_TYPE_SINGLE or CELL_TYPE_BOOLEAN as 32 bit unsigned
Definition types.h:225
uint8_t cell_byte[0]
Cell size for CELL_TYPE_BYTE.
Definition types.h:216
uint64_t cell_ulongint[0]
.. CELL_TYPE_UINT64 or CELL_TYPE_DOUBLE or CELL_TYPE_TIME as 64 bit unsigned
Definition types.h:230
bool cell_bool[0]
.. CELL_TYPE_BYTE_BOOLEAN
Definition types.h:218
ff_fp16 cell_float16[0]
.. CELL_TYPE_FLOAT16 or CELL_TYPE_BFLOAT16
Definition types.h:222
int cell_int[0]
.. CELL_TYPE_INTEGER, CELL_TYPE_FACTOR, CELL_TYPE_GRADE, CELL_TYPE_BOOLEAN and CELL_TYPE_STRING
Definition types.h:224
uint16_t cell_word[0]
.. CELL_TYPE_UINT16
Definition types.h:221
long long cell_longint[0]
.. CELL_TYPE_LONG_INTEGER
Definition types.h:228
float cell_single[0]
.. CELL_TYPE_SINGLE
Definition types.h:226