From 1a68793247b8845cefad4d157e4f4d25b1731b42 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Fri, 30 Mar 2018 12:48:20 +0100 Subject: Implement CI --- packages/base/src/Numeric/Matrix.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'packages/base/src/Numeric/Matrix.hs') diff --git a/packages/base/src/Numeric/Matrix.hs b/packages/base/src/Numeric/Matrix.hs index 06da150..6e3db61 100644 --- a/packages/base/src/Numeric/Matrix.hs +++ b/packages/base/src/Numeric/Matrix.hs @@ -4,6 +4,8 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + ----------------------------------------------------------------------------- -- | -- Module : Numeric.Matrix @@ -35,6 +37,7 @@ import Data.List(partition) import qualified Data.Foldable as F import qualified Data.Semigroup as S import Internal.Chain +import Foreign.Storable(Storable) ------------------------------------------------------------------- @@ -80,8 +83,16 @@ instance (Floating a, Container Vector a, Floating (Vector a), Fractional (Matri -------------------------------------------------------------------------------- +isScalar :: Matrix t -> Bool isScalar m = rows m == 1 && cols m == 1 +adaptScalarM :: (Foreign.Storable.Storable t1, Foreign.Storable.Storable t2) + => (t1 -> Matrix t2 -> t) + -> (Matrix t1 -> Matrix t2 -> t) + -> (Matrix t1 -> t2 -> t) + -> Matrix t1 + -> Matrix t2 + -> t adaptScalarM f1 f2 f3 x y | isScalar x = f1 (x @@>(0,0) ) y | isScalar y = f3 x (y @@>(0,0) ) @@ -96,7 +107,7 @@ instance (Container Vector t, Eq t, Num (Vector t), Product t) => M.Monoid (Matr where mempty = 1 mappend = adaptScalarM scale mXm (flip scale) - + mconcat xs = work (partition isScalar xs) where work (ss,[]) = product ss @@ -106,4 +117,3 @@ instance (Container Vector t, Eq t, Num (Vector t), Product t) => M.Monoid (Matr | otherwise = scale x00 m where x00 = x @@> (0,0) - -- cgit v1.2.3