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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ with a JSON payload of the form:
}
```

The currently supported reducers are `max`, `min`, `mean`, `sum`, `select` and `count`. All reducers return the result using the same datatype as specified in the request except for `count` which always returns the result as `int64`.
The currently supported reducers are `max`, `min`, `sum`, `select` and `count`. All reducers return the result using the same datatype as specified in the request except for `count` which always returns the result as `int64`.

The proxy adds two custom headers `x-activestorage-dtype` and `x-activestrorage-shape` to the HTTP response to allow the numeric result to be reconstructed from the binary content of the response. An additional `x-activestorage-count` header is also returned which contains the number of array elements operated on while performing the requested reduction. This header is useful, for example, to calculate the mean over multiple requests where the number of items operated on may differ between chunks.

Expand Down
1 change: 0 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ fn router() -> Router {
Router::new()
.route("/count", post(operation_handler::<operations::Count>))
.route("/max", post(operation_handler::<operations::Max>))
.route("/mean", post(operation_handler::<operations::Mean>))
.route("/min", post(operation_handler::<operations::Min>))
.route("/select", post(operation_handler::<operations::Select>))
.route("/sum", post(operation_handler::<operations::Sum>))
Expand Down
44 changes: 0 additions & 44 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,6 @@ impl NumOperation for Max {
}
}

/// Return the mean of selected elements in the array.
pub struct Mean {}

impl NumOperation for Mean {
fn execute_t<T: Element>(
request_data: &models::RequestData,
data: &Bytes,
) -> Result<models::Response, ActiveStorageError> {
let array = array::build_array::<T>(request_data, data)?;
let slice_info = array::build_slice_info::<T>(&request_data.selection, array.shape());
let sliced = array.slice(slice_info);
// FIXME: Account for missing data?
let count = i64::try_from(sliced.len())?;
// FIXME: endianness?
let body = sliced
.mean()
.ok_or(ActiveStorageError::EmptyArray { operation: "mean" })?;
let body = body.as_bytes();
// Need to copy to provide ownership to caller.
let body = Bytes::copy_from_slice(body);
Ok(models::Response::new(
body,
request_data.dtype,
vec![],
count,
))
}
}

/// Return the minimum of selected elements in the array.
pub struct Min {}

Expand Down Expand Up @@ -236,21 +207,6 @@ mod tests {
assert_eq!(1, response.count);
}

#[test]
fn mean_u32_1d() {
let mut request_data = test_utils::get_test_request_data();
request_data.dtype = models::DType::Uint32;
let data = [1, 2, 3, 4, 5, 6, 7, 8];
let bytes = Bytes::copy_from_slice(&data);
let response = Mean::execute(&request_data, &bytes).unwrap();
let expected: i32 = (0x08070605 + 0x04030201) / 2;
assert_eq!(expected.as_bytes(), response.body);
assert_eq!(4, response.body.len());
assert_eq!(models::DType::Uint32, response.dtype);
assert_eq!(vec![0; 0], response.shape);
assert_eq!(2, response.count);
}

#[test]
fn min_u64_1d() {
let mut request_data = test_utils::get_test_request_data();
Expand Down