comfort-blas-0.0.2: Numerical Basic Linear Algebra using BLAS
Safe HaskellSafe-Inferred
LanguageHaskell98

Numeric.BLAS.Vector

Synopsis

Documentation

type family RealOf x Source #

Instances

Instances details
type RealOf Double Source # 
Instance details

Defined in Numeric.BLAS.Scalar

type RealOf Float Source # 
Instance details

Defined in Numeric.BLAS.Scalar

type RealOf (Complex a) Source # 
Instance details

Defined in Numeric.BLAS.Scalar

type RealOf (Complex a) = a

toList :: (C sh, Storable a) => Vector sh a -> [a] Source #

fromList :: (C sh, Storable a) => sh -> [a] -> Vector sh a Source #

append :: (C shx, C shy, Storable a) => Array shx a -> Array shy a -> Array (shx ::+ shy) a infixr 5 #

(+++) :: (C shx, C shy, Storable a) => Vector shx a -> Vector shy a -> Vector (shx ::+ shy) a infixr 5 Source #

Precedence and associativity (right) of (List.++). This also matches (::+).

forVector number_ $ \xs -> forVector number_ $ \ys -> forVector number_ $ \zs -> Vector.toList ((xs +++ ys) +++ zs) == Vector.toList (xs +++ (ys +++ zs))

take :: (Integral n, Storable a) => n -> Array (ZeroBased n) a -> Array (ZeroBased n) a #

\(QC.NonNegative n) (Array16 x)  ->  x == Array.mapShape (Shape.ZeroBased . Shape.size) (Array.append (Array.take n x) (Array.drop n x))

drop :: (Integral n, Storable a) => n -> Array (ZeroBased n) a -> Array (ZeroBased n) a #

\(QC.NonNegative n) (Array16 x)  ->  x == Array.mapShape (Shape.ZeroBased . Shape.size) (Array.append (Array.take n x) (Array.drop n x))

takeLeft :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> Array sh0 a #

\(Array16 x) (Array16 y) -> let xy = Array.append x y in x == Array.takeLeft xy  &&  y == Array.takeRight xy

takeRight :: (C sh0, C sh1, Storable a) => Array (sh0 ::+ sh1) a -> Array sh1 a #

swap :: (Indexed sh, Storable a) => Index sh -> Index sh -> Vector sh a -> Vector sh a Source #

QC.forAll (QC.choose (1,100)) $ \dim -> QC.forAll (QC.choose (0, dim-1)) $ \i -> QC.forAll (QC.choose (0, dim-1)) $ \j -> Vector.unit (Shape.ZeroBased dim) i == (Vector.swap i j (Vector.unit (Shape.ZeroBased dim) j) :: Vector Number_)

reverse :: (Integral n, Floating a) => Vector (ZeroBased n) a -> Vector (ZeroBased n) a Source #

Vector.autoFromList [] == (Vector.reverse $ Vector.autoFromList [] :: Vector Number_)
Vector.autoFromList [1] == (Vector.reverse $ Vector.autoFromList [1] :: Vector Number_)
Vector.autoFromList [3,2,1] == (Vector.reverse $ Vector.autoFromList [1,2,3] :: Vector Number_)
forVector number_ $ \xs -> reverse (Vector.toList xs) == Vector.toList (Vector.reverse xs)
forVector number_ $ \xs -> xs == Vector.reverse (Vector.reverse xs)
forVector number_ $ \xs -> forVector number_ $ \ys -> Vector.reverse (xs <> ys) == Vector.reverse ys <> Vector.reverse xs

cyclicReverse :: (Integral n, Floating a) => Vector (Cyclic n) a -> Vector (Cyclic n) a Source #

cyclicVectorFromList [] == Vector.cyclicReverse (cyclicVectorFromList [])
cyclicVectorFromList [1] == Vector.cyclicReverse (cyclicVectorFromList [1])
cyclicVectorFromList [1,3,2] == Vector.cyclicReverse (cyclicVectorFromList [1,2,3])
cyclicVectorFromList [1,6,5,4,3,2] == Vector.cyclicReverse (cyclicVectorFromList [1,2,3,4,5,6])
forCyclicVector number_ $ \xs -> xs == Vector.cyclicReverse (Vector.cyclicReverse xs)

singleton :: Storable a => a -> Array () a #

\x  ->  Array.singleton x ! () == (x::Word16)

constant :: (C sh, Floating a) => sh -> a -> Vector sh a Source #

constant () = singleton

However, singleton does not need Floating constraint.

zero :: (C sh, Floating a) => sh -> Vector sh a Source #

