Skip to content

Commit

Permalink
Compute mappedArray with ndarray-ops
Browse files Browse the repository at this point in the history
  • Loading branch information
loichuder committed Sep 15, 2020
1 parent f3146f8 commit 24fbbf0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"lodash-es": "^4.17.15",
"nanoid": "^2.1.11",
"ndarray": "^1.0.19",
"ndarray-ops": "^1.2.2",
"ndarray-unpack": "^1.0.0",
"normalize.css": "^8.0.1",
"react": "^16.13.1",
Expand Down
7 changes: 5 additions & 2 deletions src/h5web/visualizations/shared/MappedVis.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ReactElement, useMemo, ElementType } from 'react';
import { isNumber } from 'lodash-es';
import ndarray from 'ndarray';
import unpack from 'ndarray-unpack';
import ops from 'ndarray-ops';
import type { DimensionMapping } from '../../dataset-visualizer/models';
import type { HDF5Dataset, HDF5SimpleShape } from '../../providers/models';

Expand Down Expand Up @@ -34,7 +34,10 @@ function MappedVis<T>(props: Props<T>): ReactElement {
const mappedView = isXBeforeY ? slicedView.transpose(1, 0) : slicedView;

// Create ndarray from mapped view so `dataArray.data` only contains values relevant to vis
return ndarray<T>(unpack(mappedView).flat(), mappedView.shape);
const mappedArray = ndarray<T>([], mappedView.shape);
ops.assign(mappedArray, mappedView);

return mappedArray;
}, [mapperState, baseArray]);

return <Component dataArray={dataArray} />;
Expand Down
6 changes: 6 additions & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ declare module 'ndarray-unpack' {

export = unpack;
}

declare module 'ndarray-ops' {
function assign(a: ndarray<T>, b: ndarray<T>);

export = { assign };
}

0 comments on commit 24fbbf0

Please sign in to comment.