Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/components/plots/AnalysisWG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ const AnalysisWG = ({ setTexture, }: { setTexture: React.Dispatch<React.SetState
xSlice: state.xSlice
})));
const isMounted = useRef(false)

useEffect(() => {
if (!plotOn){
return
}
const dataArray = GetCurrentArray(analysisStore);
// Guard clauses: exit if not triggered, no operation is selected, or data is invalid.
if (!operation || dataArray.length <= 1) {
if (!operation) {
return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check for dataArray.length <= 1 is no longer needed because GetCurrentArray is always called, and the function itself handles cases where the data might be invalid or empty. Removing this check simplifies the logic and avoids potential issues if dataArray is unexpectedly empty or has a length of 1.

const executeAnalysis = async () => {
Expand All @@ -100,7 +98,7 @@ const AnalysisWG = ({ setTexture, }: { setTexture: React.Dispatch<React.SetState
}

// --- 2. Dispatch GPU computation based on the operation ---
const inputArray = analysisMode ? analysisArray : dataArray;
const inputArray = GetCurrentArray(analysisStore)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

By calling GetCurrentArray(analysisStore) directly, you ensure that the inputArray always reflects the most up-to-date data based on the current state of analysisStore. This eliminates the need for a conditional assignment based on analysisMode and ensures that the correct data is used for GPU computation.

const shapeInfo = { shape: dataShape, strides};
const kernelParams = { kernelDepth, kernelSize };
// [1538316, 1481, 1]
Expand Down
11 changes: 3 additions & 8 deletions src/utils/HelperFuncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ export function GetCurrentArray(overrideStore?:string){
const [xStartIdx, xEndIdx] = currentChunks.x
const [yStartIdx, yEndIdx] = currentChunks.y
const [zStartIdx, zEndIdx] = currentChunks.z
let chunkShape;
let chunkStride;

for (let z = zStartIdx; z < zEndIdx; z++) {
Comment on lines +278 to 279
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variables chunkShape and chunkStride are no longer needed as temporary variables. The chunk shape and stride are now directly accessed from the chunk object within the loop, simplifying the code and reducing memory usage.

for (let y = yStartIdx; y < yEndIdx; y++) {
for (let x = xStartIdx; x < xEndIdx; x++) {
Expand All @@ -285,14 +284,10 @@ export function GetCurrentArray(overrideStore?:string){
const chunk = cache.get(cacheName)
const compressed = chunk.compressed
const thisData = compressed ? DecompressArray(chunk.data) : chunk.data
if (!chunkShape) {
chunkShape = chunk.shape
chunkStride = chunk.stride
}
copyChunkToArray(
thisData,
chunkShape,
chunkStride,
chunk.shape,
chunk.stride,
Comment on lines 287 to +290
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

By directly passing chunk.shape and chunk.stride to copyChunkToArray, you ensure that the correct chunk-specific parameters are used for copying data. This resolves the original issue where a global stride value was causing incorrect data analysis on the edges of certain datasets.

Suggested change
copyChunkToArray(
thisData,
chunkShape,
chunkStride,
chunk.shape,
chunk.stride,
copyChunkToArray(
thisData,
chunk.shape,
chunk.stride,
typedArray,
dataShape,
strides as [number, number, number],

typedArray,
dataShape,
strides as [number, number, number],
Expand Down
Loading