-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Add AsRef<[T]> and AsMut<[T]> trait implementations #1414
Conversation
Seeing #937 now I'm not entirely sure if I implemented it at the right place, but I'm happy to move it around. |
Signed-off-by: Markus Mayer <[email protected]>
d8fd966
to
057e142
Compare
Hmm. In my personal opinion, I don't think we should "automatically" convert from a matrix to a slice. I think this might be acceptable for vectors, but for matrices the underlying slice representation is not unambiguous. For example, |
Yeah, that's a fair point. It won't solve my problem exactly, but I can provide auto-impls only for vectors. Do you see value in that? Thinking about it, the unsafe impl<T, const R: usize, const C: usize> RawStorage<T, Const<R>, Const<C>>
for ArrayStorage<T, R, C>
{
type RStride = Const<1>;
type CStride = Const<R>; Similarly, the unsafe impl<T, C: Dim> RawStorage<T, Dyn, C> for VecStorage<T, Dyn, C> {
type RStride = U1;
type CStride = Dyn; which also seems to indicate a row-major order by design, if I am reading it correctly. In any case, I could also specialize the |
Are you thinking of |
@sunsided: virtually everything in I'm not sure what you mean by "so |
Yep, just noticed my mistake. Apologies for the confusion! 😅 |
@Ralith: sorry, that was sloppy. What I meant is that if you have something like fn foo<T>(slice: impl AsRef<[T]>) {
...
} then I don't think it would be good if you could just casually pass in a matrix to In my opinion, forcing users to be explicit about how a matrix is mapped to a slice, e.g. using |
Did you mean to close this @sunsided? I think it might be a good idea to implement |
@Andlon That's no bueno sadly. I would have to constrain one dimension to be strictly greater than 1, because If I add an implementation for only one of them it feels weirder than before due to the lack of symmetry. |
This adds
AsRef<[T]>
andAsMut<[T]>
forArrayStorage
,VecStorage
andMatrix
types withIsContiguous
storage implementations.I understand it is a bit of a duplication given the
as_slice
andas_mut_slice
implementations, but I am hoping that given thecore::convert
types, this makes adoption even easier. I stumbled over the lack of these implementations while attempting to implementnalgebra
support in myno_std
-targeted Kalman Filtering library (sunsided/minikalman-rs#13).