Skip to content

Clearer handling of sparse vs dense data in broaden() method #56

@ajjackson

Description

@ajjackson

Currently the broaden() method takes:

  • points as a 2D array of (ω), (ω,Q) or (ω, q) samples
  • data as a corresponding 1D array of intensities
  • *meshes as a sequence of 1-D arrays specifying the mesh points for output

and returns an N-D array of broadened weighted data on the axes specified by *meshes.

So the input can be "sparse" consisting of positions of a few points, but the output is always "dense" consisting of a full N-D array.

However in many use-cases the input data is also dense. Once we go beyond 1-D, the points format is not a very efficient representation; it would be better to use something like *meshes. And the 1-D data may be awkward to construct; the natural layout would be the same as the return value.

Some broadening implementations are better suited to sparse or dense data.

In a discussion with @oerc0122 we concluded that it might be reasonable to have a common broaden() entry-point that dispatches to broaden_sparse() and broaden_dense() methods. In many implementations one of these would call the other; this is fine. The natural way to dispatch was by having points be an array (following current convention) or a tuple of arrays (specifying axes of N-D data).

But on further examination these would be highly redundant with the *meshes argument. I don't think we particularly need to allow the dense input and output arrays to be different sizes? It certainly simplifies implementation if we can guarantee the axes are the same.

So maybe we make points optional and the signatures are:

# sparse data
def broaden(self,
    data: Float[np.ndarray, 'data'],
    *meshes: Float[np.ndarray, 'mesh'],
    points: Float[np.ndarray, 'sample dimension'],
) -> Float[np.ndarray, '*meshed_data']:
    ...

# dense data
def broaden(self,
    data: Float[np.ndarray, '*meshed_data'],
    *meshes: Float[np.ndarray, 'mesh'],
    points: None,
) -> Float[np.ndarray, '*meshed_data']:
    ...

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