accelerate-blas-0.2.0.1: Numeric Linear Algebra in Accelerate

Copyright [2017] Trevor L. McDonell BSD3 Trevor L. McDonell experimental non-portable (GHC extensions) None Haskell2010

Data.Array.Accelerate.Numeric.LinearAlgebra

Description

Synopsis

# Types

class (Elt a, Num a) => Numeric a Source #

Minimal complete definition

numericR

Instances
 Source # Instance details MethodsnumericR :: NumericR Double Source # Instance details MethodsnumericR :: NumericR Float Source # Instance details MethodsnumericR :: NumericR (Complex Double) Source # Instance details MethodsnumericR :: NumericR (Complex Float)

type Scalar = Array DIM0 #

Scalar arrays hold a single element

type Vector = Array DIM1 #

Vectors are one-dimensional arrays

type Matrix = Array DIM2 #

Matrices are two-dimensional arrays

# Products

## Vector-vector

(<.>) :: Numeric e => Acc (Vector e) -> Acc (Vector e) -> Acc (Scalar e) infixr 8 Source #

An infix synonym for dotu.

>>> let a = fromList (Z:.4) [1..]
>>> let b = fromList (Z:.4) [-2,0,1,1]
>>> a <.> b
Scalar Z [5.0]

>>> let c = fromList (Z:.2) [1:+1, 1:+0]
>>> let d = fromList (Z:.2) [1:+0, 1:+(-1)]
>>> c <.> d
Scalar Z [2.0 :+ 0.0]


(><) :: Numeric e => Acc (Vector e) -> Acc (Vector e) -> Acc (Matrix e) infixr 8 Source #

Outer product of two vectors

>>> let a = fromList (Z :. 3) [1,2,3]
>>> let b = fromList (Z :. 3) [5,2,3]
>>> a >< b
 Matrix (Z :. 3 :. 3)
[  5.0, 2.0, 3.0
, 10.0, 4.0, 6.0
, 15.0, 6.0, 9.0 ]


## Matrix-vector

(#>) :: Numeric e => Acc (Matrix e) -> Acc (Vector e) -> Acc (Vector e) infixr 8 Source #

Dense matrix-vector product

>>> let m = fromList (Z :. 2 :. 3) [1..]
>>> m
Matrix (Z :. 2 :. 3)
[ 1.0, 2.0, 3.0
, 4.0, 5.0, 6.0 ]

>>> let x = fromList (Z :. 3) [10,20,30]

>>> m #> x
Vector (Z :. 2) [140.0,320.0]


See gemv for a more general version of this operation.

(<#) :: Numeric e => Acc (Vector e) -> Acc (Matrix e) -> Acc (Vector e) infixr 8 Source #

Dense vector-matrix product

>>> let m = fromList (Z :. 2 :. 3) [1..]
>>> m
Matrix (Z :. 2 :. 3)
[1.0,2.0,3.0,
4.0,5.0,6.0]

>>> let v = fromList (Z :. 2) [5,10]

>>> v <# m
Vector (Z :. 3) [45.0,60.0,75.0]


See gemv for a more general version of this operation.

## Matrix-matrix

(<>) :: Numeric e => Acc (Matrix e) -> Acc (Matrix e) -> Acc (Matrix e) infixr 8 Source #

Dense matrix-matrix product

>>> let a = fromList (Z :. 3 :. 5) [1..]
>>> a
Matrix (Z:.3:.5)
[  1.0,  2.0,  3.0,  4.0,  5.0
,  6.0,  7.0,  8.0,  9.0, 10.0
, 11.0, 12.0, 13.0, 14.0, 15.0 ]

>>> let b = fromList (Z :. 5 :. 2) [1,3, 0,2, -1,5, 7,7, 6,0]
>>> b
Matrix (Z :. 5 :. 2)
[  1.0, 3.0
,  0.0, 2.0
, -1.0, 5.0
,  7.0, 7.0
,  6.0, 0.0 ]

>>> a <> b
Matrix (Z :. 3 :. 2)
[  56.0,  50.0
, 121.0, 135.0
, 186.0, 220.0 ]


See gemm for a more general version of this operation.

# Diagonal

identity :: Num e => Exp Int -> Acc (Matrix e) Source #

Create a square identity matrix of the given dimension

diagonal :: Num e => Acc (Vector e) -> Acc (Matrix e) Source #

Create a square matrix with the given diagonal