290 #ifdef FLATBUFFER_ERROR_ABORTS
291 #include "../../Shared/toString.h"
292 #define RETURN_ERROR(exc) \
299 #define RETURN_ERROR(exc) return (exc)
302 #include "../../Shared/funcannotations.h"
313 #define FLATBUFFER_UNREACHABLE() \
316 #define FLATBUFFER_UNREACHABLE() \
330 addr +=
sizeof(int64_t) - 1;
331 return (int64_t)(((uint64_t)addr >> 3) << 3);
394 #define FLATBUFFER_SIZES_T_VALUE_TYPE Int32
395 #define FLATBUFFER_OFFSETS_T_VALUE_TYPE UInt64
533 switch (header_format) {
536 int64_t flatbuffer_size = base->flatbuffer_size;
537 if (flatbuffer_size > 0) {
539 ((int64_t*)buffer)[flatbuffer_size /
sizeof(int64_t) - 1]);
540 return footer_format == header_format;
572 return getNestedArrayWorker()->value_size;
576 const auto* metadata = getNestedArrayMetadata();
577 const auto* worker = getNestedArrayWorker();
578 return worker->value_size * metadata->total_values_count;
582 const auto offset = getNestedArrayWorker()->values_buffer_offset;
583 return reinterpret_cast<const int8_t*
>(
buffer + offset);
587 const auto* worker = getNestedArrayWorker();
588 const auto* values_offsets = get_values_offsets();
589 const auto storage_index = worker->specified_items_count;
590 const auto values_offset = values_offsets[storage_index];
591 if (values_offset < 0) {
592 return -(values_offset + 1);
594 return values_offset;
607 return getGeoPointMetadata()->total_items_count;
609 return getNestedArrayMetadata()->total_items_count;
620 return 2 * (getGeoPointMetadata()->is_geoint ?
sizeof(int32_t) :
sizeof(
double));
631 return 2 * (getGeoPointMetadata()->is_geoint ?
sizeof(int32_t) :
sizeof(
double));
640 const int8_t* format_metadata_ptr) {
644 const auto format_metadata =
645 reinterpret_cast<const GeoPoint*
>(format_metadata_ptr);
648 const auto itemsize =
649 2 * (format_metadata->is_geoint ?
sizeof(int32_t) :
sizeof(
double));
651 itemsize * format_metadata->total_items_count);
658 return flatbuffer_size;
668 #define FLATBUFFER_MANAGER_FORMAT_TOOLS(TYPENAME) \
669 HOST DEVICE inline TYPENAME##Worker* get##TYPENAME##Worker() { \
670 auto* base = getBaseWorker(); \
671 return reinterpret_cast<TYPENAME##Worker*>(buffer + base->format_worker_offset); \
673 HOST DEVICE inline TYPENAME* get##TYPENAME##Metadata() { \
674 auto* base = getBaseWorker(); \
675 return reinterpret_cast<TYPENAME*>(buffer + base->format_metadata_offset); \
677 HOST DEVICE inline const TYPENAME##Worker* get##TYPENAME##Worker() const { \
678 const auto* base = getBaseWorker(); \
679 return reinterpret_cast<const TYPENAME##Worker*>(buffer + \
680 base->format_worker_offset); \
682 HOST DEVICE inline const TYPENAME* get##TYPENAME##Metadata() const { \
683 const auto* base = getBaseWorker(); \
684 return reinterpret_cast<const TYPENAME*>(buffer + base->format_metadata_offset); \
690 #define FLATBUFFER_MANAGER_FORMAT_TOOLS_NEW(TYPENAME) \
691 HOST DEVICE inline NestedArrayWorker* get##TYPENAME##Worker() { \
692 auto* base = getBaseWorker(); \
693 return reinterpret_cast<NestedArrayWorker*>(buffer + base->format_worker_offset); \
695 HOST DEVICE inline TYPENAME* get##TYPENAME##Metadata() { \
696 auto* base = getBaseWorker(); \
697 return reinterpret_cast<TYPENAME*>(buffer + base->format_metadata_offset); \
699 HOST DEVICE inline const NestedArrayWorker* get##TYPENAME##Worker() const { \
700 const auto* base = getBaseWorker(); \
701 return reinterpret_cast<const NestedArrayWorker*>(buffer + \
702 base->format_worker_offset); \
704 HOST DEVICE inline const TYPENAME* get##TYPENAME##Metadata() const { \
705 const auto* base = getBaseWorker(); \
706 return reinterpret_cast<const TYPENAME*>(buffer + base->format_metadata_offset); \
711 #undef FLATBUFFER_MANAGER_FORMAT_TOOLS
712 #undef FLATBUFFER_MANAGER_FORMAT_TOOLS_NEW
714 #define FLATBUFFER_MANAGER_SET_OFFSET(OBJ, NAME, SIZE) \
715 offset = OBJ->NAME##_offset = offset + _align_to_int64(previous_size); \
716 previous_size = SIZE;
719 int64_t total_items_count,
720 int64_t total_sizes_count,
721 int64_t total_values_count,
723 size_t user_data_size) {
724 size_t value_size =
get_size(value_type);
735 (total_items_count * ndims + 1));
737 sizeof(
sizes_t) * total_items_count);
740 return flatbuffer_size;
744 int64_t total_items_count,
745 int64_t total_sizes_count,
746 int64_t total_values_count,
748 const int8_t* null_value_ptr,
749 const int8_t* user_data_ptr,
750 size_t user_data_size) {
753 size_t value_size =
get_size(value_type);
765 auto* metadata = getNestedArrayMetadata();
766 metadata->ndims = ndims;
767 metadata->total_items_count = total_items_count;
768 metadata->total_sizes_count = total_sizes_count;
769 metadata->total_values_count = total_values_count;
770 metadata->value_type = value_type;
771 metadata->user_data_size = user_data_size;
773 auto* worker = getNestedArrayWorker();
774 worker->specified_items_count = 0;
775 worker->value_size = value_size;
778 worker, values_buffer, value_size * (total_values_count + 1));
780 worker, sizes_buffer,
sizeof(
sizes_t) * total_sizes_count);
782 worker, values_offsets,
sizeof(
offsets_t) * (total_items_count + 1));
784 worker, sizes_offsets,
sizeof(
offsets_t) * (total_items_count * ndims + 1));
786 worker, storage_indices,
sizeof(
sizes_t) * total_items_count);
789 if (base->flatbuffer_size !=
794 offsets_t* values_offsets = get_values_offsets();
795 offsets_t* sizes_offsets = get_sizes_offsets();
796 values_offsets[0] = 0;
797 sizes_offsets[0] = 0;
799 for (
int i = 0; i < total_items_count; i++) {
800 storage_indices[i] = -1;
804 int8_t* null_value_buffer = get_values_buffer() + value_size * total_values_count;
805 if (null_value_ptr !=
nullptr) {
806 if (memcpy(null_value_buffer, null_value_ptr, value_size) ==
nullptr) {
810 if (memset(null_value_buffer, 0, value_size) ==
nullptr) {
815 if (user_data_size > 0 && user_data_ptr !=
nullptr) {
816 int8_t* user_data_buffer = get_user_data_buffer();
817 if (memcpy(user_data_buffer, user_data_ptr, user_data_size) ==
nullptr) {
822 ((int64_t*)
buffer)[base->flatbuffer_size /
sizeof(int64_t) - 1] =
823 static_cast<int64_t>(base->format_id);
835 base->format_id = format_id;
843 base->format_worker_offset =
846 const auto* format_metadata =
847 reinterpret_cast<const GeoPoint*
>(format_metadata_ptr);
848 auto* this_metadata = getGeoPointMetadata();
849 this_metadata->total_items_count = format_metadata->total_items_count;
850 this_metadata->input_srid = format_metadata->input_srid;
851 this_metadata->output_srid = format_metadata->output_srid;
852 this_metadata->is_geoint = format_metadata->is_geoint;
854 auto* this_worker = getGeoPointWorker();
855 this_worker->values_offset =
860 ((int64_t*)
buffer)[base->flatbuffer_size /
sizeof(int64_t) - 1] =
861 static_cast<int64_t>(format_id);
868 return getNestedArrayMetadata()->ndims;
879 return getGeoPointMetadata()->total_items_count;
891 return getGeoPointMetadata()->total_items_count;
895 static int64_t dummy_storage_count = -1;
896 return dummy_storage_count;
903 return getGeoPointMetadata()->total_items_count;
907 static int64_t dummy = -1;
916 const auto* metadata = getGeoPointMetadata();
917 const auto itemsize =
918 2 * (metadata->is_geoint ?
sizeof(int32_t) :
sizeof(
double));
924 static int64_t dummy = -1;
934 offset = getGeoPointWorker()->values_offset;
947 offset = getGeoPointWorker()->values_offset;
955 #define FLATBUFFER_GET_BUFFER_METHODS(BUFFERNAME, BUFFERTYPE) \
956 HOST DEVICE inline BUFFERTYPE* get_##BUFFERNAME() { \
957 int64_t offset = 0; \
958 switch (format()) { \
959 case NestedArrayFormatId: \
960 offset = getNestedArrayWorker()->BUFFERNAME##_offset; \
965 return reinterpret_cast<BUFFERTYPE*>(buffer + offset); \
967 HOST DEVICE inline const BUFFERTYPE* get_##BUFFERNAME() const { \
968 int64_t offset = 0; \
969 switch (format()) { \
970 case NestedArrayFormatId: \
971 offset = getNestedArrayWorker()->BUFFERNAME##_offset; \
976 return reinterpret_cast<BUFFERTYPE*>(buffer + offset); \
985 #undef FLATBUFFER_GET_BUFFER_METHODS
996 if (null_value_ptr !=
nullptr) {
999 return *null_value_ptr == *value_ptr;
1001 return *
reinterpret_cast<const int16_t*
>(null_value_ptr) ==
1002 *reinterpret_cast<const int16_t*>(value_ptr);
1004 return *
reinterpret_cast<const int32_t*
>(null_value_ptr) ==
1005 *reinterpret_cast<const int32_t*>(value_ptr);
1007 return *
reinterpret_cast<const int64_t*
>(null_value_ptr) ==
1008 *reinterpret_cast<const int64_t*>(value_ptr);
1010 return (*reinterpret_cast<const int64_t*>(null_value_ptr) ==
1011 *
reinterpret_cast<const int64_t*
>(value_ptr) &&
1012 *(reinterpret_cast<const int64_t*>(null_value_ptr) + 1) ==
1013 *(reinterpret_cast<const int64_t*>(value_ptr) + 1));
1025 offset = getNestedArrayWorker()->storage_indices_offset;
1037 offset = getNestedArrayWorker()->storage_indices_offset;
1051 template <
size_t NDIM>
1055 auto status = getItem<NDIM>(index,
n, item);
1065 template <
size_t NDIM = 1>
1067 const int64_t index_[NDIM] = {index};
1068 return getLength<NDIM>(index_, 1, length);
1073 template <
size_t NDIM>
1076 size_t& length)
const {
1085 if (n > ndims + 1) {
1088 if (index[0] < 0 || index[0] >=
itemsCount()) {
1093 if (storage_index < 0) {
1096 const auto* values_offsets = get_values_offsets();
1097 const auto values_offset = values_offsets[storage_index];
1098 if (values_offset < 0) {
1102 const auto* sizes_offsets = get_sizes_offsets();
1103 const auto* sizes_buffer = get_sizes_buffer();
1104 const auto sizes_offset = sizes_offsets[storage_index * ndims];
1107 length = sizes_buffer[sizes_offset];
1110 const auto sizes2_offset = sizes_offsets[storage_index * ndims + 1];
1111 if (index[1] < 0 || index[1] >= sizes_buffer[sizes_offset]) {
1114 length = sizes_buffer[sizes2_offset + index[1]];
1117 const auto sizes2_offset = sizes_offsets[storage_index * ndims + 1];
1118 const auto sizes3_offset = sizes_offsets[storage_index * ndims + 2];
1119 if (index[1] < 0 || index[1] >= sizes_buffer[sizes_offset]) {
1122 if (index[2] < 0 || index[2] >= sizes_buffer[sizes2_offset + index[1]]) {
1126 for (int64_t i = 0; i < index[1]; i++) {
1127 soffset += sizes_buffer[sizes2_offset + i];
1129 length = sizes_buffer[sizes3_offset + soffset + index[2]];
1140 template <
size_t NDIM>
1144 int32_t& nof_values,
1145 int32_t* sizes_buffers[NDIM],
1146 int32_t sizes_lengths[NDIM],
1152 std::memset(sizes_buffers, 0, NDIM *
sizeof(int32_t*));
1153 std::memset(sizes_lengths, 0, NDIM *
sizeof(int32_t));
1161 if (n <= 0 || n > ndims + 1) {
1207 if (index[0] < 0 || index[0] >=
itemsCount()) {
1212 if (storage_index < 0) {
1215 const auto* values_offsets = get_values_offsets();
1216 const auto values_offset = values_offsets[storage_index];
1217 if (values_offset < 0) {
1221 const auto* sizes_offsets = get_sizes_offsets();
1222 auto* sizes_buffer = get_sizes_buffer();
1223 auto* values_buffer = get_values_buffer();
1225 const auto next_values_offset = values_offsets[storage_index + 1];
1227 const auto sizes_offset = sizes_offsets[storage_index * ndims];
1228 nof_sizes = ndims -
n;
1231 if (next_values_offset < 0) {
1232 nof_values = -(next_values_offset + 1) - values_offset;
1234 nof_values = next_values_offset - values_offset;
1236 values = values_buffer + values_offset * valuesize;
1239 const auto sizes2_offset = sizes_offsets[storage_index * ndims + 1];
1240 const auto sizes3_offset = sizes_offsets[storage_index * ndims + 2];
1241 sizes_buffers[0] = sizes_buffer + sizes2_offset;
1242 sizes_buffers[1] = sizes_buffer + sizes3_offset;
1243 sizes_lengths[0] = sizes_buffer[sizes_offset];
1244 sizes_lengths[1] = sizes_offsets[storage_index * ndims + 3] - sizes3_offset;
1248 const auto sizes2_offset = sizes_offsets[storage_index * ndims + 1];
1249 sizes_buffers[0] = sizes_buffer + sizes2_offset;
1250 sizes_lengths[0] = sizes_buffer[sizes_offset];
1262 const auto sizes2_offset = sizes_offsets[storage_index * ndims + 1];
1263 if (index[1] < 0 || index[1] >= sizes_buffer[sizes_offset]) {
1267 for (int64_t i = 0; i < index[1]; i++) {
1268 soffset += sizes_buffer[sizes2_offset + i];
1270 values = values_buffer + (values_offset + soffset) * valuesize;
1273 const auto sizes3_offset = sizes_offsets[storage_index * ndims + 2];
1274 const sizes_t nsizes = sizes_buffer[sizes2_offset + index[1]];
1275 auto sizes_buf = sizes_buffer + sizes3_offset + soffset;
1276 sizes_buffers[0] = sizes_buf;
1277 sizes_lengths[0] = nsizes;
1279 for (int64_t i = 0; i < nsizes; i++) {
1280 nof_values += sizes_buf[i];
1285 nof_values = sizes_buffer[sizes2_offset + index[1]];
1303 const auto sizes2_offset = sizes_offsets[storage_index * ndims + 1];
1304 const auto sizes3_offset = sizes_offsets[storage_index * ndims + 2];
1305 if (index[1] < 0 || index[1] >= sizes_buffer[sizes_offset]) {
1308 if (index[2] < 0 || index[2] >= sizes_buffer[sizes2_offset + index[1]]) {
1313 int64_t soffset = 0;
1314 int64_t voffset = 0;
1315 for (int64_t i = 0; i < index[1]; i++) {
1316 auto size2 = sizes_buffer[sizes2_offset + i];
1318 for (int64_t j = 0; j < size2; j++) {
1319 voffset += sizes_buffer[sizes3_offset + i3];
1323 for (int64_t j = 0; j < index[2]; j++) {
1324 voffset += sizes_buffer[sizes3_offset + i3];
1327 values = values_buffer + (values_offset + voffset) * valuesize;
1328 nof_values = sizes_buffer[sizes3_offset + soffset + index[2]];
1338 template <
size_t NDIM>
1348 template <
size_t NDIM>
1350 const int64_t index_[NDIM] = {index};
1351 return getItem<NDIM>(index_, 1,
result);
1354 template <
size_t NDIM>
1356 return getItemWorker<NDIM>(index,
n,
1367 template <
size_t NDIM,
bool check_sizes=true>
1369 const int8_t* values,
1370 const int32_t nof_values,
1371 const int32_t*
const sizes_buffers[NDIM],
1372 const int32_t sizes_lengths[NDIM],
1373 const int32_t nof_sizes) {
1381 if (nof_sizes + 1 != ndims) {
1386 if (storage_indices[index] >= 0) {
1389 auto* worker = getNestedArrayWorker();
1390 const auto storage_index = worker->specified_items_count;
1391 storage_indices[index] = storage_index;
1392 worker->specified_items_count++;
1394 auto* values_offsets = get_values_offsets();
1395 auto* sizes_offsets = get_sizes_offsets();
1396 auto* sizes_buffer = get_sizes_buffer();
1397 auto* values_buffer = get_values_buffer();
1398 const auto* metadata = getNestedArrayMetadata();
1401 auto values_offset = values_offsets[storage_index];
1402 const auto sizes_offset = sizes_offsets[storage_index * ndims];
1403 if (values_offset + nof_values > metadata->total_values_count) {
1409 sizes_buffer[sizes_offset] = nof_values;
1410 sizes_offsets[storage_index * ndims + 1] = sizes_offset + 1;
1413 const auto sizes2_offset = sizes_offset + 1;
1414 if (sizes2_offset + sizes_lengths[0] > metadata->total_sizes_count) {
1417 sizes_buffer[sizes_offset] = sizes_lengths[0];
1418 if constexpr (check_sizes) {
1420 int32_t sum_of_sizes = 0;
1421 for (int32_t i=0; i < sizes_lengths[0]; i++) {
1422 sum_of_sizes += sizes_buffers[0][i];
1424 if (nof_values != sum_of_sizes) {
1428 if (memcpy(sizes_buffer + sizes2_offset,
1430 sizes_lengths[0] *
sizeof(
sizes_t)) ==
nullptr) {
1433 sizes_offsets[storage_index * ndims + 1] = sizes2_offset;
1434 sizes_offsets[storage_index * ndims + 2] = sizes2_offset + sizes_lengths[0];
1437 const auto sizes2_offset = sizes_offset + 1;
1438 const auto sizes3_offset = sizes2_offset + sizes_lengths[0];
1439 if (sizes2_offset + sizes_lengths[0] + sizes_lengths[1] >
1440 metadata->total_sizes_count) {
1443 sizes_buffer[sizes_offset] = sizes_lengths[0];
1444 if constexpr (check_sizes) {
1446 int32_t sum_of_sizes_of_sizes = 0;
1447 for (int32_t i=0; i < sizes_lengths[0]; i++) {
1448 sum_of_sizes_of_sizes += sizes_buffers[0][i];
1450 if (sizes_lengths[1] != sum_of_sizes_of_sizes) {
1454 if (memcpy(sizes_buffer + sizes2_offset,
1456 sizes_lengths[0] *
sizeof(
sizes_t)) ==
nullptr) {
1459 if constexpr (check_sizes) {
1461 int32_t sum_of_sizes = 0;
1462 for (int32_t i=0; i < sizes_lengths[1]; i++) {
1463 sum_of_sizes += sizes_buffers[1][i];
1465 if (nof_values != sum_of_sizes) {
1469 if (memcpy(sizes_buffer + sizes3_offset,
1471 sizes_lengths[1] *
sizeof(
sizes_t)) ==
nullptr) {
1474 sizes_offsets[storage_index * ndims + 1] = sizes2_offset;
1475 sizes_offsets[storage_index * ndims + 2] = sizes3_offset;
1476 sizes_offsets[storage_index * ndims + 3] = sizes3_offset + sizes_lengths[1];
1482 if (values !=
nullptr) {
1483 if (memcpy(values_buffer + values_offset * valuesize,
1485 nof_values * valuesize) ==
nullptr) {
1489 values_offsets[storage_index + 1] = values_offset + nof_values;
1497 template <
size_t NDIM,
bool check_sizes=true>
1499 const int8_t* values,
1500 const int32_t nof_values,
1501 const int32_t*
const sizes_buffers[NDIM],
1502 const int32_t sizes_lengths[NDIM],
1503 const int32_t nof_sizes) {
1511 if (nof_sizes + 1 != ndims) {
1515 auto storage_index = storage_indices[index];
1516 if (storage_index == -1) {
1517 return setItemWorker<NDIM, check_sizes>(index,
1524 auto* worker = getNestedArrayWorker();
1525 if (storage_index != worker->specified_items_count - 1) {
1534 auto* values_offsets = get_values_offsets();
1535 auto values_offset = values_offsets[storage_index];
1536 if (values_offset < 0) {
1540 auto* values_buffer = get_values_buffer();
1541 auto* sizes_offsets = get_sizes_offsets();
1542 auto* sizes_buffer = get_sizes_buffer();
1543 const auto sizes_offset = sizes_offsets[storage_index * ndims];
1544 const auto* metadata = getNestedArrayMetadata();
1546 values_offset += sizes_buffer[sizes_offset];
1547 if (values_offset + nof_values > metadata->total_values_count) {
1552 sizes_buffer[sizes_offset] += nof_values;
1555 const auto sizes2_offset = sizes_offset + 1;
1556 if (sizes2_offset + sizes_buffer[sizes_offset] + sizes_lengths[0] > metadata->total_sizes_count) {
1559 if constexpr (check_sizes) {
1561 int32_t sum_of_sizes = 0;
1562 for (int32_t i=0; i < sizes_lengths[0]; i++) {
1563 sum_of_sizes += sizes_buffers[0][i];
1565 if (nof_values != sum_of_sizes) {
1569 if (memcpy(sizes_buffer + sizes2_offset + sizes_buffer[sizes_offset],
1571 sizes_lengths[0] *
sizeof(
sizes_t)) ==
nullptr) {
1574 sizes_buffer[sizes_offset] += sizes_lengths[0];
1575 sizes_offsets[storage_index * ndims + 2] += sizes_lengths[0];
1584 if (nof_values > 0 && values !=
nullptr &&
1585 memcpy(values_buffer + values_offset * valuesize, values, nof_values * valuesize) ==
nullptr) {
1588 values_offsets[storage_index + 1] += nof_values;
1592 template <
size_t NDIM=1,
bool check_sizes=true>
1594 const int8_t* values_buf,
1595 const int32_t nof_values) {
1596 const int32_t*
const sizes_buffers[1] = {
nullptr};
1597 int32_t sizes_lengths[1] = {0};
1598 return setItemWorker<1, check_sizes>(index,
1606 template <
size_t NDIM=1,
bool check_sizes=true>
1608 const int8_t* values_buf,
1609 const int32_t nof_values,
1610 const int32_t* sizes_buf,
1611 const int32_t nof_sizes) {
1612 const int32_t*
const sizes_buffers[NDIM] = {sizes_buf};
1613 int32_t sizes_lengths[NDIM] = {nof_sizes};
1614 return setItemWorker<NDIM, check_sizes>(index,
1619 static_cast<int32_t
>(NDIM));
1622 template <
size_t NDIM=2,
bool check_sizes=true>
1624 const int8_t* values_buf,
1625 const int32_t nof_values,
1626 const int32_t* sizes_buf,
1627 const int32_t nof_sizes,
1628 const int32_t* sizes_of_sizes_buf,
1629 const int32_t nof_sizes_of_sizes) {
1630 const int32_t*
const sizes_buffers[NDIM] = {sizes_of_sizes_buf, sizes_buf};
1631 int32_t sizes_lengths[NDIM] = {nof_sizes_of_sizes, nof_sizes};
1632 return setItemWorker<NDIM, check_sizes>(index,
1637 static_cast<int32_t
>(NDIM));
1640 template <
size_t NDIM=1,
bool check_sizes=true>
1646 return setItemWorker<NDIM, check_sizes>(index,
1654 template <
size_t NDIM=0,
bool check_sizes=true>
1656 const int8_t* values_buf,
1657 const int32_t nof_values) {
1658 const int32_t*
const sizes_buffers[1] = {
nullptr};
1659 int32_t sizes_lengths[1] = {0};
1660 return concatItemWorker<1, check_sizes>(index,
1668 template <
size_t NDIM=1,
bool check_sizes=true>
1674 return concatItemWorker<NDIM, check_sizes>(index,
1684 const auto* metadata = getNestedArrayMetadata();
1685 if (metadata->value_type !=
Int8) {
1697 s.assign(reinterpret_cast<const char*>(item.
values), static_cast<size_t>(item.
nof_values));
1703 template <
typename CT>
1705 std::vector<CT>& values,
1706 std::vector<int32_t>& sizes,
1708 if constexpr (!std::is_same<CT, uint8_t>::value) {
1709 if constexpr (std::is_same<CT, double>::value) {
1710 const auto* metadata = getNestedArrayMetadata();
1714 }
else if constexpr (std::is_same<CT, int32_t>::value) {
1715 const auto* metadata = getNestedArrayMetadata();
1735 const auto values_count = item.
nof_values * valuesize /
sizeof(CT);
1736 values.reserve(values_count);
1737 values.insert(values.end(),
1738 reinterpret_cast<CT*
>(item.
values),
1739 reinterpret_cast<CT*>(item.
values) + values_count);
1742 sizes.insert(sizes.end(),
1748 template <
typename CT>
1750 std::vector<CT>& values,
1751 std::vector<int32_t>& sizes,
1752 std::vector<int32_t>& sizes_of_sizes,
1754 if constexpr (!std::is_same<CT, uint8_t>::value) {
1755 if constexpr (std::is_same<CT, double>::value) {
1756 const auto* metadata = getNestedArrayMetadata();
1760 }
else if constexpr (std::is_same<CT, int32_t>::value) {
1761 const auto* metadata = getNestedArrayMetadata();
1781 const auto values_count = item.
nof_values * valuesize /
sizeof(CT);
1782 values.reserve(values_count);
1783 values.insert(values.end(),
1784 reinterpret_cast<CT*
>(item.
values),
1785 reinterpret_cast<CT*>(item.
values) + values_count);
1788 sizes.insert(sizes.end(),
1793 sizes_of_sizes.insert(sizes_of_sizes.end(),
1801 const auto* metadata = getNestedArrayMetadata();
1802 if (metadata->value_type !=
Int8) {
1805 return setItem<1, false>(index,
reinterpret_cast<const int8_t*
>(s.data()), s.size());
1808 template <
typename CT,
size_t NDIM=0>
1813 if constexpr (!std::is_same<CT, uint8_t>::value) {
1814 if constexpr (std::is_same<CT, double>::value) {
1815 const auto* metadata = getNestedArrayMetadata();
1819 }
else if constexpr (std::is_same<CT, int32_t>::value) {
1820 const auto* metadata = getNestedArrayMetadata();
1829 auto sz = (arr.size() *
sizeof(CT)) / valuesize;
1830 const int32_t*
const sizes_buffers[1] = {
nullptr};
1831 int32_t sizes_lengths[1] = {0};
1832 return setItemWorker<1, false>(index,
1833 reinterpret_cast<const int8_t*
>(arr.data()),
1840 template <
typename CT,
size_t NDIM=1,
bool check_sizes=false>
1843 std::vector<int32_t> sizes;
1844 sizes.reserve(item.size());
1845 int32_t nof_values = 0;
1846 size_t nof_elements = 0;
1847 for (
const auto& subitem: item) {
1848 const auto sz = (subitem.size() *
sizeof(CT)) / valuesize;
1849 sizes.push_back(sz);
1851 nof_elements += subitem.size();
1853 std::vector<CT> flatitem;
1854 flatitem.reserve(nof_elements);
1855 for (
const auto& subitem: item) {
1856 flatitem.insert(flatitem.end(), subitem.begin(), subitem.end());
1858 return setItem<CT, NDIM, check_sizes>(index, flatitem, sizes);
1861 template <
typename CT,
size_t NDIM=2,
bool check_sizes=false>
1863 const std::vector<std::vector<std::vector<CT>>>& item) {
1865 std::vector<int32_t> sizes_of_sizes;
1866 std::vector<int32_t> sizes;
1867 std::vector<CT> flatitem;
1868 sizes_of_sizes.reserve(item.size());
1869 size_t nof_sizes_of_sizes = 0;
1870 for (
const auto& subitem: item) {
1871 sizes_of_sizes.push_back(subitem.size());
1872 nof_sizes_of_sizes += subitem.size();
1874 sizes.reserve(nof_sizes_of_sizes);
1875 int32_t nof_values = 0;
1876 size_t nof_elements = 0;
1877 for (
const auto& subitem: item) {
1878 for (
const auto& subitem1: subitem) {
1879 const auto sz = (subitem1.size() *
sizeof(CT)) / valuesize;
1880 sizes.push_back(sz);
1882 nof_elements += subitem1.size();
1885 flatitem.reserve(nof_elements);
1886 for (
const auto& subitem: item) {
1887 for (
const auto& subitem1: subitem) {
1888 flatitem.insert(flatitem.end(), subitem1.begin(), subitem1.end());
1891 return setItem<CT, NDIM, check_sizes>(index, flatitem, sizes, sizes_of_sizes);
1894 template <
typename CT,
size_t NDIM=1,
bool check_sizes=true>
1896 const std::vector<CT>& values,
1897 const std::vector<int32_t>& sizes) {
1901 const auto* metadata = getNestedArrayMetadata();
1902 if constexpr (!std::is_same<CT, uint8_t>::value) {
1903 if constexpr (std::is_same<CT, double>::value) {
1907 }
else if constexpr (std::is_same<CT, int32_t>::value) {
1916 const int32_t nof_values = (values.size() *
sizeof(CT)) / valuesize;
1917 return setItem<NDIM, check_sizes>(index,
1918 reinterpret_cast<const int8_t*
>(values.data()),
1924 template <
typename CT,
size_t NDIM=2,
bool check_sizes=true>
1926 const std::vector<CT>& values,
1927 const std::vector<int32_t>& sizes,
1928 const std::vector<int32_t>& sizes_of_sizes) {
1932 const auto* metadata = getNestedArrayMetadata();
1933 if constexpr (!std::is_same<CT, uint8_t>::value) {
1934 if constexpr (std::is_same<CT, double>::value) {
1938 }
else if constexpr (std::is_same<CT, int32_t>::value) {
1947 const auto nof_values = (values.size() *
sizeof(CT)) / valuesize;
1948 return setItem<NDIM, check_sizes>(index,
1949 reinterpret_cast<const int8_t*
>(values.data()),
1953 sizes_of_sizes.data(),
1954 sizes_of_sizes.size()
1966 int8_t**
dest =
nullptr) {
1973 if (size != itemsize) {
1994 const int64_t csize = index * itemsize;
1995 if (src !=
nullptr && memcpy(values + csize, src, size) ==
nullptr) {
1998 if (dest !=
nullptr) {
1999 *dest = values + csize;
2023 return storage_indices[index] >= 0;
2035 if (storage_indices[index] >= 0) {
2038 auto* worker = getNestedArrayWorker();
2039 const auto storage_index = worker->specified_items_count;
2040 worker->specified_items_count++;
2041 storage_indices[index] = storage_index;
2043 auto* sizes_buffer = get_sizes_buffer();
2044 auto* values_offsets = get_values_offsets();
2045 auto* sizes_offsets = get_sizes_offsets();
2046 const auto values_offset = values_offsets[storage_index];
2047 const auto sizes_offset = sizes_offsets[storage_index * ndims];
2048 sizes_buffer[sizes_offset] = 0;
2049 for (
size_t i = 0; i < ndims; i++) {
2050 sizes_offsets[storage_index * ndims + i + 1] = sizes_offset + 1;
2052 values_offsets[storage_index] = -(values_offset + 1);
2053 values_offsets[storage_index + 1] = values_offset;
2078 const auto* metadata = getGeoPointMetadata();
2079 if (metadata->is_geoint) {
2081 *
reinterpret_cast<uint32_t*
>(values + index * itemsize) = 0x80000000U;
2082 *
reinterpret_cast<uint32_t*
>(values + index * itemsize +
sizeof(int32_t)) =
2086 *
reinterpret_cast<double*
>(values + index * itemsize) = 2 * DBL_MIN;
2087 *
reinterpret_cast<double*
>(values + index * itemsize +
sizeof(double)) =
2105 const auto* values_offsets = get_values_offsets();
2106 const auto values_offset = values_offsets[storage_index];
2107 is_null = values_offset < 0;
2117 const auto* metadata = getGeoPointMetadata();
2119 if (metadata->is_geoint) {
2121 is_null = (*
reinterpret_cast<const uint32_t*
>(values + index * itemsize)) ==
2125 is_null = (*
reinterpret_cast<const double*
>(values + index * itemsize)) ==
2149 dest = values + index * itemsize;
2167 #ifdef HAVE_TOSTRING
2168 #define HAVE_FLATBUFFER_TOSTRING
2169 std::string bufferToString(
const int8_t*
buffer,
2172 size_t value_size =
get_size(value_type);
2173 size_t count = size / value_size;
2175 for (
size_t i = 0; i < count; i++) {
2179 switch (value_type) {
2181 result += (buffer[i] ?
"true" :
"false");
2187 result +=
std::to_string(reinterpret_cast<const int16_t*>(buffer)[i]);
2190 result +=
std::to_string(reinterpret_cast<const int32_t*>(buffer)[i]);
2193 result +=
std::to_string(reinterpret_cast<const int64_t*>(buffer)[i]);
2196 result +=
std::to_string(reinterpret_cast<const uint8_t*>(buffer)[i]);
2199 result +=
std::to_string(reinterpret_cast<const uint16_t*>(buffer)[i]);
2202 result +=
std::to_string(reinterpret_cast<const uint32_t*>(buffer)[i]);
2205 result +=
std::to_string(reinterpret_cast<const uint64_t*>(buffer)[i]);
2208 result +=
std::to_string(reinterpret_cast<const float*>(buffer)[i]);
2211 result +=
std::to_string(reinterpret_cast<const double*>(buffer)[i]);
2218 result +=
std::to_string(reinterpret_cast<const int32_t*>(buffer)[2 * i]);
2220 result +=
std::to_string(reinterpret_cast<const int32_t*>(buffer)[2 * i + 1]);
2229 result +=
std::to_string(reinterpret_cast<const double*>(buffer)[2 * i]);
2231 result +=
std::to_string(reinterpret_cast<const double*>(buffer)[2 * i + 1]);
2241 if (buffer ==
nullptr) {
2248 const auto* metadata = getNestedArrayMetadata();
2249 const auto* worker = getNestedArrayWorker();
2250 result +=
",\n " + metadata->toString();
2251 result +=
",\n " + worker->toString();
2252 result +=
",\n values_buffer=[" +
2256 result +=
",\n sizes_buffer=[" +
2258 reinterpret_cast<const int8_t*>(get_sizes_buffer()),
2262 result +=
",\n values_offsets=[" +
2263 bufferToString(reinterpret_cast<const int8_t*>(get_values_offsets()),
2264 (metadata->total_items_count + 1) *
2268 result +=
",\n sizes_offsets=[" +
2269 bufferToString(reinterpret_cast<const int8_t*>(get_sizes_offsets()),
2270 (metadata->total_items_count * metadata->ndims + 1) *
2274 result +=
",\n storage_indices=[" +
2280 result +=
",\n user_data_buffer=[" +
2281 bufferToString(get_user_data_buffer(), metadata->user_data_size,
Int8) +
2290 std::cout <<
"fmt=" <<
static_cast<int64_t
>(fmt) <<
", " <<
sizeof(fmt) << std::endl;
2293 result +=
", " + getGeoPointMetadata()->toString();
2294 result +=
", " + getGeoPointWorker()->toString();
2303 const auto* metadata = getGeoPointMetadata();
2304 result +=
", point data=";
2306 if (metadata->is_geoint) {
2307 const int32_t* values_buf =
reinterpret_cast<const int32_t*
>(
get_values());
2308 std::vector<int32_t> values(values_buf, values_buf + numitems * 2);
2311 const double* values_buf =
reinterpret_cast<const double*
>(
get_values());
2312 std::vector<double> values(values_buf, values_buf + numitems * 2);
2315 return result +
")";
2325 #ifdef HAVE_TOSTRING
2326 inline std::ostream&
operator<<(std::ostream& os,
2366 os <<
"PointFloat64";
2373 std::ostringstream ss;
2379 std::ostringstream ss;
2384 inline std::ostream&
operator<<(std::ostream& os,
2394 os <<
"SubIndexError";
2400 os <<
"FlatbufferSizeError";
2403 os <<
"ItemAlreadySpecifiedError";
2406 os <<
"ItemUnspecifiedError";
2409 os <<
"UnexpectedNullItemError";
2412 os <<
"ValuesBufferTooSmallError";
2415 os <<
"SizesBufferTooSmallError";
2418 os <<
"CompressedIndices2BufferTooSmallError";
2421 os <<
"MemoryError";
2424 os <<
"UnknownFormatError";
2427 os <<
"NotSupportedFormatError";
2430 os <<
"NotImplementedError";
2433 os <<
"InvalidUserDataError";
2436 os <<
"DimensionalityError";
2439 os <<
"UserDataError";
2445 os <<
"InconsistentSizesError";
2448 os <<
"[Unknown FlatBufferManager::Status value]";
2454 std::ostringstream ss;
HOST DEVICE size_t getNDims() const
static size_t get_size(ValueType type)
FLATBUFFER_MANAGER_FORMAT_TOOLS(GeoPoint)
offsets_t format_worker_offset
#define FLATBUFFER_OFFSETS_T_VALUE_TYPE
offsets_t format_metadata_offset
HOST DEVICE size_t getValuesBufferSize() const
HOST DEVICE Status getItemWorker(const int64_t index[NDIM], const size_t n, int8_t *&values, int32_t &nof_values, int32_t *sizes_buffers[NDIM], int32_t sizes_lengths[NDIM], int32_t &nof_sizes, bool &is_null)
HOST DEVICE bool isNestedArray() const
HOST DEVICE Status concatItem(const int64_t index, const NestedArrayItem< NDIM > &item)
HOST DEVICE int64_t dtypeSize() const
int64_t total_sizes_count
#define FLATBUFFER_UNREACHABLE()
offsets_t values_offsets_offset
offsets_t sizes_buffer_offset
HOST DEVICE bool containsNullValue(const int8_t *value_ptr) const
HOST DEVICE Status setNullNoValidation(int64_t index)
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Status setItem(const int64_t index, const std::vector< std::vector< std::vector< CT >>> &item)
HOST DEVICE Status getItemOld(int64_t index, int64_t &size, int8_t *&dest, bool &is_null)
HOST DEVICE size_t getValueSize() const
HOST DEVICE const int8_t * getNullValuePtr() const
HOST DEVICE FlatBufferFormat format() const
HOST DEVICE const sizes_t * get_storage_indices() const
#define RETURN_ERROR(exc)
offsets_t flatbuffer_size
HOST DEVICE Status setItemWorker(const int64_t index, const int8_t *values, const int32_t nof_values, const int32_t *const sizes_buffers[NDIM], const int32_t sizes_lengths[NDIM], const int32_t nof_sizes)
Status setItem(const int64_t index, const std::vector< std::vector< CT >> &item)
HOST DEVICE sizes_t get_storage_index(const int64_t index) const
HOST DEVICE Status getItem(const int64_t index, NestedArrayItem< NDIM > &result)
void initialize(FlatBufferFormat format_id, const int8_t *format_metadata_ptr)
HOST DEVICE Status getLength(const int64_t index, size_t &length)
int64_t specified_items_count
FlatBufferFormat format_id
CONSTEXPR DEVICE bool is_null(const T &value)
HOST DEVICE const int8_t * get_values() const
const int64_t & get_storage_count() const
offsets_t sizes_offsets_offset
int64_t get_max_nof_values() const
HOST DEVICE Status concatItemWorker(const int64_t index, const int8_t *values, const int32_t nof_values, const int32_t *const sizes_buffers[NDIM], const int32_t sizes_lengths[NDIM], const int32_t nof_sizes)
HOST DEVICE sizes_t * get_storage_indices()
offsets_t user_data_buffer_offset
HOST DEVICE bool isSpecified(int64_t index) const
Status getItem(const int64_t index, std::string &s, bool &is_null)
HOST DEVICE Status setItem(const int64_t index, const int8_t *values_buf, const int32_t nof_values)
Status setItemOld(const int64_t index, const int8_t *src, const int64_t size, int8_t **dest=nullptr)
HOST DEVICE Status getItem(const int64_t index[NDIM], const size_t n, NestedArrayItem< NDIM > &result)
offsets_t storage_indices_offset
std::string toString(const Executor::ExtModuleKinds &kind)
Status setItem(const int64_t index, const std::string &s)
HOST DEVICE int64_t itemsCount() const
int64_t getBufferSize() const
HOST DEVICE int8_t * get_values()
Status getItem(const int64_t index, std::vector< CT > &values, std::vector< int32_t > &sizes, std::vector< int32_t > &sizes_of_sizes, bool &is_null)
static int64_t compute_flatbuffer_size(FlatBufferFormat format_id, const int8_t *format_metadata_ptr)
FLATBUFFER_GET_BUFFER_METHODS(user_data_buffer, int8_t)
HOST DEVICE const int8_t * getValuesBuffer() const
HOST DEVICE Status getItemOld(int64_t index, size_t &size, int8_t *&dest, bool &is_null)
Status setEmptyItemNoValidation(int64_t index, int64_t size, int8_t **dest)
int32_t * sizes_buffers[NDIM]
int64_t get_values_buffer_size() const
static int64_t computeBufferSizeNestedArray(int64_t ndims, int64_t total_items_count, int64_t total_sizes_count, int64_t total_values_count, ValueType value_type, size_t user_data_size)
HOST DEVICE Status getLength(const int64_t index[NDIM], const size_t n, size_t &length) const
HOST DEVICE BaseWorker * getBaseWorker()
std::string typeName(const T *v)
Status initializeNestedArray(int64_t ndims, int64_t total_items_count, int64_t total_sizes_count, int64_t total_values_count, ValueType value_type, const int8_t *null_value_ptr, const int8_t *user_data_ptr, size_t user_data_size)
HOST DEVICE Status setItem(const int64_t index, const int8_t *values_buf, const int32_t nof_values, const int32_t *sizes_buf, const int32_t nof_sizes)
int64_t total_items_count
int64_t total_values_count
Status setItem(const int64_t index, const std::vector< CT > &values, const std::vector< int32_t > &sizes, const std::vector< int32_t > &sizes_of_sizes)
#define FLATBUFFER_MANAGER_SET_OFFSET(OBJ, NAME, SIZE)
Status setItem(const int64_t index, const std::vector< CT > &values, const std::vector< int32_t > &sizes)
int64_t _align_to_int64(int64_t addr)
HOST DEVICE Status setItem(const int64_t index, const int8_t *values_buf, const int32_t nof_values, const int32_t *sizes_buf, const int32_t nof_sizes, const int32_t *sizes_of_sizes_buf, const int32_t nof_sizes_of_sizes)
HOST DEVICE int64_t & get_storage_count()
offsets_t values_buffer_offset
HOST DEVICE int64_t valueByteSize() const
size_t getValuesCount() const
HOST DEVICE Status isNull(int64_t index, bool &is_null) const
int64_t total_items_count
#define FLATBUFFER_SIZES_T_VALUE_TYPE
HOST DEVICE Status concatItem(const int64_t index, const int8_t *values_buf, const int32_t nof_values)
HOST DEVICE Status isNull(const int64_t index[NDIM], const size_t n, bool &is_null)
HOST DEVICE const BaseWorker * getBaseWorker() const
HOST static DEVICE bool isFlatBuffer(const void *buffer)
int32_t sizes_lengths[NDIM]
Status getItem(const int64_t index, std::vector< CT > &values, std::vector< int32_t > &sizes, bool &is_null)
HOST DEVICE Status setNull(int64_t index)
HOST DEVICE Status setItem(const int64_t index, const NestedArrayItem< NDIM > &item)
Status setItem(const int64_t index, const std::vector< CT > &arr)
static int64_t getBufferSize(const void *buffer)
Status setItemNoValidation(const int64_t index, const int8_t *src, const int64_t size, int8_t **dest)