Skip to content

Commit

Permalink
dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Mar 11, 2014
1 parent ad35e0f commit 3cbab1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Diagrams/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Diagrams.Core

-- ** Utilities
, basis
, dimension
, determinant

-- ** Invertible linear transformations
Expand Down
10 changes: 7 additions & 3 deletions src/Diagrams/Core/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Diagrams.Core.Transform
, papply
, fromLinear
, basis
, dimension
, onBasis
, matrixRep
, determinant
Expand Down Expand Up @@ -197,6 +198,10 @@ basis :: forall v. HasLinearMap v => [v]
basis = map basisValue b
where b = map fst (decompose (zeroV :: v))

-- | Get the dimension of a Transformation
dimension :: forall v. HasLinearMap v => Transformation v -> Int
dimension _ = length (decompose (zeroV :: v))

This comment has been minimized.

Copy link
@jeffreyrosenbluth

jeffreyrosenbluth Mar 11, 2014

Author Member

Is there a way to write a function that just gives the dimension of the vector space it lives in.
something like

dimension :: forall v. HasLinearMap v => Int
dimension  = length (decompose (zeroV :: v))
-- | Get the matrix equivalent of the linear transform,
-- (as a list of columns) and the translation vector. This
-- is mostly useful for implementing backends.
Expand Down Expand Up @@ -243,9 +248,8 @@ determinant t = det . matrixRep $ t
-- avgScale (t1 <> t2) == avgScale t1 * avgScale t2
-- @
--
avgScale :: (HasLinearMap v, Scalar v ~ Double) => Transformation v -> Double
avgScale t = (abs . det $ m) ** (1 / fromIntegral (length m))
where m = matrixRep t
avgScale :: (HasLinearMap v, Floating (Scalar v)) => Transformation v -> Scalar v
avgScale t = (abs . determinant $ t) ** (1 / fromIntegral (dimension t))

{-
Expand Down

0 comments on commit 3cbab1f

Please sign in to comment.