저는 haskell의 벡터 라이브러리로 행렬 (전체 또는 희소)을 효율적으로 조작하고 싶습니다. 여기 unboxing, (희박한) 행렬 및 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
이다. 자, 저는 벡터와 행렬 사이에 내적 (dot product)을 만들고 싶습니다. 합계, 우편 번호 및지도를 결합하여 처리하는 것이 매우 간단합니다.
그러나 행렬의 행을 통해 매핑하기 때문에 상자에 넣을 수는 있지만 결과는 박스형 벡터입니다.
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 = U.sum $ zipWithSparse (*) w s
zipWithFull = U.zipWith
zipWithSparse f x y = U.map f' x
where f' (i,v) = f v (y U.! i)
효율적으로 박스 풀링되지 않은 벡터를 얻으려면 어떻게해야합니까?
Field의 정의는 무엇입니까? –