You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you do something like this, the types change when they really shouldn't:
x <- 1:5
rray_abs(x) # using xtensor::abs()
x is an "integer" and the result of rray_abs(x) is an "array" class holding an integer. These behave slightly differently, and it is enough that I think it would be nice if we could return an "integer" for this kind of thing.
If the shape.size() > 0 we currently always create an R "array".
I want something sort of like this. If it sees that shape.size() == 1, then it knows it can just make an R vector instead, using Rf_allocVector(). The thing that doesn't work here is that if you start with an "array" that is 1D like array(1:5) and then do rray_abs(array(1:5)), it will return an "integer" (because shape.size() == 1), rather than an array.
I think we need to record if the SEXP is an "array" at creation, checking with Rf_isArray() which looks for a "dim" attribute, and then the condition can be:
I don't know quite enough about where I'd add that boolean flag of whether or not it was originally an array, and where I'd have to update it in the constructors and so on. Some help there would be great, and then I could attempt a PR if you are okay with this idea.
I would also love a pointer on how to coerce shape into an integer more gracefully than what I am doing here. Rf_allocVector() takes an R_xlen_t for its second argument, and that can be just an int, so if you could tell me how to go from shape of size 1 -> int that would be great.
The text was updated successfully, but these errors were encountered:
When you do something like this, the types change when they really shouldn't:
x
is an"integer"
and the result ofrray_abs(x)
is an"array"
class holding an integer. These behave slightly differently, and it is enough that I think it would be nice if we could return an"integer"
for this kind of thing.After some searching, I learned that this happens because of this line in
init_from_shape()
:https://github.com/QuantStack/xtensor-r/blob/9c13372e72b76792fa3abead8a7546a8d0cbc9ca/include/xtensor-r/rarray.hpp#L189
If the
shape.size() > 0
we currently always create an R"array"
.I want something sort of like this. If it sees that
shape.size() == 1
, then it knows it can just make an R vector instead, usingRf_allocVector()
. The thing that doesn't work here is that if you start with an"array"
that is 1D likearray(1:5)
and then dorray_abs(array(1:5))
, it will return an"integer"
(becauseshape.size() == 1
), rather than an array.I think we need to record if the SEXP is an
"array"
at creation, checking withRf_isArray()
which looks for a"dim"
attribute, and then the condition can be:I don't know quite enough about where I'd add that boolean flag of whether or not it was originally an array, and where I'd have to update it in the constructors and so on. Some help there would be great, and then I could attempt a PR if you are okay with this idea.
I would also love a pointer on how to coerce
shape
into an integer more gracefully than what I am doing here.Rf_allocVector()
takes anR_xlen_t
for its second argument, and that can be just anint
, so if you could tell me how to go fromshape of size 1
->int
that would be great.The text was updated successfully, but these errors were encountered: