DiamondLightSource / DiamondLightSource/fastcs-catio

Optimize average() function and improve async exception handling

Open
#22 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Location
[src/fastcs_catio/utils.py](src/fastcs_catio/utils.py) - `average()` function (lines 107-110)

## Current Implementation
The `average()` function iterates over each field in a numpy structured array and computes the mean individually:

```python
mean_array = np.empty(1, dtype=array.dtype)
for field in array.dtype.fields:
mean_array[field] = np.mean(array[field])
return mean_array
```

## Suggested Improvements

### 1. Vectorize the averaging operation
The current loop-based approach could be replaced with a single numpy call to improve performance. Consider using `numpy.mean()` with structured array views or `np.lib.recfunctions` utilities.

### 2. Async exception reporting
Investigate and implement proper exception reporting for async tasks that use this function. Currently, exceptions may be silently swallowed.

## References
See TODO comments at lines 108-109 in utils.py

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.