-
Notifications
You must be signed in to change notification settings - Fork 9
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
Create compatibility between vectors and matrices #39
base: master
Are you sure you want to change the base?
Conversation
Vectors are now children of matrices, so they share the same set of properties. This hierarchy change allows the deletions of some duplicate code that was shared among the two classes. Some algorithms have been rewritten to accept both vectors and matrices.
Thanks for the PR! Sorry I took so long to get to this, I've been pretty busy lately. I like the direction this is going. @drubinstein had an idea though, why not go one step further with |
Thank you for this answer ! |
With the parameter pack the dimensions are still constants, so I think so. |
I may be missing something, but I was wondering about the creation of the array. |
Yeah, I'll have to think about that one more. I'm pretty sure it's possible, but not obvious to me either at the moment. I think it's probably possible with a recursive template. |
This works: #include <cstdint>
template <typename T, std::size_t... Dimension>
struct data_impl;
template <typename T, std::size_t... Dimension>
using data_impl_t = typename data_impl<T, Dimension...>::type;
template <typename T>
struct data_impl<T> {
using type = T;
};
template <typename T, std::size_t First, std::size_t... Dimension>
struct data_impl<T, First, Dimension...> {
using type = data_impl_t<T, Dimension...>[First];
};
constexpr data_impl_t<int, 2, 3, 1> d {{{0}, {1}, {2}}, {{3}, {4}, {5}}}; // same as int[2][3][1] |
Woww ! It's truly impressive ! As another way to tackle this problem, isn't it possible to flatten the array ? With your example, the element 4 (in position If this solution work, wouldn't it be simpler ? |
That is possible, but the problem is that makes initialization frustrating--you need to also initialize it in one giant array. Using a multidimensional array is more ergonomic, I think. |
Definitely agreeing for a simple initialization. |
I'm pretty sure most of the current operations can be ported over pretty easily if the new
Was talking with @calebzulawski and we're thinking about keeping the scala, vector, 2D matrix specializations for now but rewrite them with |
Vectors are now children of matrices, so they share the same set of properties.
This hierarchy change allows the deletions of some duplicate code that was
shared among the two classes.
Some algorithms have been rewritten to accept both vectors and matrices.
However, there is a regression, you now need to be explicit about both
dimensions of the matrix when using iota().