one :: (C sh, Floating a) => sh -> Vector sh a Source #

unit :: (Indexed sh, Floating a) => sh -> Index sh -> Vector sh a Source #

dot :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> a Source #

dot x y = Matrix.toScalar (singleRow x -*| singleColumn y)

inner :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> a Source #

forVector2 number_ $ \xs ys -> Vector.inner xs ys == Vector.dot (Vector.conjugate xs) ys

(-*|) :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> a infixl 7 Source #

dot x y = Matrix.toScalar (singleRow x -*| singleColumn y)

sum :: (C sh, Floating a) => Vector sh a -> a Source #

forVector number_ $ \xs -> Vector.sum xs == List.sum (Vector.toList xs)

absSum :: (C sh, Floating a) => Vector sh a -> RealOf a Source #

Sum of the absolute values of real numbers or components of complex numbers. For real numbers it is equivalent to norm1.

norm2 :: (C sh, Floating a) => Vector sh a -> RealOf a Source #

Euclidean norm of a vector or Frobenius norm of a matrix.

norm2Squared :: (C sh, Floating a) => Vector sh a -> RealOf a Source #

normInf :: (C sh, Floating a) => Vector sh a -> RealOf a Source #

forVector number_ $ \xs -> Vector.normInf xs == List.maximum (0 : List.map absolute (Vector.toList xs))

normInf1 :: (C sh, Floating a) => Vector sh a -> RealOf a Source #

Computes (almost) the infinity norm of the vector. For complex numbers every element is replaced by the sum of the absolute component values first.

argAbsMaximum :: (InvIndexed sh, Floating a) => Vector sh a -> (Index sh, a) Source #

Returns the index and value of the element with the maximal absolute value. Caution: It actually returns the value of the element, not its absolute value!

>>> Vector.argAbsMaximum $ Vector.autoFromList [1:+2, 3:+4, 5, 6 :: Complex_]
(3,6.0 :+ 0.0)
forVector number_ $ \xs -> isNonEmpty xs ==> let (xi,xm) = Vector.argAbsMaximum xs in xs!xi == xm
forVector number_ $ \xs -> isNonEmpty xs ==> let (_xi,xm) = Vector.argAbsMaximum xs in List.all (\x -> absolute x <= absolute xm) $ Vector.toList xs
forVector number_ $ \xs -> forVector number_ $ \ys -> isNonEmpty xs && isNonEmpty ys ==> let (_xi,xm) = Vector.argAbsMaximum xs; (_yi,ym) = Vector.argAbsMaximum ys; (zi,zm) = Vector.argAbsMaximum (xs+++ys) in case zi of Left _ -> xm==zm && absolute xm >= absolute ym; Right _ -> ym==zm && absolute xm < absolute ym

argAbs1Maximum :: (InvIndexed sh, Floating a) => Vector sh a -> (Index sh, a) Source #

Returns the index and value of the element with the maximal absolute value. The function does not strictly compare the absolute value of a complex number but the sum of the absolute complex components. Caution: It actually returns the value of the element, not its absolute value!

>>> Vector.argAbs1Maximum $ Vector.autoFromList [1:+2, 3:+4, 5, 6 :: Complex_]
(1,3.0 :+ 4.0)
forVector real_ $ \xs -> isNonEmpty xs ==> Vector.argAbsMaximum xs == Vector.argAbs1Maximum xs

product :: (C sh, Floating a) => Vector sh a -> a Source #

QC.forAll (QC.choose (0,10)) $ \dim -> QC.forAll (genVector (shapeInt dim) (genNumber 3)) $ \xs -> approx 1e-2 (Vector.product xs) (List.product (Vector.toList (xs :: Vector Number_)))

scale :: (C sh, Floating a) => a -> Vector sh a -> Vector sh a Source #

forVector number_ $ \xs -> Vector.negate xs == Vector.scale minusOne xs
forVector number_ $ \xs -> Vector.scale 2 xs == xs |+| xs

scaleReal :: (C sh, Floating a) => RealOf a -> Vector sh a -> Vector sh a Source #

(.*|) :: (C sh, Floating a) => a -> Vector sh a -> Vector sh a infixl 7 Source #

forVector number_ $ \xs -> Vector.negate xs == Vector.scale minusOne xs
forVector number_ $ \xs -> Vector.scale 2 xs == xs |+| xs

add :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> Vector sh a infixl 6 Source #

forVector2 number_ $ \xs ys -> xs |+| ys == ys |+| xs
forVector2 number_ $ \xs ys -> xs == xs |-| ys |+| ys

