Skip to content
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

Use pcodec bounded representation #15

Merged
merged 4 commits into from
Mar 21, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build:
strategy:
matrix:
toolchain: ["stable", "1.71", "beta", "nightly"]
toolchain: ["stable", "1.73", "beta", "nightly"]
features: ["--features \"\"", "--all-features", "--no-default-features"]
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- **Breaking**: Bump MSRV to 1.73 (5 October, 2023)
- Bump `pco` (pcodec) to 0.2.1

## [0.12.5] - 2024-03-17

### Added
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "zarrs"
version = "0.12.5"
authors = ["Lachlan Deakin <[email protected]>"]
edition = "2021"
rust-version = "1.71"
rust-version = "1.73"
description = "A library for the Zarr V3 storage format for multidimensional arrays and metadata"
documentation = "https://docs.rs/zarrs"
repository = "https://github.com/LDeakin/zarrs"
Expand Down Expand Up @@ -60,7 +60,7 @@ object_store = { version = "0.9.0", optional = true }
opendal = { version = "0.45", optional = true }
parking_lot = "0.12"
pathdiff = "0.2"
pco = { version = "0.1.3", optional = true }
pco = { version = "0.2.1", optional = true }
rayon = "1.6"
rayon_iter_concurrent_limit = "0.2.0"
reqwest = { version = "0.11", features = ["blocking"], optional = true }
Expand Down
12 changes: 2 additions & 10 deletions src/array/codec/array_to_bytes/pcodec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ mod tests {
ChunkRepresentation::new(chunk_shape, data_type, fill_value).unwrap();
let bytes: Vec<u8> = (0..chunk_representation.size()).map(|s| s as u8).collect();

let max_encoded_size = codec.compute_encoded_size(&chunk_representation)?;
let encoded = codec.encode(
bytes.clone(),
&chunk_representation,
&CodecOptions::default(),
)?;
assert!((encoded.len() as u64) <= max_encoded_size.size().unwrap());
let decoded = codec
.decode(encoded, &chunk_representation, &CodecOptions::default())
.unwrap();
Expand All @@ -240,7 +242,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_u32() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -251,7 +252,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_u64() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -262,7 +262,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_i32() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -273,7 +272,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_i64() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -284,7 +282,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_f32() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -295,7 +292,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_f64() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -306,7 +302,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_complex64() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -317,7 +312,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_round_trip_complex128() {
codec_pcodec_round_trip_impl(
&PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()),
Expand All @@ -338,7 +332,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn codec_pcodec_partial_decode() {
let chunk_shape: ChunkShape = vec![4, 4].try_into().unwrap();
let chunk_representation = ChunkRepresentation::new(
Expand Down Expand Up @@ -381,7 +374,6 @@ mod tests {

#[cfg(feature = "async")]
#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn codec_pcodec_async_partial_decode() {
let chunk_shape: ChunkShape = vec![4, 4].try_into().unwrap();
let chunk_representation = ChunkRepresentation::new(
Expand Down
29 changes: 24 additions & 5 deletions src/array/codec/array_to_bytes/pcodec/pcodec_codec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pco::{ChunkConfig, FloatMultSpec, IntMultSpec, PagingSpec};
use pco::{standalone::guarantee::file_size, ChunkConfig, FloatMultSpec, IntMultSpec, PagingSpec};

use crate::{
array::{
Expand Down Expand Up @@ -147,7 +147,7 @@ impl ArrayCodecTraits for PcodecCodec {
let data_type = decoded_representation.data_type();
macro_rules! pcodec_decode {
( $t:ty ) => {
pco::standalone::auto_decompress(encoded_value.as_slice())
pco::standalone::simple_decompress(encoded_value.as_slice())
.map(|bytes| transmute_to_bytes_vec::<$t>(bytes))
.map_err(|err| CodecError::Other(err.to_string()))
};
Expand Down Expand Up @@ -211,9 +211,28 @@ impl ArrayToBytesCodecTraits for PcodecCodec {

fn compute_encoded_size(
&self,
_decoded_representation: &ChunkRepresentation,
decoded_representation: &ChunkRepresentation,
) -> Result<BytesRepresentation, CodecError> {
// FIXME: pcodec is likely bounded, but it doesn't have a nice API to figure out what the bounded size is
Ok(BytesRepresentation::UnboundedSize)
let data_type = decoded_representation.data_type();
let mut num_elements = decoded_representation.num_elements_usize();
if data_type == &DataType::Complex64 || data_type == &DataType::Complex128 {
num_elements *= 2;
}

let size = match data_type {
DataType::UInt32 | DataType::Int32 | DataType::Float32 | DataType::Complex64 => Ok(
file_size::<u32>(num_elements, &self.chunk_config.paging_spec)
.map_err(|err| CodecError::from(err.to_string()))?,
),
DataType::UInt64 | DataType::Int64 | DataType::Float64 | DataType::Complex128 => Ok(
file_size::<u64>(num_elements, &self.chunk_config.paging_spec)
.map_err(|err| CodecError::from(err.to_string()))?,
),
_ => Err(CodecError::UnsupportedDataType(
data_type.clone(),
IDENTIFIER.to_string(),
)),
}?;
Ok(BytesRepresentation::BoundedSize(size.try_into().unwrap()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ fn do_partial_decode(
Some(decoded_value) => {
macro_rules! pcodec_partial_decode {
( $t:ty ) => {
let decoded_chunk = pco::standalone::auto_decompress(decoded_value.as_slice())
.map(|bytes| crate::array::transmute_to_bytes_vec::<$t>(bytes))
.map_err(|err| CodecError::Other(err.to_string()))?;
let decoded_chunk =
pco::standalone::simple_decompress(decoded_value.as_slice())
.map(|bytes| crate::array::transmute_to_bytes_vec::<$t>(bytes))
.map_err(|err| CodecError::Other(err.to_string()))?;
for array_subset in decoded_regions {
let bytes_subset = array_subset
.extract_bytes(
Expand Down
Loading