How to use the tiledb.DenseArray function in tiledb

To help you get started, we’ve selected a few tiledb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TileDB-Inc / TileDB-Py / examples / writing_dense_padding.py View on Github external
def write_array():
    # Open the array and write to it.
    with tiledb.DenseArray(array_name, mode='w') as A:
        # Write to [2,3], [1,2]
        data = np.array(([1, 2], [3, 4]))
        A[2:4, 1:3] = data
github TileDB-Inc / TileDB-Py / examples / quickstart_dense.py View on Github external
def read_array():
    # Open the array and read from it.
    with tiledb.DenseArray(array_name, mode='r') as A:
        # Slice only rows 1, 2 and cols 2, 3, 4.
        data = A[1:3, 2:5]
        print(data["a"])
github TileDB-Inc / TileDB-Py / examples / reading_dense_layouts.py View on Github external
def write_array():
    # Open the array and write to it.
    with tiledb.DenseArray(array_name, mode='w') as A:
        # NOTE: global writes are not currently supported in the Python API.
        # The following code will produce the same array as the corresponding
        # C++ example in the docs (which wrote in global order)
        data = np.array(([1, 2, 5, 6],
                         [3, 4, 7, 8],
                         [9, 10, 13, 14],
                         [11, 12, 15, 16]))
        A[:] = data
github TileDB-Inc / TileDB-Py / examples / fragments_consolidation.py View on Github external
def write_array_1():
    with tiledb.DenseArray(array_name, mode='w') as A:
        A[1:3, 1:5] = np.array(([1, 2, 3, 4, 5, 6, 7, 8]))
github mars-project / mars / mars / tensor / datastore / totiledb.py View on Github external
tiledb_ctx = get_tiledb_ctx(op.tiledb_config)
        uri = op.tiledb_uri
        key = op.tiledb_key
        timestamp = op.tiledb_timestamp
        axis_offsets = op.axis_offsets

        chunk = op.outputs[0]
        if not chunk.issparse():
            # dense
            to_store = np.ascontiguousarray(ctx[op.input.key])
            slcs = []
            for axis in range(chunk.ndim):
                axis_offset = int(axis_offsets[axis])
                axis_length = int(op.input.shape[axis])
                slcs.append(slice(axis_offset, axis_offset + axis_length))
            with tiledb.DenseArray(uri=uri, ctx=tiledb_ctx, mode='w',
                                   key=key, timestamp=timestamp) as arr:
                arr[tuple(slcs)] = to_store
            ctx[chunk.key] = np.empty((0,) * chunk.ndim, dtype=chunk.dtype)
        else:
            # sparse
            to_store = ctx[op.input.key].spmatrix.tocoo()
            if to_store.nnz > 0:
                with tiledb.SparseArray(uri=uri, ctx=tiledb_ctx, mode='w',
                                        key=key, timestamp=timestamp) as arr:
                    if chunk.ndim == 1:
                        vec = to_store.col if to_store.shape[0] == 1 else to_store.row
                        vec += axis_offsets[0]
                        arr[vec] = to_store.data
                    else:
                        i, j = to_store.row + axis_offsets[0], to_store.col + axis_offsets[1]
                        arr[i, j] = to_store.data
github TileDB-Inc / TileDB-Py / examples / multi_attribute.py View on Github external
def read_array_subselect():
    # Open the array and read from it.
    with tiledb.DenseArray(array_name, mode='r') as A:
        # Slice only rows 1, 2 and cols 2, 3, 4, attribute 'a1' only.
        # We use the '.query()' syntax which allows attribute subselection.
        data = A.query(attrs=["a1"])[1:3, 2:5]
        print("Subselecting on attribute a1:")
        for a in data["a1"].flat:
            print("a1: '%s'" % chr(a))
github TileDB-Inc / TileDB-Py / examples / writing_dense_multiple.py View on Github external
def read_array():
    # Open the array and read from it.
    with tiledb.DenseArray(array_name, mode='r') as A:
        # Slice the entire array
        data = A[:]
        print(data["a"])
github TileDB-Inc / TileDB-Py / examples / using_tiledb_stats.py View on Github external
def write_array():
    # Open the array and write to it.
    with tiledb.DenseArray(array_name, mode='w') as A:
        data = np.arange(12000 * 12000)
        A[:] = data
github mars-project / mars / mars / tensor / datastore / totiledb.py View on Github external
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]