Is it possible to compute an array which depends on the past value(s) (i.e., lesser indexes), in Repa? Initial part(s) of the array (e.g., a[0]
) is given. (Note that I am using C-like notation to indicate an element of array; please don't confuse.)
I read the tutorial and quickly check the hackage but I could not find a function to do it.
(I guess doing this kind of computation in 1D array does not make sence in Repa because you can't parallelize it. But I think you can parallelize it in 2 or more dimensional case.)
EDIT:
Probably I should be more specific about what kind of f
I want to use. As there is no way to parallelize in the case a[i]
is a scalar, let's focus on the case a[i]
is a N dim vector. I don't need a[i]
to be higher dimensional (such as matrix) because you can "unroll" it to a vector. So, f
is a function which maps R^N to R^N.
Most of the case, it's like this:
b = M a[i-1]
a[i][j] = g(b)[j]
where b
is a N dim vector, M
is a N by N matrix (no assumption for sparseness), and g
is some nonlinear function. And I want to compute it for i=1,..N-1
given a[0]
, g
and M
. My hope is that there are some generic way to (1) parallelize this type of calculation and (2) make allocation of intermediate variables such as b
efficient (in C-like language, you can just reuse it, it would be nice if Repa or similar library can do it like a magic without breaking purity).
f
, it can be parallelized and it is called a "scan". en.wikipedia.org/wiki/Prefix_sum I couldn't find scan in the Repa documentation, though. – Catholicitya[i] = f(a[i], a[i-1])
. Actually, it's more liketake n $ iterate f z
. – Catholicityf
is multi-dimensional? Also, I am afraid that using infinite list and take generate some kind of overhead comparing C-like language where you can allocate memory before the computation. I am hoping that Repa reduce such kind of overhead comparing to bare Haskell list. – Snowy