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#define BLOCK_ATTRIB_SNIPSTATE 7
162#define BLOCK_ATTRIB_SNIPVERS 8
163
165#define SET_HAS_NA_
166
167#define SET_HAS_NA_FALSE 0
168#define SET_HAS_NA_TRUE 1
169#define SET_HAS_NA_AUTO 2
170
171
172typedef std::chrono::steady_clock::time_point TimePoint;
173
174
183typedef char Name[NAME_SIZE];
184typedef Name *pName;
185typedef char *pChar;
186
187
192struct TensorDim {
193 int dim[MAX_TENSOR_RANK];
194};
195
196
200 int name;
201 int rank;
202 int dim[MAX_TENSOR_RANK];
203 union {
206 };
207};
208
209
210typedef uint16_t ff_fp16;
211
212
214union Tensor {
215 uint8_t cell_byte[0];
216 int8_t cell_int8[0];
217 bool cell_bool[0];
218
219 int16_t cell_int16[0];
220 uint16_t cell_word[0];
222
223 int cell_int[0];
224 uint32_t cell_uint[0];
225 float cell_single[0];
226
227 long long cell_longint[0];
228 time_t cell_time[0];
229 uint64_t cell_ulongint[0];
230 double cell_double[0];
232};
233
234
235typedef std::set<std::string> Dimensions;
236
237
238typedef std::map<std::string, std::string> Index;
239
240
244 int size;
246 union {
247 struct {
248 int rank;
252 bool has_NA;
253 uint64_t hash64;
254
256
257 };
259 };
260};
262
263
279
280
290
291
292extern float F_NA;
293extern double R_NA;
294
295} // namespace jazz_elements
296
297#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:261
double R_NA
NaN in double (binary R-compatible)
Definition types.cpp:57
StringBuffer * pStringBuffer
A pointer to a StringBuffer.
Definition types.h:289
std::map< std::string, std::string > Index
An Index kept in RAM by Volatile implemented as an stdlib map (string, string)
Definition types.h:238
std::set< std::string > Dimensions
An set::set with the dimension names returned by kind.dimensions()
Definition types.h:235
char * pChar
A pointer to a char buffer.
Definition types.h:185
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:183
uint16_t ff_fp16
A future (C++23 declares std::float16_t) 16-bit floating point placeholder for float16 and bfloat16.
Definition types.h:210
Name * pName
A pointer to a Name.
Definition types.h:184
std::chrono::steady_clock::time_point TimePoint
A time point stored as 8 bytes.
Definition types.h:172
float F_NA
NaN in single.
Definition types.cpp:56
StaticBlockHeader * pStaticBlockHeader
A pointer to a StaticBlockHeader.
Definition types.h:278
Header for a Movable Block (Tensor, Kind or Tuple) or a Dynamic Block (Index)
Definition types.h:242
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:255
int total_bytes
Total size of the block everything included.
Definition types.h:251
Index index
Any kind of Index.
Definition types.h:258
int size
The total number of cells in the tensor.
Definition types.h:244
TimePoint created
Timestamp when the block was created.
Definition types.h:245
bool has_NA
If true, at least one value in the tensor is a NA and block requires NA-aware arithmetic.
Definition types.h:252
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:243
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:249
uint64_t hash64
Hash of everything but the header.
Definition types.h:253
int rank
The number of dimensions.
Definition types.h:248
int num_attributes
Number of elements in the JazzAttributesMap.
Definition types.h:250
Header for an item (of a Kind or Tuple)
Definition types.h:198
int data_start
The data start of this tensor as an offset of &BlockHeader.tensor. (If is is a Tuple....
Definition types.h:204
int name
The name of this item as an offset in StringBuffer.
Definition types.h:200
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. For Kind: negative numbers are dimension names as -offset in StringBuffer.
Definition types.h:202
int rank
The number of dimensions.
Definition types.h:201
int cell_type
The type for the cells in the item. See CELL_TYPE_*.
Definition types.h:199
int item_size
During parsing of text blocks, this field is named item_size to temporarily hold the item size.
Definition types.h:205
A Binary Compatible BlockHeader without Index (and therefore constructors/destructors)
Definition types.h:265
int size
The total number of cells in the tensor.
Definition types.h:267
TimePoint created
Timestamp when the block was created.
Definition types.h:268
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:266
uint64_t hash64
Hash of everything but the header.
Definition types.h:274
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:276
int total_bytes
Total size of the block everything included.
Definition types.h:272
int num_attributes
Number of elements in the JazzAttributesMap.
Definition types.h:271
bool has_NA
If true, at least one value is a NA and block requires NA-aware arithmetic.
Definition types.h:273
int rank
The number of dimensions.
Definition types.h:269
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:270
Structure at the end of a Block, initially created with init_string_buffer()
Definition types.h:282
int last_idx
The index to the first free space after the last stored string.
Definition types.h:285
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:283
int buffer_size
The size in bytes of buffer[].
Definition types.h:286
char buffer[]
The buffer where strings are stored starting with two zeroes for STRING_NA & STRING_EMPTY.
Definition types.h:287
bool alloc_failed
A previous call to get_string_offset() failed to alloc space for a string.
Definition types.h:284
The dimension of a tensor.
Definition types.h:192
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. The product of all * (cell_type & 0xff) < 2 Gb.
Definition types.h:193
A tensor of cell size 1, 4, 8 or sizeof(BlockHeader)
Definition types.h:214
double cell_double[0]
.. CELL_TYPE_DOUBLE
Definition types.h:230
ItemHeader cell_item[0]
.. An array of BlockHeader used by Kinds and Tuples
Definition types.h:231
int8_t cell_int8[0]
.. CELL_TYPE_INT8
Definition types.h:216
int16_t cell_int16[0]
.. CELL_TYPE_INT16
Definition types.h:219
time_t cell_time[0]
.. CELL_TYPE_TIME
Definition types.h:228
uint32_t cell_uint[0]
.. CELL_TYPE_UINT32 or CELL_TYPE_SINGLE or CELL_TYPE_BOOLEAN as 32 bit unsigned
Definition types.h:224
uint8_t cell_byte[0]
Cell size for CELL_TYPE_BYTE.
Definition types.h:215
uint64_t cell_ulongint[0]
.. CELL_TYPE_UINT64 or CELL_TYPE_DOUBLE or CELL_TYPE_TIME as 64 bit unsigned
Definition types.h:229
bool cell_bool[0]
.. CELL_TYPE_BYTE_BOOLEAN
Definition types.h:217
ff_fp16 cell_float16[0]
.. CELL_TYPE_FLOAT16 or CELL_TYPE_BFLOAT16
Definition types.h:221
int cell_int[0]
.. CELL_TYPE_INTEGER, CELL_TYPE_FACTOR, CELL_TYPE_GRADE, CELL_TYPE_BOOLEAN and CELL_TYPE_STRING
Definition types.h:223
uint16_t cell_word[0]
.. CELL_TYPE_UINT16
Definition types.h:220
long long cell_longint[0]
.. CELL_TYPE_LONG_INTEGER
Definition types.h:227
float cell_single[0]
.. CELL_TYPE_SINGLE
Definition types.h:225