Skip to content

Commit

Permalink
Unify codec options
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Feb 18, 2024
1 parent 2b317e3 commit e9388ad
Show file tree
Hide file tree
Showing 39 changed files with 391 additions and 515 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add store lock tests
- Added `contiguous_elements` method to `ContiguousIndicesIterator` and `ContiguousLinearisedIndicesIterator`
- Added `ChunkShape::num_elements`
- Added `codec::{Encode,Decode,PartialDecode,PartialDecoder}Options{Builder}`
- Added `codec::CodecOptions{Builder}`
- Added new `Array::opt` methods which can use new encode/decode options
- **Breaking** Existing `Array` `_opt` use new encode/decode options insted of `parallel: bool`
- Implement `DoubleEndedIterator` for `{Indices,LinearisedIndices,ContiguousIndices,ContiguousLinearisedIndicesIterator}Iterator`
Expand Down
70 changes: 35 additions & 35 deletions src/array/array_async_readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{

use super::{
codec::{
ArrayCodecTraits, ArrayToBytesCodecTraits, AsyncArrayPartialDecoderTraits,
AsyncStoragePartialDecoder, DecodeOptions, PartialDecoderOptions,
options::CodecOptions, ArrayCodecTraits, ArrayToBytesCodecTraits,
AsyncArrayPartialDecoderTraits, AsyncStoragePartialDecoder,
},
transmute_from_bytes_vec,
unsafe_cell_slice::UnsafeCellSlice,
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunk_if_exists_opt(
&self,
chunk_indices: &[u64],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Option<Vec<u8>>, ArrayError> {
let storage_handle = Arc::new(StorageHandle::new(self.storage.clone()));
let storage_transformer = self
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
) -> Result<Option<Vec<u8>>, ArrayError> {
self.async_retrieve_chunk_if_exists_opt(chunk_indices, &DecodeOptions::default())
self.async_retrieve_chunk_if_exists_opt(chunk_indices, &CodecOptions::default())
.await
}

Expand All @@ -111,7 +111,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunk_opt(
&self,
chunk_indices: &[u64],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<u8>, ArrayError> {
let chunk = self
.async_retrieve_chunk_if_exists_opt(chunk_indices, options)
Expand All @@ -128,7 +128,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
/// Read and decode the chunk at `chunk_indices` into its bytes or the fill value if it does not exist (default options).
#[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)]
pub async fn async_retrieve_chunk(&self, chunk_indices: &[u64]) -> Result<Vec<u8>, ArrayError> {
self.async_retrieve_chunk_opt(chunk_indices, &DecodeOptions::default())
self.async_retrieve_chunk_opt(chunk_indices, &CodecOptions::default())
.await
}

Expand All @@ -144,7 +144,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunk_elements_if_exists_opt<T: bytemuck::Pod + Send + Sync>(
&self,
chunk_indices: &[u64],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Option<Vec<T>>, ArrayError> {
validate_element_size::<T>(self.data_type())?;
let bytes = self
Expand All @@ -159,7 +159,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
) -> Result<Option<Vec<T>>, ArrayError> {
self.async_retrieve_chunk_elements_if_exists_opt(chunk_indices, &DecodeOptions::default())
self.async_retrieve_chunk_elements_if_exists_opt(chunk_indices, &CodecOptions::default())
.await
}

Expand All @@ -175,7 +175,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunk_elements_opt<T: bytemuck::Pod + Send + Sync>(
&self,
chunk_indices: &[u64],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<T>, ArrayError> {
validate_element_size::<T>(self.data_type())?;
let bytes = self
Expand All @@ -190,7 +190,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
) -> Result<Vec<T>, ArrayError> {
self.async_retrieve_chunk_elements_opt(chunk_indices, &DecodeOptions::default())
self.async_retrieve_chunk_elements_opt(chunk_indices, &CodecOptions::default())
.await
}

Expand All @@ -210,7 +210,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunk_ndarray_if_exists_opt<T: bytemuck::Pod + Send + Sync>(
&self,
chunk_indices: &[u64],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Option<ndarray::ArrayD<T>>, ArrayError> {
// validate_element_size::<T>(self.data_type())?; in // async_retrieve_chunk_elements_if_exists
let shape = self
Expand All @@ -234,7 +234,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
) -> Result<Option<ndarray::ArrayD<T>>, ArrayError> {
self.async_retrieve_chunk_ndarray_if_exists_opt(chunk_indices, &DecodeOptions::default())
self.async_retrieve_chunk_ndarray_if_exists_opt(chunk_indices, &CodecOptions::default())
.await
}

Expand All @@ -254,7 +254,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunk_ndarray_opt<T: bytemuck::Pod + Send + Sync>(
&self,
chunk_indices: &[u64],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<ndarray::ArrayD<T>, ArrayError> {
// validate_element_size::<T>(self.data_type())?; // in async_retrieve_chunk_elements
let shape = self
Expand All @@ -274,7 +274,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
) -> Result<ndarray::ArrayD<T>, ArrayError> {
self.async_retrieve_chunk_ndarray_opt(chunk_indices, &DecodeOptions::default())
self.async_retrieve_chunk_ndarray_opt(chunk_indices, &CodecOptions::default())
.await
}

Expand All @@ -291,7 +291,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunks_opt(
&self,
chunks: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<u8>, ArrayError> {
if chunks.dimensionality() != self.dimensionality() {
return Err(ArrayError::InvalidArraySubset(
Expand Down Expand Up @@ -349,7 +349,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
/// Read and decode the chunk at `chunk_indices` into its bytes (default options).
#[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)]
pub async fn async_retrieve_chunks(&self, chunks: &ArraySubset) -> Result<Vec<u8>, ArrayError> {
self.async_retrieve_chunks_opt(chunks, &DecodeOptions::default())
self.async_retrieve_chunks_opt(chunks, &CodecOptions::default())
.await
}

Expand All @@ -360,7 +360,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunks_elements_opt<T: bytemuck::Pod + Send + Sync>(
&self,
chunks: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<T>, ArrayError> {
validate_element_size::<T>(self.data_type())?;
let bytes = self.async_retrieve_chunks_opt(chunks, options).await?;
Expand All @@ -375,7 +375,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunks: &ArraySubset,
) -> Result<Vec<T>, ArrayError> {
self.async_retrieve_chunks_elements_opt(chunks, &DecodeOptions::default())
self.async_retrieve_chunks_elements_opt(chunks, &CodecOptions::default())
.await
}

Expand All @@ -387,7 +387,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_chunks_ndarray_opt<T: bytemuck::Pod + Send + Sync>(
&self,
chunks: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<ndarray::ArrayD<T>, ArrayError> {
validate_element_size::<T>(self.data_type())?;
let array_subset = self.chunks_subset(chunks)?;
Expand All @@ -404,7 +404,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunks: &ArraySubset,
) -> Result<ndarray::ArrayD<T>, ArrayError> {
self.async_retrieve_chunks_ndarray_opt(chunks, &DecodeOptions::default())
self.async_retrieve_chunks_ndarray_opt(chunks, &CodecOptions::default())
.await
}

Expand All @@ -413,7 +413,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
chunk_indices: &[u64],
array_subset: &ArraySubset,
output: &mut [u8],
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<(), ArrayError> {
// Get the subset of the array corresponding to the chunk
let chunk_subset_in_array = unsafe {
Expand Down Expand Up @@ -474,7 +474,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_array_subset_opt(
&self,
array_subset: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<u8>, ArrayError> {
if array_subset.dimensionality() != self.dimensionality() {
return Err(ArrayError::InvalidArraySubset(
Expand Down Expand Up @@ -647,7 +647,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
array_subset: &ArraySubset,
) -> Result<Vec<u8>, ArrayError> {
self.async_retrieve_array_subset_opt(array_subset, &DecodeOptions::default())
self.async_retrieve_array_subset_opt(array_subset, &CodecOptions::default())
.await
}

Expand All @@ -663,7 +663,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_array_subset_elements_opt<T: bytemuck::Pod + Send + Sync>(
&self,
array_subset: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<T>, ArrayError> {
validate_element_size::<T>(self.data_type())?;
let bytes = self
Expand All @@ -678,7 +678,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
array_subset: &ArraySubset,
) -> Result<Vec<T>, ArrayError> {
self.async_retrieve_array_subset_elements_opt(array_subset, &DecodeOptions::default())
self.async_retrieve_array_subset_elements_opt(array_subset, &CodecOptions::default())
.await
}

Expand All @@ -696,7 +696,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_retrieve_array_subset_ndarray_opt<T: bytemuck::Pod + Send + Sync>(
&self,
array_subset: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<ndarray::ArrayD<T>, ArrayError> {
// validate_element_size::<T>(self.data_type())?; // in async_retrieve_array_subset_elements
let elements = self
Expand All @@ -712,7 +712,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
array_subset: &ArraySubset,
) -> Result<ndarray::ArrayD<T>, ArrayError> {
self.async_retrieve_array_subset_ndarray_opt(array_subset, &DecodeOptions::default())
self.async_retrieve_array_subset_ndarray_opt(array_subset, &CodecOptions::default())
.await
}

Expand All @@ -731,7 +731,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
chunk_subset: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<u8>, ArrayError> {
let chunk_representation = self.chunk_array_representation(chunk_indices)?;
if !chunk_subset.inbounds(&chunk_representation.shape_u64()) {
Expand Down Expand Up @@ -777,7 +777,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
chunk_indices: &[u64],
chunk_subset: &ArraySubset,
) -> Result<Vec<u8>, ArrayError> {
self.async_retrieve_chunk_subset_opt(chunk_indices, chunk_subset, &DecodeOptions::default())
self.async_retrieve_chunk_subset_opt(chunk_indices, chunk_subset, &CodecOptions::default())
.await
}

Expand All @@ -793,7 +793,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
chunk_subset: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<Vec<T>, ArrayError> {
validate_element_size::<T>(self.data_type())?;
let bytes = self
Expand All @@ -812,7 +812,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
self.async_retrieve_chunk_subset_elements_opt(
chunk_indices,
chunk_subset,
&DecodeOptions::default(),
&CodecOptions::default(),
)
.await
}
Expand All @@ -833,7 +833,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&self,
chunk_indices: &[u64],
chunk_subset: &ArraySubset,
options: &DecodeOptions,
options: &CodecOptions,
) -> Result<ndarray::ArrayD<T>, ArrayError> {
// validate_element_size::<T>(self.data_type())?; // in async_retrieve_chunk_subset_elements
let elements = self
Expand All @@ -853,7 +853,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
self.async_retrieve_chunk_subset_ndarray_opt(
chunk_indices,
chunk_subset,
&DecodeOptions::default(),
&CodecOptions::default(),
)
.await
}
Expand All @@ -865,7 +865,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
pub async fn async_partial_decoder_opt<'a>(
&'a self,
chunk_indices: &[u64],
options: &PartialDecoderOptions,
options: &CodecOptions,
) -> Result<Box<dyn AsyncArrayPartialDecoderTraits + 'a>, ArrayError> {
let storage_handle = Arc::new(StorageHandle::new(self.storage.clone()));
let storage_transformer = self
Expand All @@ -890,7 +890,7 @@ impl<TStorage: ?Sized + AsyncReadableStorageTraits + 'static> Array<TStorage> {
&'a self,
chunk_indices: &[u64],
) -> Result<Box<dyn AsyncArrayPartialDecoderTraits + 'a>, ArrayError> {
self.async_partial_decoder_opt(chunk_indices, &PartialDecoderOptions::default())
self.async_partial_decoder_opt(chunk_indices, &CodecOptions::default())
.await
}
}
Loading

0 comments on commit e9388ad

Please sign in to comment.