summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Tensor.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-05 10:09:17 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-05 10:09:17 +0000
commit1fb4ea70c517050d3cbad75357a4fffbf5a40e7b (patch)
tree6107b470be9300297f9f08a4280fbf46faf6a862 /lib/Data/Packed/Internal/Tensor.hs
parent7430630fa0504296b796223e01cbd417b88650ef (diff)
working on contraction
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 11101a9..960e3c5 100644
--- a/lib/Data/Packed/Internal/Tensor.hs
+++ b/lib/Data/Packed/Internal/Tensor.hs
@@ -17,16 +17,24 @@ module Data.Packed.Internal.Tensor where
17 17
18import Data.Packed.Internal.Vector 18import Data.Packed.Internal.Vector
19import Data.Packed.Internal.Matrix 19import Data.Packed.Internal.Matrix
20 20import Foreign.Storable
21 21
22data IdxTp = Covariant | Contravariant deriving Show 22data IdxTp = Covariant | Contravariant deriving Show
23 23
24data Tensor t = T { dims :: [(Int,(IdxTp,String))] 24data Tensor t = T { dims :: [(Int,(IdxTp,String))]
25 , ten :: Vector t 25 , ten :: Vector t
26 } deriving Show 26 }
27 27
28rank = length . dims 28rank = length . dims
29 29
30outer u v = dat (multiply RowMajor r c) 30outer u v = dat (multiply RowMajor r c)
31 where r = matrixFromVector RowMajor 1 u 31 where r = matrixFromVector RowMajor 1 u
32 c = matrixFromVector RowMajor (dim v) v 32 c = matrixFromVector RowMajor (dim v) v
33
34instance (Show a,Storable a) => Show (Tensor a) where
35 show T {dims = [], ten = t} = "scalar "++show (t `at` 0)
36 show T {dims = ds, ten = t} = "("++shdims ds ++") "++ show (toList t)
37
38
39shdims [(n,(t,name))] = name++"["++show n++"]"
40shdims (d:ds) = shdims [d] ++ "><"++ shdims ds \ No newline at end of file