Skip to content

typing(aggregation): Add structure and none based weightings#655

Draft
ValerianRey wants to merge 3 commits intomainfrom
refactor-linalg-types
Draft

typing(aggregation): Add structure and none based weightings#655
ValerianRey wants to merge 3 commits intomainfrom
refactor-linalg-types

Conversation

@ValerianRey
Copy link
Copy Markdown
Contributor

@ValerianRey ValerianRey commented Apr 17, 2026

Draft for now (I think I broke the documentation, even if it still builds) but I'd like to know your opinion about this @PierreQuinton. Seems a bit more rigorous than what we had before.

This fixes the issue that currently, weightings are bound to operate on tensors (which doesn't really make sense, as they're supposed to operate on some stats which may not be represented as a single tensor).

This also removes the responsibility from ConstantWeighting of checking if the matrix' shape[0] matches the number of weights.

- The idea is to make it explicit that some weightings are based on the structure of the matrix (sum, mean, random) and that some are independent of their input (constant), by separating the part where we extract the structure (or the none for constant) and the part where we use this structure (or the none for constant) to make a vector of weigths.
@ValerianRey ValerianRey added package: aggregation cc: typing Conventional commit type for improvements to typing. labels Apr 17, 2026
@github-actions github-actions bot changed the title Add structure and none based weightings typing(aggregation): Add structure and none based weightings Apr 17, 2026
@github-actions github-actions bot changed the title Add structure and none based weightings typing(aggregation): Add structure and none based weightings Apr 17, 2026
@github-actions github-actions bot changed the title Add structure and none based weightings typing(aggregation): Add structure and none based weightings Apr 17, 2026
@ValerianRey ValerianRey marked this pull request as ready for review April 17, 2026 01:29
@ValerianRey ValerianRey requested review from a team and PierreQuinton as code owners April 17, 2026 01:29
"""Computes the vector of weights from the input stat."""

def __call__(self, stat: Tensor, /) -> Tensor:
def __call__(self, stat: object, /) -> Tensor:
Copy link
Copy Markdown
Contributor Author

@ValerianRey ValerianRey Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. This type should be _T. Before, Tensor was the public equivalent of both Matrix and PSDMatrix, so it worked, but it's quite wrong.

If we do type this as _T, we need Matrix and PSDMatrix to become public, and I think we need users to cast to Matrix and PSDMatrix in order to use call.

Finding a workaround would be huge (this problem + the issue of having a gap between public and private type, solved at once).

@ValerianRey ValerianRey marked this pull request as draft April 17, 2026 01:53
dtype: torch.dtype


def extract_structure(matrix: Matrix) -> Structure:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be not only for Matrices but any non-scalar?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That's my plan for a future PR.

Copy link
Copy Markdown
Contributor

@PierreQuinton PierreQuinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add an abstraction level (e.g. _MeanWeighting)? Can this be avoided?

EDIT: I guess it is for the statistic extraction. I understand it, but it feels a bit heavy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: typing Conventional commit type for improvements to typing. package: aggregation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants