-
-
Save ihnorton/00480fb03266f975478e7dfe645744a2 to your computer and use it in GitHub Desktop.
Demo sparse write to dense array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.12) | |
set(CMAKE_CXX_STANDARD 11) | |
set(CMAKE_BUILD_TYPE Debug) | |
set(TileDB_DIR "/bld/TileDB-dbg/dist/lib/cmake/TileDB") | |
find_package(TileDB REQUIRED) | |
add_executable(main main.cc) | |
target_link_libraries(main PRIVATE TileDB::tiledb_shared) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tiledb/tiledb> | |
#include <iostream> | |
using namespace tiledb; | |
void create_array(std::string path) { | |
int dim0 = 0; | |
int dim1 = 3; | |
uint64_t tile_size = 4; | |
auto ctx = Context(); | |
Domain domain(ctx); | |
domain | |
.add_dimension( | |
Dimension::create<int32_t>(ctx, "x", {{dim0, dim1}}, tile_size)) | |
.add_dimension( | |
Dimension::create<int32_t>(ctx, "y", {{dim0, dim1}}, tile_size)) | |
.add_dimension( | |
Dimension::create<int32_t>(ctx, "z", {{dim0, dim1}}, tile_size)); | |
ArraySchema schema(ctx, TILEDB_DENSE); | |
schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}}); | |
schema.add_attribute(Attribute::create<double>(ctx, "")); | |
tiledb::Array::create(path, schema); | |
// write ones to array | |
Array a(ctx, path, TILEDB_WRITE); | |
Query q(ctx, a); | |
size_t nelem = pow(dim1-dim0 + 1, 3); | |
std::cout << "n: " << nelem << std::endl; | |
std::vector<double> data; | |
data.resize(nelem); | |
for (size_t i = 0; i < nelem; i++) | |
data[i] = 1.0; | |
q.set_buffer("", data); | |
q.submit(); | |
} | |
int main(int, char**) { | |
std::string path = "array1"; | |
create_array(path); | |
auto ctx = tiledb::Context(); | |
Array a(ctx, path, TILEDB_WRITE); | |
Query q(ctx, a); | |
std::vector<int32_t> x = {0, 2}; | |
std::vector<int32_t> y = {0, 2}; | |
std::vector<int32_t> z = {0, 2}; | |
std::vector<double> d = {7.0, 112.0}; | |
q.set_layout(TILEDB_GLOBAL_ORDER); | |
q.set_buffer("x", x); | |
q.set_buffer("y", y); | |
q.set_buffer("z", z); | |
q.set_buffer("", d); | |
q.submit(); | |
q.finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment