Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deepSeqArray of a single precision array

I have a vector of Float elements created by the getVectorFloat function. In order to make some measurements, I need to use deepSeqArray. However, I don't manage to do it.

Here is my example:

import Data.Array.Repa as R
import Data.Array.Repa.Algorithms.Randomish

len :: Int
len = 3000000

main = do
    ws <- getVectorFloat len
    ws `deepSeqArray` return()

getVectorFloat :: Int -> Array DIM1 Float
getVectorFloat len = R.map (toFloat) (getVectorDouble len)

toFloat :: Double -> Float
toFloat a = realToFrac a

getVectorDouble :: Int -> Array DIM1 Double
getVectorDouble len = randomishDoubleArray (Z :. len) (-100) 100 1

And the error I get:

haskell.hs:9:9:
    Couldn't match expected type `Array sh0 a0'
                with actual type `Float'
    In the first argument of `deepSeqArray', namely `ws'
    In the expression: ws `deepSeqArray` return ()
    In the expression:
      do { ws <- getVectorFloat len;
             ws `deepSeqArray` return () }

I don't understand why Array sh0 a0 can't be matched to Array Dim1 Float.

Thank you for your help

like image 374
Wilfried Kirschenmann Avatar asked Dec 09 '25 23:12

Wilfried Kirschenmann


1 Answers

The problemo comes, from the do which doesn't do what you think. When you do ws <- getVectorFloat len

ws is not set with the Array, but called for each value of it. ie the do notation for an array , is similar to a map. Consider the following example

prelude > do x <- [1,2,3]; return (x*10)
[10, 20, 30]

or more fun ;-)

Prelude> do <-[1,2,3];y<-[10,20,30]; return(x,y)                                                                                                                                         
[(1,10),(1,20),(1,30),(2,10),(2,20),(2,30),(3,10),(3,20),(3,30)]   

So I'm not sure your usage of do is appropriate.

like image 61
mb14 Avatar answered Dec 11 '25 22:12

mb14



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!