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

Consider requiring that Scalar: Default #1054

Open
Andlon opened this issue Dec 30, 2021 · 1 comment
Open

Consider requiring that Scalar: Default #1054

Andlon opened this issue Dec 30, 2021 · 1 comment

Comments

@Andlon
Copy link
Collaborator

Andlon commented Dec 30, 2021

In many cases, we might want to allocate a buffer that we fill with data. One way to do that might be to use an uninitialized buffer - but this severely complicates the code, as we'll have to deal with complex unsafe reasoning. Therefore it's often preferable to fill the buffer with arbitrary values that will anyway be overwritten, since this can be done safely.

The canonical way to get such an arbitrary way is arguably T: Default. However, when writing generic code with nalgebra we often only want to require T: Scalar. In particular, if we require e.g. T: Scalar + Default then we can not call this method from a method that only has T: Scalar. This is a pretty big problem for composability.

I therefore suggest that we modify the Scalar trait to require Default. This seems like a sane choice: all integer and floating point types implement Default, and there is no reason that arbitrary precision types or big integers from external crates can not implement Default as well.

@Andlon
Copy link
Collaborator Author

Andlon commented Nov 19, 2022

I wanted to follow up on this because it is frequently an annoyance. However, making Scalar: Default means that simba would also need some updates to traits such as SimdComplexField. The reason is that since Scalar resides in nalgebra, simba-based traits are only Scalar through the blanket impl, which means that all corresponding simba traits also need to be updated with Default bounds. I think this is a good idea though, since the arguments made in the original issue still applies. It is definitely a breaking change though (although unlikely to break much code).

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

1 participant