'Is there a Julia way to split a vector function without evaluting the whole vector
Say, we have a function f
which returns a vector of known size n
with n>1.
Is it possible to access f(x)[1]
without computing f(x)
as a whole?
Solution 1:[1]
There is not unless the vector returned by f
is a lazy data structure—standard arrays contain already-computed values. If you want to return a lazy data structure, you can look at MappedArrays
. If you don't want to return a lazy data structure, then you could refactor f
to take an index to compute, so you would call it as f(x, 1)
instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | StefanKarpinski |