Skip to content

Commit

Permalink
Merge pull request #1103 from silx-kit/h5wasm-slice
Browse files Browse the repository at this point in the history
Implement slicing for h5wasm provider
  • Loading branch information
loichuder authored May 9, 2022
2 parents 368c4e8 + 9243ee4 commit bd6ca61
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/h5wasm/src/h5wasm-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
isH5WasmDataset,
isH5WasmGroup,
isHDF5,
convertSelectionToRanges,
} from './utils';

export class H5WasmApi extends ProviderApi {
Expand All @@ -43,11 +44,16 @@ export class H5WasmApi extends ProviderApi {
}

public async getValue(params: ValuesStoreParams): Promise<unknown> {
const { dataset } = params;
const { dataset, selection } = params;

const h5wDataset = await this.getH5WasmEntity(dataset.path);
assertH5WasmDataset(h5wDataset);

if (selection) {
const ranges = convertSelectionToRanges(h5wDataset, selection);
return h5wDataset.slice(ranges);
}

return h5wDataset.value;
}

Expand Down
16 changes: 16 additions & 0 deletions packages/h5wasm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ export function convertMetadataToDType(metadata: Metadata): DType {
};
}
}

export function convertSelectionToRanges(
dataset: H5WasmDataset,
selection: string
): number[][] {
const { shape } = dataset;
const selectionMembers = selection.split(',');

return selectionMembers.map((member, i) => {
if (member === ':') {
return [0, shape[i]];
}

return [Number(member), Number(member) + 1];
});
}

0 comments on commit bd6ca61

Please sign in to comment.