where
theta = (recip norms) NP.* (v1 `dot` v2)
norms = (norm v1) NP.* (norm v2)
+
+
+
+-- | Given a square @matrix@, return a new matrix of the same size
+-- containing only the on-diagonal entries of @matrix@. The
+-- off-diagonal entries are set to zero.
+--
+-- Examples:
+--
+-- >>> let m = fromList [[1,2,3],[4,5,6],[7,8,9]] :: Mat3 Int
+-- >>> diagonal m
+-- ((1,0,0),(0,5,0),(0,0,9))
+--
+diagonal :: (Arity m, Ring.C a)
+ => Mat m m a
+ -> Mat m m a
+diagonal matrix =
+ construct lambda
+ where
+ lambda i j = if i == j then matrix !!! (i,j) else 0