-
Notifications
You must be signed in to change notification settings - Fork 50
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
Columns support for matrix class #229
Conversation
The tests are failing because the matrix::row-related API has changed. I will fix the tests once there is a decision how this API should actually look like. |
An alternative interface would be to let the user to supply if they want to use column or row based indexing as part of the matrix constructor, either as a template parameter or an argument. I think generally users only want to iterator over rows or columns, and very rarely do both with the same matrix. If they do want to use both in the same application they could create two matrix objects pointing at the same underlying data. |
@jimhester I've tried to implement your suggestion. Now the It's been a while since I wrote something in C++, I hope I have not overcomplicated these specialization things. If this approach looks good, I can start updating the tests. |
80dfe43
to
a23f116
Compare
@jimhester the tests pass now |
using integers_matrix = matrix<r_vector<int>, int>; | ||
using logicals_matrix = matrix<r_vector<r_bool>, r_bool>; | ||
using strings_matrix = matrix<r_vector<r_string>, r_string>; | ||
template <typename S = by_column> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the default access pattern would need to be by row, as this is what cpp11 currently supplies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change that. I just have thought that cpp11 is in active development and have not reached 1.0.0 yet, so changes like this are still possible. The reason is - column slices have continuous memory layout, so it would be nice to select more efficient alternative by default. And the fact that there were some issues with matrix iterators suggests that so far there are not so many matrix users whose code might be broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, let me ask around and see what people might prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright since R generally does column major ordering by default I think having cpp11 match that makes the most sense. So I think leaving it as you have it now is OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for double-checking.
I've applied some cosmetics and squashed the commits to clean-up the log.
5f14f52
to
e8ac032
Compare
Can you please add a bullet to NEWS? It should briefly describe the change and end with Otherwise I think this looks great, thanks for working on it! |
- add the 3rd template parameter S, which could be either by_row or by_column - matrix::row is replaced by matrix::slice - make matrix::slice::iterator conforming to the iterator concept - separate matrix::slice from matrix::slice_iterator
since it matches the column-major memory layout of R matrices
add tests for by_column slicing
@jimhester done |
This draft PR adds
matrix::column
class in full analogy tomatrix::row
class and updates the matrix API so that both rows and columns could be accessed. I just added it because my use-case required column-wise access.I'm not sure about the proposed matrix API, it was just the easiest to implement.
Alternatively one could think about
matrix::row_vector
proxy class andmatrix::rows()
method that would provide row access (begin/end/[] etc) andmatrix::column_vector
that would provide symmetric columns access.I also added the required types to
matrix::row::iterator
so that it actually conforms to the iterator concept.