scalar :: a -> Mat1 a
scalar x = Mat (mk1 (mk1 x))
-dot :: (RealRing.C a, m ~ S t, Arity t)
- => Col m a
- -> Col m a
+-- Get the scalar value out of a 1x1 matrix.
+unscalar :: Mat1 a -> a
+unscalar (Mat rows) = V.head $ V.head rows
+
+
+dot :: (Ring.C a, Arity m)
+ => Col (S m) a
+ -> Col (S m) a
-> a
-v1 `dot` v2 = ((transpose v1) * v2) !!! (0, 0)
+v1 `dot` v2 = unscalar $ ((transpose v1) * v2)
-- | The angle between @v1@ and @v2@ in Euclidean space.
reverse2 (Mat rows) = Mat $ V.reverse $ V.map V.reverse rows
+-- | Unsafely set the (i,j) element of the given matrix.
+--
+-- Examples:
+--
+-- >>> let m = fromList [[1,2,3],[4,5,6],[7,8,9]] :: Mat3 Int
+-- >>> set_idx m (1,1) 17
+-- ((1,2,3),(4,17,6),(7,8,9))
+--
+set_idx :: forall m n a.
+ (Arity m, Arity n)
+ => Mat m n a
+ -> (Int, Int)
+ -> a
+ -> Mat m n a
+set_idx matrix (i,j) newval =
+ imap2 updater matrix
+ where
+ updater :: Int -> Int -> a -> a
+ updater k l existing =
+ if k == i && l == j
+ then newval
+ else existing