-
Notifications
You must be signed in to change notification settings - Fork 7
Reshape codec #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jbms
wants to merge
1
commit into
zarr-developers:main
Choose a base branch
from
jbms:reshape-codec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Reshape codec #10
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,117 @@ | ||||||
# reshape codec | ||||||
|
||||||
Defines an `array -> array` codec that performs a reshaping operation. | ||||||
|
||||||
Note that `reshape` always preserves the (logical) lexicographical order (i.e. C | ||||||
order traversal) of elements within an array, but may be combined with the | ||||||
`transpose` codec to both reorder and reshape an array. | ||||||
|
||||||
## Codec name | ||||||
|
||||||
The value of the `name` member in the codec object MUST be `reshape`. | ||||||
|
||||||
## Configuration parameters | ||||||
|
||||||
### `shape` | ||||||
An array specifying the size `B_shape[i]` of each dimension `i` of | ||||||
the *output* array `B` as a function of the shape `A_shape` of the input array | ||||||
`A`. Each element `shape[i]` must be one of: | ||||||
|
||||||
- a positive integer `size`, specifying that `B_shape[i] := size`. | ||||||
|
||||||
- an array of integers `input_dims`, specifying that: | ||||||
|
||||||
``` | ||||||
B_shape[i] := prod(A_shape[input_dims]] | ||||||
```. | ||||||
|
||||||
Specifying the corresponding `input_dims` rather than an explicit `size` is | ||||||
paticularly useful when using variable-size chunking. | ||||||
|
||||||
- the special value `-1`, which must occur at most once, specifying that | ||||||
`B_shape[i]` is determined automatically in order to satisfy the | ||||||
invariant that `prod(B_shape) == prod(A_shape)`. | ||||||
|
||||||
Implementations MUST return an error if the invariant | ||||||
|
||||||
``` | ||||||
prod(B_shape) == prod(A_shape) | ||||||
``` | ||||||
|
||||||
cannot be satisfied. | ||||||
|
||||||
Additionally, when `shape[i]` is specified as an array of integers `input_dims`, | ||||||
implementations MUST return an error if the following constraints are not | ||||||
satisfied: | ||||||
|
||||||
- the flattened list of input dimensions, over all elements of `shape`, must be | ||||||
in monotonically increasing order, i.e. `"shape": [[0, 1], 10, [3, 4]]` is | ||||||
allowed but the following are NOT allowed: | ||||||
|
||||||
- `"shape": [[1], [0]]` | ||||||
- `"shape": [[1, 0], 10, [3, 4]]` | ||||||
- `"shape": [[3, 4], 10, [0, 1]]` are not allowed. | ||||||
|
||||||
This constraint serves to avoid confusing `shape` configurations that may | ||||||
(incorrectly) suggest a transpose, when in fact the `reshape` codec never | ||||||
performs a transpose. | ||||||
|
||||||
- If `input_dims` specifies `k > 0` input dimensions: | ||||||
|
||||||
`prod(B_shape[:i]) == prod(A_shape[input_dims[0]])` and | ||||||
`prod(B_shape[i+1:]) == prod(A_shape[input_dims[k-1]+1:])`. | ||||||
|
||||||
This two constraints ensure that if the size of output dimension `i` is | ||||||
specified by `input_dims`, the coordinates in the input array along `input_dims` | ||||||
actually correspond to the raveled index along output dimension `i`. | ||||||
|
||||||
## Example | ||||||
|
||||||
For example, the array metadata below specifies that the compressor is the Zstd | ||||||
codec configured with a compression level of 1 and with the checksum stored: | ||||||
Comment on lines
+70
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this description does not match the JSON |
||||||
|
||||||
```json | ||||||
{ | ||||||
"chunk_grid": { | ||||||
"name": "regular", | ||||||
"configuration": { | ||||||
"chunk_shape": [100, 50, 64, 3] | ||||||
} | ||||||
}, | ||||||
"codecs": [ | ||||||
{ | ||||||
"name": "reshape", | ||||||
"configuration": { | ||||||
"shape": [[0, 1], [2], 3] | ||||||
} | ||||||
}, | ||||||
{ | ||||||
"name": "bytes" | ||||||
"configuration": {"endian": "little"} | ||||||
} | ||||||
] | ||||||
} | ||||||
``` | ||||||
|
||||||
## Format and algorithm | ||||||
|
||||||
This is an `array -> array` codec. | ||||||
|
||||||
The dimensionality of the output array `B` is equal to the length of the `shape` | ||||||
configuration parameter, and the output shape `B_shape` is determined as | ||||||
specified above. | ||||||
|
||||||
As this codec does NOT alter the lexicographical order of elements, the contents | ||||||
of the output array `B` is related to the contents of the input array `A` by: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
`ravel(B) == ravel(A)`. | ||||||
|
||||||
Implementations should, when possible, construct a virtual view rather than copy | ||||||
the array. | ||||||
|
||||||
## Change log | ||||||
|
||||||
No changes yet. | ||||||
|
||||||
## Current maintainers | ||||||
|
||||||
* Jeremy Maitin-Shepard ([@jbms](https://github.com/jbms)), Google |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"const": "reshape" | ||
}, | ||
"configuration": { | ||
"type": "object", | ||
"properties": { | ||
"shape": { | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{"type": "integer", "minimum": -1}, | ||
{"type": "array", "items": {"type": "integer", "minimum": 0}} | ||
] | ||
} | ||
} | ||
}, | ||
"required": ["shape"], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"required": ["name", "configuration"], | ||
"additionalProperties": false | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.