{-# LANGUAGE Unsafe #-}
module Data.Geometry.Matrix.Internal where

import           Control.Lens (set)
import           Data.Geometry.Vector
import qualified Data.Vector.Fixed as FV

--------------------------------------------------------------------------------
-- * Helper functions to easily create matrices

-- | Creates a row with zeroes everywhere, except at position i, where the
-- value is the supplied value.
mkRow     :: forall d r. (Arity d, Num r) => Int -> r -> Vector d r
mkRow :: Int -> r -> Vector d r
mkRow Int
i r
x = ASetter (Vector d r) (Vector d r) r r
-> r -> Vector d r -> Vector d r
forall s t a b. ASetter s t a b -> b -> s -> t
set (Int -> ASetter (Vector d r) (Vector d r) r r
forall (v :: * -> *) a (f :: * -> *).
(Vector v a, Functor f) =>
Int -> (a -> f a) -> v a -> f (v a)
FV.element Int
i) r
x Vector d r
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero