Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matrix literals or const constructors #1359

Open
GummyGun opened this issue Feb 4, 2024 · 1 comment
Open

matrix literals or const constructors #1359

GummyGun opened this issue Feb 4, 2024 · 1 comment

Comments

@GummyGun
Copy link

GummyGun commented Feb 4, 2024

is there any reason that there are no constant constructors for types like all matrixes or even for just for some common ones like identity.
And on that same point, Is it posible to get a literal for a Matrix/Vector

@tpdickso
Copy link
Collaborator

Can you elaborate on what you mean by "types like all matrixes"? Owned matrices of constant size appear to expose const constructors for sizes up to 6x6. Not every matrix can be initialized in a const context because their data may not be const; for example, you can't have a dynamic matrix in a const, because its storage is a Vec, which would require a dynamic allocation.

I suspect the issue with making identity const is that it's a generic function over the scalar field; it invokes Zero::zero and One::one to populate the relevant entries of the matrix. Without a stable way to parameterize over specifically-const implementations of these trait functions I don't think it's possible to produce the relevant const? annotation on identity. Something like from_diagonal but that allows specifying both the on-diagonal and off-diagonal entries would be possible, but currently you can explicitly write new(1.0, 0.0, 0.0, 1.0) to get a const identity matrix.

I don't believe Rust has custom literals at all, but you can get a similar effect using the matrix! macro. It invokes new and so should be usable in a const context when invoking a const new. So you should also be able to write matrix![1.0, 0.0; 0.0, 1.0] to produce a 2x2 identity matrix.

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

No branches or pull requests

2 participants