小编jiy*_*ori的帖子

拆箱,(稀疏)矩阵和haskell矢量库

我想用haskell的向量库有效地操纵矩阵(完整或稀疏).

这是一种矩阵类型

import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V

data Link a = Full (V.Vector (U.Vector a))
    | Sparse (V.Vector (U.Vector (Int,a)))

type Vector a = U.Vector a
Run Code Online (Sandbox Code Playgroud)

如您所见,矩阵是未装箱矢量的矢量.现在,我想在矢量和矩阵之间做一个点积.通过组合sum,zip和map可以非常简单.

但是,如果我这样做,因为我正在映射矩阵的行,结果是一个盒装矢量,即使它可以是未装箱的.

propagateS output (Field src) (Full weights) = V.map (sum out) weights
    where out     = U.map output src
          sum s w = U.sum $ zipWithFull (*) w s

propagateS output (Field src) (Sparse weights) = V.map (sum out) weights
    where out     = U.map output src
          sum s w …
Run Code Online (Sandbox Code Playgroud)

arrays unboxing haskell vector

8
推荐指数
1
解决办法
1272
查看次数

标签 统计

arrays ×1

haskell ×1

unboxing ×1

vector ×1