-
Notifications
You must be signed in to change notification settings - Fork 41
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
Rmatrix docs #466
Rmatrix docs #466
Conversation
I removed the proposed |
@multimeric Hi! What happens here if you call |
Good point. That would surely fail, but possibly on the R side. Maybe I should just make this function fallible and have it return an |
I am not certain that would fail on the R side, unfortunatelly I can't run any tests now. I don't know how other people do, but I only create these extendr types right before returning them to R, so, in the way I use it, I don't expect to run into any trouble before R would detect the problem. |
In relation to "... it encouraged using row-major iterables when we want to discourage this for performance reasons..." perhaps you can indicate in the docs that by row is slower performance. R, numpy, and ndarray support insertion rowwise—i think having a counterpart would be appreciated. Re "...should use ndarray instead": perhaps this is the best answer. If it is the documentation for using ndarray + extendr should be improved. I have not been able to find any, personally. For example I had to write my own conversion function from RMatrix -> Array2. |
Hi @JosiahParry! Would you mind giving examples of those functionalities on ndarray? I was looking through the docs but I don't see how you create a new column major array row by row or a new row major array column by column. I see row major arrays being populated by row or column major array being populated by column. Remember R doesn't support row major matrices. |
@daniellga Again, i'm referring to insertion into a matrix not internal storage. You can insert rowwise into a column major matrix in R. ndarray is row-major so the inverse method is provided using the [ |
Perhaps the |
If we use R's |
My understanding is that |
I must apologise. Since I'm a contributor, I was able to push a commit to your pr. I had hoped it would be suggestions. But it just took it whole sale. |
TODO:
|
Feel free to request a review again when that is done.
I will give it again.
…On Wed, 8 Feb 2023, 23.14 Michael Milton, ***@***.***> wrote:
TODO:
- Convert into arbitrary RArray using collect_array
- Move the trait into RobjItertools instead of using own trait
—
Reply to this email directly, view it on GitHub
<#466 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIDVSFVPXIFKK4VBVY4LPTWWQLFTANCNFSM6AAAAAAUKAHXQQ>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
Suggested edit: diff --git a/extendr-api/src/robj/into_robj.rs b/extendr-api/src/robj/into_robj.rs
index 1d084cb5..bb1fe15c 100644
--- a/extendr-api/src/robj/into_robj.rs
+++ b/extendr-api/src/robj/into_robj.rs
@@ -478,8 +478,8 @@ pub trait RobjItertools: Iterator {
vec.into_iter().collect_robj()
}
- /// Collects an iterable into an RArray.
- /// The iterable must yield items column by column (aka Fortan order)
+ /// Collects an iterable into an `RArray`.
+ /// The iterable must yield items column by column (aka Fortran order)
///
/// # Arguments
///
diff --git a/extendr-api/src/wrapper/matrix.rs b/extendr-api/src/wrapper/matrix.rs
index 92fc4449..95dd6230 100644
--- a/extendr-api/src/wrapper/matrix.rs
+++ b/extendr-api/src/wrapper/matrix.rs
@@ -134,8 +134,8 @@ where
/// * `f` - a function that will be called for each entry of the matrix in order to populate it with values.
/// It must return a scalar value that can be converted to an R scalar, such as `u32`, `f64`, i.e. see [ToVectorValue].
/// It accepts two arguments:
- /// * `r` (usize) - the current row of the entry we are creating
- /// * `c` (usize) - the current column of the entry we are creating
+ /// * `r` - the current row of the entry we are creating
+ /// * `c` - the current column of the entry we are creating
pub fn new_matrix<F: Clone + FnMut(usize, usize) -> T>(
nrows: usize,
ncols: usize,
@@ -148,7 +148,7 @@ where
})
.collect_robj();
let dim = [nrows, ncols];
- let mut robj = robj.set_attrib(wrapper::symbol::dim_symbol(), dim).unwrap();
+ let mut robj = robj.set_attrib(wrapper::symbol::dim_symbol(), dim)?;
let data = robj.as_typed_slice_mut().unwrap().as_mut_ptr();
RArray::from_parts(robj, data, dim)
}
|
Why remove |
Sorry, but cargo docs will result in a very neatly formatted documentation,
that will show the types quite clearly.
So I find it a little cluttering actually..
…On Thu, Feb 9, 2023 at 4:33 PM Josiah Parry ***@***.***> wrote:
Why remove (usize)? I feel like removing that only adds ambiguity. Having
it only helps and doesnt hurt.
—
Reply to this email directly, view it on GitHub
<#466 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIDVSEXZH5E5GBEYNGARJDWWUE3TANCNFSM6AAAAAAUKAHXQQ>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
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.
Approve. You can add my changes if you like.
I can't use this, because
|
Sorry about that. You can use Also I think I think the documentation should follow Rust documentation etiquette, and not some other way... |
|
That's not what I meant. In the docstring the argument name should match the function signature. |
But |
Ah.. The documentation is for the closure. Damn.. Yeah you're absolutely right. |
I don't mind removing the |
RArray::new_matrix()
(closes Document how to create a new matrix #463)CollectRMatrix
trait that can be used to collect arbitrary iterables into an R matrix