Skip to content

Commit

Permalink
Move size check logic into shared helper
Browse files Browse the repository at this point in the history
  • Loading branch information
katamartin committed Jan 15, 2025
1 parent f93f559 commit 1383be3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const toKeyArray = (chunkKey, { chunk_separator }) => {
return chunkKey.split(chunk_separator).map(Number)
}

const isArrayOverSizeLimit = (dimensions) => {
return dimensions.reduce((product, d) => product * d, 1) >= MAX_ARRAY_LENGTH
}

const getChunkShapeOverride = (chunkShape, shape, dimensions, axes) => {
if (chunkShape.length === 1) {
return null
Expand All @@ -104,8 +108,7 @@ const getChunkShapeOverride = (chunkShape, shape, dimensions, axes) => {
const fullSpace =
dimensions
.filter((d) => [axes?.X, axes?.Y].includes(d))
.every((d) => d <= 360) &&
chunkShape.reduce((product, d) => product * d, 1) < MAX_ARRAY_LENGTH
.every((d) => d <= 360) && !isArrayOverSizeLimit(chunkShape)

return dimensions.map((d, i) => {
if ([axes?.X, axes?.Y].includes(d)) {
Expand Down Expand Up @@ -353,7 +356,7 @@ export const getVariableInfo = async (
if (
isSpatialDimension(dimensions[i]) ||
!arr ||
arr.shape > MAX_ARRAY_LENGTH
isArrayOverSizeLimit(arr.shape)
) {
return null
} else {
Expand Down

0 comments on commit 1383be3

Please sign in to comment.