Skip to content

Add Linear System Operators to Bonsai.ML.Torch#83

Open
ncguilbeault wants to merge 10 commits intobonsai-rx:mainfrom
ncguilbeault:dev/torch-linalg-additions
Open

Add Linear System Operators to Bonsai.ML.Torch#83
ncguilbeault wants to merge 10 commits intobonsai-rx:mainfrom
ncguilbeault:dev/torch-linalg-additions

Conversation

@ncguilbeault
Copy link
Copy Markdown
Collaborator

This PR adds several new operators to the Bonsai.ML.Torch package for doing operations on linear systems. This includes operators for solving systems with least squares, SVD, multiple matrix multiplications, computing rank, etc.

@glopesdev glopesdev changed the title Addition of Linear System Operaters in Bonsai.ML.Torch Add Linear System Operators to Bonsai.ML.Torch Mar 12, 2026
@glopesdev glopesdev self-requested a review March 12, 2026 07:25
@glopesdev glopesdev changed the title Add Linear System Operators to Bonsai.ML.Torch Add Linear System Operators to Bonsai.ML.Torch Mar 12, 2026
Copy link
Copy Markdown
Member

@glopesdev glopesdev left a comment

Choose a reason for hiding this comment

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

Mostly minor naming and organization comments, otherwise looks great.

[Combinator]
[Description("Computes the solution to the least squares and least norm problems for a full rank matrix A of size m*n and a matrix B of size m*k.")]
[WorkflowElementCategory(ElementCategory.Transform)]
public class LeastSquaresSolve
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public class LeastSquaresSolve
public class LeastSquares

It feels off to have the verb at the end. I would either move it to the beginning, i.e. SolveLeastSquares, or follow the linalg convention and drop it, i.e. just call this operator LeastSquares.

/// Represents the result of a QR decomposition.
/// </summary>
/// <param name="result"></param>
public readonly struct QRDecompositionResult((Tensor Q, Tensor R) result)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would move this struct declaration outside the class. That way it would make it easier to manipulate in workflows, visualizers, etc.

However, if it really makes sense to have a nested class, we should remove the QRDecomposition prefix, since its name would be effectively coupled to the name of the container class.

/// Represents the result of computing the sign and natural logarithm of the absolute value of the determinant.
/// </summary>
/// <param name="result"></param>
public readonly struct SignLogDeterminantResult((Tensor sign, Tensor logabsdet) result)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as above on nested struct classes.

[Combinator]
[Description("Computes the solution to a triangular system of linear equations with a unique solution.")]
[WorkflowElementCategory(ElementCategory.Transform)]
public class TriangularSolve
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public class TriangularSolve
public class SolveTriangular

I guess now I start to understand where the Solve prefix come from. It looks like linalg itself is not consistent on terminology, but I would still follow their lead for consistency, and rename this class to SolveTriangular.

@glopesdev glopesdev added this to the v0.5.0 milestone Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants