Reuse For of size and of size , every selected row and column has length . Their dot product isThe two list comprehensions place this entry in row , column of an result. The dimension guard checks exactly the compatibility condition for matrix multiplication. The shared
dimensions and either transpose definition above:multMat :: Num a => Matrix a -> Matrix a -> Matrix a
multMat a b
| colsA /= rowsB = error "multMat: incompatible sizes"
| otherwise = [[sum (zipWith (*) row col) | col <- columnsB]
| row <- a]
where
(_,colsA) = dimensions a
(rowsB,_) = dimensions b
columnsB = transpose bcolumnsB avoids recomputing the transpose for each row; the arithmetic cost is in the unit-cost model. Articles by others on the same topic
There are currently no matching articles.