-
Notifications
You must be signed in to change notification settings - Fork 5
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
Stricter recycling rules #98
Comments
Maybe one wants to be even stricter, i.e. in a operation A strong argument for being stricter is that the recycling rules for vectors are then more consistent with the recycling rules for n-dimensional arrays. For example, it should also not be possible to multiply two matrices with shapes |
Great catch! I remember thinking about this when implementing the current recycling... and promptly forgetting about it. This style works great for objects that have a known length... which for now should account for all objects. But my goal is that objects eventually are calculated lazily, and possibly even from generators where the length is unknown. All operators are currently set up with this laziness in mind. They are implemented on any representation that implements That said, we can add something that is like... |
One thing that one also has to pay attention to is to make the lazy evaluation work correctly with error handling. In the code below (assuming stricter recycling rules), the multiplication y <- (1:3)[c(TRUE, TRUE, TRUE)]
x <- 1:10
z <- tryCatch(x * y, # this should throw
error = function(e) {
messagef("Catch all them errors")
NA
}
)
stop("wupsie")
mean(z) |
I have started to think about this again and there is another relevant case that is also relevant to error-handling.
The one possible problem from above regarding the Let's say we do something like print(1:3[ [true, true, true] ] + 1:2[ [true, true]]) With the recycling rules that I suggested, this should throw an error, as the lengths of the left and right subsets are 3 and 2.
The whole problem becomes worse if we - instead of printing the final vector - subset the first element as shown below: (1:3[ [true, true, true] ] + 1:2[ [true, true]])[1] instead of printing the first two elements and then throwing an error, this operation will never notice that the addition of the two masked vectors is an invalid operation according to the stricter recycling rules, because it will only yield the first element of the final iterator. So if we want both the stricter recycling rules and usage of |
@dgkf Do you agree that these examples seem to make it necessary to always have a known length? |
Currently, the code below works:
I think this should be stricter and at least throw a warning (but I would probably even tend to an error) when the shorter length does not divide the longer length.
The text was updated successfully, but these errors were encountered: