Mi piacerebbe manipolare le matrici (complete o sparse) in modo efficiente con la libreria vettoriale di haskell.matrici unboxing, (sparse) e libreria vettoriale haskell
Qui è un tipo di matrice
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
Come si può vedere, la matrice è un vettore di vettori senza custodia. Ora, vorrei fare un prodotto punto tra un vettore e una matrice. È abbastanza semplice combinare una somma, una zip e una mappa.
Ma se lo faccio, perché sto mappando attraverso le righe della matrice, il risultato è un vettore in scatola, anche se potrebbe essere unboxed.
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)
Come posso ottenere un vettore unboxed come risultato in modo efficiente?
qual è il defn di Field? –