Skip to content

Optimize average() function and improve async exception handling #22

@gilesknap

Description

@gilesknap

Location

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions