summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Tensor.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Tensor.hs')
-rw-r--r--lib/Data/Packed/Internal/Tensor.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Data/Packed/Internal/Tensor.hs b/lib/Data/Packed/Internal/Tensor.hs
index 67dcb09..123270d 100644
--- a/lib/Data/Packed/Internal/Tensor.hs
+++ b/lib/Data/Packed/Internal/Tensor.hs
@@ -1,4 +1,3 @@
1--{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-}
2----------------------------------------------------------------------------- 1-----------------------------------------------------------------------------
3-- | 2-- |
4-- Module : Data.Packed.Internal.Tensor 3-- Module : Data.Packed.Internal.Tensor
@@ -9,15 +8,17 @@
9-- Stability : provisional 8-- Stability : provisional
10-- Portability : portable (uses FFI) 9-- Portability : portable (uses FFI)
11-- 10--
12-- Fundamental types 11-- basic tensor operations
13-- 12--
14----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
15 14
16module Data.Packed.Internal.Tensor where 15module Data.Packed.Internal.Tensor where
17 16
17import 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)
21 22
22data IdxTp = Covariant | Contravariant deriving (Show,Eq) 23data IdxTp = Covariant | Contravariant deriving (Show,Eq)
23 24
@@ -99,3 +100,10 @@ compatIdxAux (n1,(t1,_)) (n2, (t2,_)) = t1 /= t2 && n1 == n2
99compatIdx t1 n1 t2 n2 = compatIdxAux d1 d2 where 100compatIdx t1 n1 t2 n2 = compatIdxAux d1 d2 where
100 d1 = head $ snd $ fst $ findIdx n1 t1 101 d1 = head $ snd $ fst $ findIdx n1 t1
101 d2 = head $ snd $ fst $ findIdx n2 t2 102 d2 = head $ snd $ fst $ findIdx n2 t2
103
104names t = sort $ map (snd.snd) (dims t)
105
106normal t = tridx (names t) t
107
108contractions t1 t2 = [ contraction t1 n1 t2 n2 | n1 <- names t1, n2 <- names t2, compatIdx t1 n1 t2 n2 ]
109