Skip to content

Commit

Permalink
allow forwarding of store options (alimanfoo#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Dec 17, 2021
1 parent 6655691 commit 8003d2e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zarrita",
"type": "module",
"license": "MIT",
"version": "0.2.0-beta.1",
"version": "0.2.0-beta.2",
"repository": {
"type": "git",
"url": "https://github.com/manzt/zarrita.js.git"
Expand Down
7 changes: 4 additions & 3 deletions src/lib/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ const unwrap = <D extends DataType>(

export async function get<
D extends DataType,
Store extends Readable | Async<Readable>,
Arr extends Chunk<D>,
Sel extends (null | Slice | number)[],
>(
arr: Array<D, Readable | Async<Readable>>,
arr: Array<D, Store>,
selection: null | Sel,
opts: GetOptions,
opts: GetOptions<Parameters<Store["get"]>[1]>,
setter: {
prepare: Prepare<D, Arr>;
set_scalar: SetScalar<D, Arr>;
Expand All @@ -50,7 +51,7 @@ export async function get<
// iterator over chunks
for (const { chunk_coords, chunk_selection, out_selection } of indexer) {
queue.add(() =>
arr.get_chunk(chunk_coords)
arr.get_chunk(chunk_coords, opts.opts)
.then(({ data, shape }) => {
const chunk = setter.prepare(data, shape);
setter.set_from_chunk(out, out_selection, chunk, chunk_selection);
Expand Down
7 changes: 5 additions & 2 deletions src/lib/hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ export class Array<
return bytes;
}

async get_chunk(chunk_coords: number[]): Promise<Chunk<Dtype>> {
async get_chunk(
chunk_coords: number[],
opts?: Parameters<Store["get"]>[1],
): Promise<Chunk<Dtype>> {
const chunk_key = this._chunk_key(chunk_coords);
const buffer = await this.store.get(chunk_key);
const buffer = await this.store.get(chunk_key, opts);
if (!buffer) throw new KeyError(chunk_key);
const data = await this._decode_chunk(buffer);
return { data, shape: [...this.chunk_shape] };
Expand Down
32 changes: 19 additions & 13 deletions src/ndarray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,30 @@ import { set as set_with_setter } from "./lib/set";
/** @category Utility */
export async function get<
D extends DataType,
Store extends Readable | Async<Readable>,
Sel extends (null | Slice | number)[],
>(
arr: Array<D, Readable | Async<Readable>>,
arr: Array<D, Store>,
selection: Sel | null = null,
opts: GetOptions = {},
opts: GetOptions<Parameters<Store["get"]>[1]> = {},
) {
return get_with_setter<D, ndarray.NdArray<TypedArray<D>>, Sel>(arr, selection, opts, {
prepare: ndarray,
set_scalar(target, selection, value) {
ops.assigns(view(target, selection), value);
},
set_from_chunk(target, target_selection, chunk, chunk_selection) {
ops.assign(
view(target, target_selection),
view(chunk, chunk_selection),
);
return get_with_setter<D, Store, ndarray.NdArray<TypedArray<D>>, Sel>(
arr,
selection,
opts,
{
prepare: ndarray,
set_scalar(target, selection, value) {
ops.assigns(view(target, selection), value);
},
set_from_chunk(target, target_selection, chunk, chunk_selection) {
ops.assign(
view(target, target_selection),
view(chunk, chunk_selection),
);
},
},
});
);
}

/** @category Utility */
Expand Down
7 changes: 4 additions & 3 deletions src/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import { set as set_with_setter } from "./lib/set";
/** @category Utility */
export async function get<
D extends Exclude<DataType, UnicodeStr | ByteStr>,
Store extends Readable | Async<Readable>,
Sel extends (null | Slice | number)[],
>(
arr: Array<D, Readable | Async<Readable>>,
arr: Array<D, Store>,
selection: Sel | null = null,
opts: GetOptions = {},
opts: GetOptions<Parameters<Store["get"]>[1]> = {},
) {
return get_with_setter<D, NdArray<D>, Sel>(arr, selection, opts, {
return get_with_setter<D, Store, NdArray<D>, Sel>(arr, selection, opts, {
prepare: (data, shape) => ({ data, shape, stride: get_strides(shape) }),
set_scalar(target, selection, value) {
set_scalar(compat(target), selection, cast_scalar(target, value));
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export type ChunkQueue = {
onIdle(): Promise<void[]>;
};

export type Options = { create_queue?: () => ChunkQueue };
export type GetOptions = Options;
export type Options = {
create_queue?: () => ChunkQueue;
};
export type GetOptions<O> = Options & { opts?: O };
export type SetOptions = Options;

0 comments on commit 8003d2e

Please sign in to comment.