sub :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> Vector sh a infixl 6 Source #

forVector2 number_ $ \xs ys -> xs |+| ys == ys |+| xs
forVector2 number_ $ \xs ys -> xs == xs |-| ys |+| ys

(|+|) :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> Vector sh a infixl 6 Source #

forVector2 number_ $ \xs ys -> xs |+| ys == ys |+| xs
forVector2 number_ $ \xs ys -> xs == xs |-| ys |+| ys

(|-|) :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> Vector sh a infixl 6 Source #

forVector2 number_ $ \xs ys -> xs |+| ys == ys |+| xs
forVector2 number_ $ \xs ys -> xs == xs |-| ys |+| ys

negate :: (C sh, Floating a) => Vector sh a -> Vector sh a Source #

forVector number_ $ \xs -> xs == Vector.negate (Vector.negate xs)

raise :: (C sh, Floating a) => a -> Vector sh a -> Vector sh a Source #

QC.forAll (genNumber maxElem) $ \d -> forVector number_ $ \xs -> xs == Vector.raise (-d) (Vector.raise d xs)

mac :: (C sh, Eq sh, Floating a) => a -> Vector sh a -> Vector sh a -> Vector sh a Source #

mul :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> Vector sh a Source #

forVector2 number_ $ \xs ys -> Vector.mul xs ys == Vector.mul ys xs

mulConj :: (C sh, Eq sh, Floating a) => Vector sh a -> Vector sh a -> Vector sh a Source #

forVector2 number_ $ \xs ys -> Vector.mulConj xs ys == Vector.mul (Vector.conjugate xs) ys

minimum :: (C sh, Real a) => Vector sh a -> a Source #

For restrictions see limits.

forVector real_ $ \xs -> isNonEmpty xs ==> Vector.minimum xs == List.minimum (Vector.toList xs)
forVector real_ $ \xs -> isNonEmpty xs ==> Vector.maximum xs == List.maximum (Vector.toList xs)
forVector real_ $ \xs -> isNonEmpty xs ==> - Vector.maximum xs == Vector.minimum (Vector.negate xs)

argMinimum :: (InvIndexed sh, Index sh ~ ix, Real a) => Vector sh a -> (ix, a) Source #

For restrictions see limits.

maximum :: (C sh, Real a) => Vector sh a -> a Source #

For restrictions see limits.

forVector real_ $ \xs -> isNonEmpty xs ==> Vector.minimum xs == List.minimum (Vector.toList xs)
forVector real_ $ \xs -> isNonEmpty xs ==> Vector.maximum xs == List.maximum (Vector.toList xs)
forVector real_ $ \xs -> isNonEmpty xs ==> - Vector.maximum xs == Vector.minimum (Vector.negate xs)

argMaximum :: (InvIndexed sh, Index sh ~ ix, Real a) => Vector sh a -> (ix, a) Source #

For restrictions see limits.

limits :: (C sh, Real a) => Vector sh a -> (a, a) Source #

forVector real_ $ \xs -> isNonEmpty xs ==> Vector.limits xs == Array.limits xs

In contrast to limits this implementation is based on fast BLAS functions. It should be faster than Array.minimum and Array.maximum although it is certainly not as fast as possible. Boths limits share the precision of the limit with the larger absolute value. This implies for example that you cannot rely on the property that raise (- minimum x) x has only non-negative elements.

argLimits :: (InvIndexed sh, Index sh ~ ix, Real a) => Vector sh a -> ((ix, a), (ix, a)) Source #

For restrictions see limits.

foldl :: (C sh, Storable a) => (b -> a -> b) -> b -> Array sh a -> b #

foldl1 :: (C sh, Storable a) => (a -> a -> a) -> Array sh a -> a #

foldMap :: (C sh, Storable a, Ord a, Semigroup m) => (a -> m) -> Array sh a -> m #

conjugate :: (C sh, Floating a) => Vector sh a -> Vector sh a Source #

fromReal :: (C sh, Floating a) => Vector sh (RealOf a) -> Vector sh a Source #

toComplex :: (C sh, Floating a) => Vector sh a -> Vector sh (ComplexOf a) Source #

realPart :: (C sh, Floating a) => Vector sh a -> Vector sh (RealOf a) Source #

imaginaryPart :: (C sh, Real a) => Vector sh (Complex a) -> Vector sh a Source #

zipComplex :: (C sh, Eq sh, Real a) => Vector sh a -> Vector sh a -> Vector sh (Complex a) Source #

unzipComplex :: (C sh, Real a) => Vector sh (Complex a) -> (Vector sh a, Vector sh a) Source #