jalla-0.2.0.1: Higher level functions for linear algebra. Wraps BLAS and LAPACKE.

Safe HaskellNone
LanguageHaskell98

Numeric.Jalla.CVector

Contents

Description

Functions to work with C-like arrays. This is provided to have arrays which work with CBLAS and LAPACKE libraries.

Synopsis

Classes

Vectors

class (Indexable (vec e) Index e, Field1 e) => GVector vec e where Source

Methods

vectorLength :: vec e -> Index Source

Creates a vector. Not really useful may be dropped in the future. vector :: Index -> vec e | Returns the length of a vector.

class (BlasOps e, GVector vec e, Show (vec e)) => CVector vec e where Source

Methods

vectorAlloc :: Index -> IO (vec e) Source

Allocate a vector of a given length.

withCVector :: vec e -> (Ptr e -> IO a) -> IO a Source

Operate on a vector with the given IO action. The action gets as parameter a pointer to the array.

inc :: vec e -> Index Source

Returns the increment per element for this vector (like the inc arguments for BLAS). For contiguous storage, this would simply be 1.

Instances

Vector/vector operations

class CVector vec e => VectorVector vec e where Source

Vector/vector operations.

Minimal complete definition

Nothing

Methods

(||+) :: vec e -> vec e -> vec e infixl 6 Source

Vector addition

(||-) :: vec e -> vec e -> vec e infixl 6 Source

Vector subtraction

(||*) :: vec e -> vec e -> e infixl 7 Source

Dot product

Vector/scalar operations

class CVector vec e => VectorScalar vec e where Source

Vector manipulations by a scalar.

Minimal complete definition

Nothing

Methods

(|.*) :: vec e -> e -> vec e infixl 7 Source

(|./) :: vec e -> e -> vec e infixl 7 Source

(|.+) :: vec e -> e -> vec e infixl 6 Source

(|.-) :: vec e -> e -> vec e infixl 6 Source

Indexable

Construction, conversion, modification

Monadic, efficient vector modification

data VMM s vec e a Source

Instances

Monad (VMM s vec e) Source 
Functor (VMM s vec e) Source 
Applicative (VMM s vec e) Source 
(BlasOps e, CVector vec e) => IMM (VMM s vec e) Index (vec e) e Source 

createVector :: CVector vec e => Index -> VMM s vec e a -> vec e Source

modifyVector :: CVector vec e => vec e -> VMM s vec e a -> vec e Source

Vector maps

vectorAdd :: CVector vec e => e -> vec e -> VMM s vec e () Source

Adds alpha * v to the current vector.

vectorMap :: (CVector vec1 e1, CVector vec2 e2) => (e1 -> e2) -> vec1 e1 -> vec2 e2 Source

Maps a unary function over the elements of a vector and returns the resulting vector.

vectorBinMap Source

Arguments

:: (CVector vec1 e1, CVector vec2 e2, CVector vec3 e3) 
=> (e1 -> e2 -> e3)

The function f to map.

-> vec1 e1

The first input vector v1 for f.

-> vec2 e2

The second input vector v2 for f.

-> vec3 e3

The result vector. It will have length min(l1,l2), where l1,l2 are the lengths of v1 and v2.

Maps a binary function to the elements of two vectors and returns the resulting vector.

Conversion From And To Lists

listVector :: CVector vec e => [e] -> vec e Source

vectorList :: GVector vec e => vec e -> [e] Source

Getting Single Values

vectorGetElem :: CVector vec e => vec e -> Index -> e Source

Inner product

innerProduct :: (BlasOps e, CVector vec e) => vec e -> vec e -> e Source

IO Functions

copyVector :: (BlasOps e, CVector vec e, CVector vec2 e) => vec e -> IO (vec2 e) Source

Make a copy of the input vector. Using the cblas_*copy functions.

Unsafe Functions

unsafeCopyVector Source

Arguments

:: (CVector vec e, CVector vec2 e) 
=> vec e

The source vector.

-> vec2 e

The destination vector.

-> IO () 

Copies from one vector to the other, in-place and therefore unsafely. Uses the BLAS copy function. min (vectorLength src) (vectorlength dest) elements are copied from the first to the second vector.

unsafeVectorAdd Source

Arguments

:: (BlasOps e, CVector vec e) 
=> e

alpha

-> vec e

Vector 1

-> vec e

Vector 2, will be changed in place!

-> IO () 

Computes v2 <- alpha * v1 + v2. The result is stored in the memory of v2, therefore this is unsafe and low level, only for internal use.

unsafeVectorMap :: (CVector vec1 e1, CVector vec2 e2) => (e1 -> e2) -> vec1 e1 -> vec2 e2 -> IO () Source

unsafeVectorBinMap :: (CVector vec1 e1, CVector vec2 e2, CVector vec3 e3) => (e1 -> e2 -> e3) -> vec1 e1 -> vec2 e2 -> vec3 e3 -> IO () Source

Re-exported

data Complex a :: * -> *

Complex numbers are an algebraic type.

For a complex number z, abs z is a number with the magnitude of z, but oriented in the positive real direction, whereas signum z has the phase of z, but unit magnitude.

Instances