File: Matrix.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (26 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Data.Matrix where

import Foreign.Vector

import Text.Show

-- This is actually a C++ matrix<T> defined in "util/matrix.H"
-- Most of these functions seem to only be defined for matrix<double> = Matrix
data Matrix a

foreign import bpcall "Vector:fromVectors" fromVectors :: EVector (EVector a) -> Matrix a

fromLists xss = fromVectors $ toVector $ map toVector xss

foreign import bpcall "Matrix:" nrows :: Matrix a -> Int
foreign import bpcall "Matrix:" ncols :: Matrix a -> Int
foreign import bpcall "Matrix:transpose" tr :: Matrix a -> Matrix a
foreign import bpcall "Matrix:" scaleMatrix :: a -> Matrix a -> Matrix a
foreign import bpcall "Matrix:elementwise_multiply" (%*%) :: Matrix Double -> Matrix Double -> Matrix Double
foreign import bpcall "Matrix:elementwise_add" (%+%) :: Matrix Double -> Matrix Double -> Matrix Double
foreign import bpcall "Matrix:" zero :: Int -> Int -> Matrix Double
foreign import bpcall "Matrix:" identity :: Int -> Matrix Double
foreign import bpcall "Prelude:show" showMatrix :: Matrix a -> CPPString

instance Show (Matrix a) where
    show x = unpack_cpp_string $ showMatrix x