diff options
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed/Internal/Common.hs | 4 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Tensor.hs | 17 |
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/Data/Packed/Internal/Common.hs b/lib/Data/Packed/Internal/Common.hs index acefe92..91985f7 100644 --- a/lib/Data/Packed/Internal/Common.hs +++ b/lib/Data/Packed/Internal/Common.hs | |||
@@ -74,8 +74,8 @@ check msg ls f = do | |||
74 | mapM_ (touchForeignPtr . fptr) ls | 74 | mapM_ (touchForeignPtr . fptr) ls |
75 | return () | 75 | return () |
76 | 76 | ||
77 | class (Storable a, Typeable a) => Field a where | 77 | class (Storable a, Typeable a) => Field a |
78 | instance (Storable a, Typeable a) => Field a where | 78 | instance (Storable a, Typeable a) => Field a |
79 | 79 | ||
80 | isReal w x = typeOf (undefined :: Double) == typeOf (w x) | 80 | isReal w x = typeOf (undefined :: Double) == typeOf (w x) |
81 | isComp w x = typeOf (undefined :: Complex Double) == typeOf (w x) | 81 | isComp w x = typeOf (undefined :: Complex Double) == typeOf (w x) |
diff --git a/lib/Data/Packed/Internal/Tensor.hs b/lib/Data/Packed/Internal/Tensor.hs index 123270d..27fce6a 100644 --- a/lib/Data/Packed/Internal/Tensor.hs +++ b/lib/Data/Packed/Internal/Tensor.hs | |||
@@ -18,7 +18,7 @@ import Data.Packed.Internal | |||
18 | import Data.Packed.Internal.Vector | 18 | import Data.Packed.Internal.Vector |
19 | import Data.Packed.Internal.Matrix | 19 | import Data.Packed.Internal.Matrix |
20 | import Foreign.Storable | 20 | import Foreign.Storable |
21 | import Data.List(sort) | 21 | import Data.List(sort,elemIndex,nub) |
22 | 22 | ||
23 | data IdxTp = Covariant | Contravariant deriving (Show,Eq) | 23 | data IdxTp = Covariant | Contravariant deriving (Show,Eq) |
24 | 24 | ||
@@ -107,3 +107,18 @@ normal t = tridx (names t) t | |||
107 | 107 | ||
108 | contractions t1 t2 = [ contraction t1 n1 t2 n2 | n1 <- names t1, n2 <- names t2, compatIdx t1 n1 t2 n2 ] | 108 | contractions t1 t2 = [ contraction t1 n1 t2 n2 | n1 <- names t1, n2 <- names t2, compatIdx t1 n1 t2 n2 ] |
109 | 109 | ||
110 | -- sent to Haskell-Cafe by Sebastian Sylvan | ||
111 | perms [x] = [[x]] | ||
112 | perms xs = [y:ps | (y,ys) <- selections xs , ps <- perms ys] | ||
113 | selections [] = [] | ||
114 | selections (x:xs) = (x,xs) : [(y,x:ys) | (y,ys) <- selections xs] | ||
115 | |||
116 | |||
117 | interchanges ls = sum (map (count ls) ls) | ||
118 | where count l p = n | ||
119 | where Just pel = elemIndex p l | ||
120 | n = length $ filter (>p) $ take pel l | ||
121 | |||
122 | signature l | length (nub l) < length l = 0 | ||
123 | | even (interchanges l) = 1 | ||
124 | | otherwise = -1 | ||