Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tile(cls, op):
import tiledb
tensor = super().tile(op)[0]
ctx = tiledb.Ctx(op.tiledb_config)
tiledb_array_type = tiledb.SparseArray if tensor.issparse() else tiledb.DenseArray
try:
tiledb_array_type(uri=op.tiledb_uri, key=op.tiledb_key,
timestamp=op.tiledb_timestamp, ctx=ctx)
except tiledb.TileDBError:
# not exist, try to create TileDB Array by given uri
tiledb_array_schema = get_tiledb_schema_from_tensor(op.input, ctx, op.input.nsplits)
tiledb_array_type.create(op.tiledb_uri, tiledb_array_schema, key=op.tiledb_key)
return [tensor]
def write_array(data_dict):
ctx = tiledb.Ctx()
# open array for writing, and write data
with tiledb.open(array_name, 'w', ctx=ctx) as array:
array[:] = data_dict
def main():
# Create TileDB context
ctx = tiledb.Ctx()
# Load the dense array schema
dense_example = tiledb.DenseArray.load(ctx, "my_dense_array")
# Retrieve and print the non-empty domain
nonempty = dense_example.nonempty_domain()
print("Non-empty domain:")
for i in range(dense_example.ndim):
print("{0!s}: {1!r}".format(dense_example.domain.dim(i).name, nonempty[i]))
# Read an array slice. `result` is a dict of numpy arrays
result = dense_example[3:5, 3:5]
# Print the results
result_num = result["a1"].size
print("\nResult num: ", result_num)
def main():
ctx = tiledb.Ctx()
sparse_example = tiledb.SparseArray.load(ctx, "my_sparse_array")
result = sparse_example[3:5, 2:5][["a1", "a2"]]
result_num = len(result["coords"])
print("\nResult num: ", result_num)
print()
print("{:<10s}{:<5s}{:<10s}{:<10s}{:<10s}".format("coords", "a1", "a2", "a3[0]", "a3[1]"))
print("----------------------------------------")
for i in range(result_num):
print("{:<10s}{:<5d}{:<10s}{:<10.1f}{:<10.1f}"
.format(result["coords"][i],
result["a1"][i],
result["a2"][i],
result["a3"][i][0],
result["a3"][i][1]))
def _create_tiledb_ctx(conf_tuple):
if conf_tuple is not None:
return tiledb.Ctx(dict(conf_tuple))
return tiledb.Ctx()
# Set values
config["vfs.s3.connect_timeout_ms"] = 5000
config["vfs.s3.endpoint_override"] = "localhost:88880"
# Get values
tile_cache_size = config["sm.tile_cache_size"]
print("\nTile cache size: ", tile_cache_size)
# Print only the s3 settings
print("\nVFS S3 settings:")
for p, v in config.items(prefix="vfs.s3."):
print("{0!r} : {1!r}".format(p, v))
# Assign a config object to Ctx and VFS
ctx = tiledb.Ctx(config=config)
vfs = tiledb.VFS(ctx, config=config)
"""
Create and return an empty, writeable DenseArray with schema based on
a NumPy-array like object.
:param uri: array URI
:param arr: NumPy ndarray, or shape tuple
:param config: (optional, deprecated) configuration to apply to *new* Ctx
:param key: (optional) encryption key, if applicable
:param tile: (optional) tiling of generated array
:param ctx: (optional) TileDB Ctx
:return:
"""
if config is not None:
warnings.warn(DeprecationWarning("'config' keyword argument is deprecated; use 'ctx'"))
cfg = tiledb.Config(config)
ctx = tiledb.Ctx(cfg)
elif ctx is None:
ctx = default_ctx()
if arr is ArraySchema:
schema = arr
else:
schema = schema_like(arr, tile=tile, ctx=ctx)
tiledb.DenseArray.create(uri, key=key, schema=schema)
return tiledb.DenseArray(uri, mode='w', key=key, ctx=ctx)
def fromtiledb(uri, ctx=None, key=None, timestamp=None, gpu=None):
import tiledb
raw_ctx = ctx
if raw_ctx is None:
ctx = tiledb.Ctx()
# get metadata from tiledb
try:
tiledb_arr = tiledb.DenseArray(uri=uri, ctx=ctx, key=key, timestamp=timestamp)
sparse = False
except ValueError:
# if the array is not dense, ValueError will be raised by tiledb
tiledb_arr = tiledb.SparseArray(uri=uri, ctx=ctx, key=key, timestamp=timestamp)
sparse = True
if tiledb_arr.nattr > 1:
raise NotImplementedError('Does not supported TileDB array schema '
'with more than 1 attr')
tiledb_dim_starts = tuple(tiledb_arr.domain.dim(j).domain[0]
for j in range(tiledb_arr.ndim))
if any(isinstance(s, float) for s in tiledb_dim_starts):