How can I replicate matrix in Haskell Accelerate?
For example, I have a matrix mat :: Matrix (Z :. 2 :. 5) ...
. I want to get a three-dimensional array with shape Z :. 9 :. 2 :. 5
.
I tried to use A.replicate (A.lift (Z :. 9 :. All)) mat
, but I get an error
Couldn't match type ‘Z’ with ‘DIM0 :. Int’ Expected type: Acc (Array (SliceShape ((Z :. Int) :. All)) a) Actual type: Acc (Matrix a)
What does that mean?
And similarly, if I have a matrix with shape Z :. 9 :. 5
, how can I get a three-dimensional array with shape Z :. 9 :. 2 :. 5
?
The problem is that the slice needs to have the same rank (number of dimensions) as the input array. All
does not mean 'all the rest of the dimensions', but it only means 'all the elements in this dimension'. So you can solve your issue with:
A.replicate (A.lift (Z :. 9 :. All :. All)) mat
This also gives some intuition about how you might answer your second question:
A.replicate (A.lift (Z :. All :. 2 :. All)) mat
I don't know if there is a way to say 'all the rest of the dimensions'.
The error message Couldn't match type 'Z' with 'DIM0 :. Int'
means that the rank of your shape is not correct. You need to add another dimension. Maybe it would be easier to read if it said: Couldn't match type 'Z' with 'Z :. Int'
.