summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Tensor.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-21 08:39:22 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-21 08:39:22 +0000
commitaa14e6615533e7bd5e2b15acdc3ec76afbe1aac4 (patch)
tree619fc0cdb35be0d67a111dc2665981aa858ebd5e /lib/Data/Packed/Internal/Tensor.hs
parentb2af660f87a55dd15f4519b21e66837ec811dc25 (diff)
working with tensors
Diffstat (limited to 'lib/Data/Packed/Internal/Tensor.hs')
-rw-r--r--lib/Data/Packed/Internal/Tensor.hs17
1 files changed, 16 insertions, 1 deletions
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
18import Data.Packed.Internal.Vector 18import Data.Packed.Internal.Vector
19import Data.Packed.Internal.Matrix 19import Data.Packed.Internal.Matrix
20import Foreign.Storable 20import Foreign.Storable
21import Data.List(sort) 21import Data.List(sort,elemIndex,nub)
22 22
23data IdxTp = Covariant | Contravariant deriving (Show,Eq) 23data IdxTp = Covariant | Contravariant deriving (Show,Eq)
24 24
@@ -107,3 +107,18 @@ normal t = tridx (names t) t
107 107
108contractions t1 t2 = [ contraction t1 n1 t2 n2 | n1 <- names t1, n2 <- names t2, compatIdx t1 n1 t2 n2 ] 108contractions 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
111perms [x] = [[x]]
112perms xs = [y:ps | (y,ys) <- selections xs , ps <- perms ys]
113selections [] = []
114selections (x:xs) = (x,xs) : [(y,x:ys) | (y,ys) <- selections xs]
115
116
117interchanges 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
122signature l | length (nub l) < length l = 0
123 | even (interchanges l) = 1
124 | otherwise = -1