单precision阵列deepSeqArray [英] deepSeqArray of a single precision array

查看:191
本文介绍了单precision阵列deepSeqArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 getVectorFloat 函数创建浮动元素的矢量。
为了使一些测量,我需要使用 deepSeqArray
不过,我不设法做到这一点。

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.

下面是我的例子:

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

和错误,我得到:

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 () }

我不明白为什么阵列SH0 A0 不能匹配阵列DIM1浮动

感谢您的帮助。

推荐答案

该problemo来了,从不会做你认为该做的。
当你做 WS&LT; - getVectorFloat LEN

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

WS未设置与阵列,但呼吁它的每个值。即对数组做记号,类似于地图。请看下面的例子

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.

这篇关于单precision阵列deepSeqArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