FsAlg


Vector

Operations on Vector type. (Implementing functionality similar to Microsoft.FSharp.Collections.Array)

Functions and values

Function or valueDescription
append(v1 v2)
Signature: v1:Vector<^T> -> v2:Vector<^T> -> Vector<^T>
Type parameters: ^T

Creates a vector that contains the elements of vector v1 followed by the elements of vector v2

concat(v)
Signature: v:seq<Vector<^T>> -> Vector<^T>
Type parameters: ^T

Builds a new vector that contains the elements of each of the given sequence of vectors v

copy(v)
Signature: v:Vector<^T> -> Vector<^T>
Type parameters: ^T

Creates a copy of vector v

create(n v)
Signature: n:int -> v:^T -> Vector<^T>
Type parameters: ^T

Creates a vector with n elements, all having value v

createBasis(n i v)
Signature: n:int -> i:int -> v:^T -> Vector<^T>
Type parameters: ^T

Creates a vector with n elements, where the element with index i has value v and the rest of the elements have value 0

exists(p v)
Signature: p:(^T -> bool) -> v:Vector<^T> -> bool
Type parameters: ^T

Tests if any element of vector v satisfies predicate p

exists2(p v1 v2)
Signature: p:(^T1 -> ^T2 -> bool) -> v1:Vector<^T1> -> v2:Vector<^T2> -> bool
Type parameters: ^T1, ^T2

Tests if any pair of corresponding elements of vectors v1 and v2 satisfies predicate p

fill(v s c a)
Signature: v:Vector<^T> -> s:int -> c:int -> a:^T -> unit
Type parameters: ^T

Fills a range of elements of vector v with value a starting with index s and counting c elements

find(p v)
Signature: p:(^T -> bool) -> v:Vector<^T> -> ^T
Type parameters: ^T

Returns the first element of vector v for which predicate p is true

findIndex(p v)
Signature: p:(^T -> bool) -> v:Vector<^T> -> int
Type parameters: ^T

Returns the index of the first element of vector v for which predicate p is true

fold(f s v)
Signature: f:('S -> ^T -> 'S) -> s:'S -> v:Vector<^T> -> 'S
Type parameters: 'S, ^T

Applies function f to each element of vector v, threading an accumulator (with initial state s) through the computation. If the input function is f and the elements are i0...iN then computes f (... (f s i0)...) iN.

fold2(f s v1 v2)
Signature: f:('S -> ^T1 -> ^T2 -> 'S) -> s:'S -> v1:Vector<^T1> -> v2:Vector<^T2> -> 'S
Type parameters: 'S, ^T1, ^T2

Applies function f to corresponding elements of vectors v1 and v2, threading an accumulator (with initial state s) through the computation. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

foldBack(f v s)
Signature: f:(^T -> 'S -> 'S) -> v:Vector<^T> -> s:'S -> 'S
Type parameters: ^T, 'S

Applies function f to each element of vector v, threading an accumulator (with initial state s) through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN s)).

foldBack2(f v1 v2 s)
Signature: f:(^T1 -> ^T2 -> 'S -> 'S) -> v1:Vector<^T1> -> v2:Vector<^T2> -> s:'S -> 'S
Type parameters: ^T1, ^T2, 'S

Applies function f to corresponding elements of vectors v1 and v2, threading an accumulator (with initial state s) through the computation. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

forall(p v)
Signature: p:(^T -> bool) -> v:Vector<^T> -> bool
Type parameters: ^T

Tests if all elements of vector v satisfy predicate p

forall2(p v1 v2)
Signature: p:(^T1 -> ^T2 -> bool) -> v1:Vector<^T1> -> v2:Vector<^T2> -> bool
Type parameters: ^T1, ^T2

Tests if all corresponding elements of vectors v1 and v2 satisfy predicate p pairwise

get(v i)
Signature: v:Vector<^T> -> i:int -> ^T
Type parameters: ^T

Gets the element of vector v with index i

init(n f)
Signature: n:int -> f:(int -> ^T) -> Vector<^T>
Type parameters: ^T

Creates a vector with dimension n and a generator function f to compute the elements

iter(f v)
Signature: f:(^T -> unit) -> v:Vector<^T> -> unit
Type parameters: ^T

Applies function f to each element of vector v

iter2(f v1 v2)
Signature: f:(^T1 -> ^T2 -> unit) -> v1:Vector<^T1> -> v2:Vector<^T2> -> unit
Type parameters: ^T1, ^T2

Applies function f to corresponding elements of vectors v1 and v2 pairwise. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

iteri(f v)
Signature: f:(int -> ^T -> unit) -> v:Vector<^T> -> unit
Type parameters: ^T

Applies function f to each element of vector v. The integer passed to function f indicates the index of element.

iteri2(f v1 v2)
Signature: f:(int -> ^T1 -> ^T2 -> unit) -> v1:Vector<^T1> -> v2:Vector<^T2> -> unit
Type parameters: ^T1, ^T2

Applies function f to corresponding elements of vectors v1 and v2 pairwise. The integer passed to function f indicates the index of element. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

l1norm(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Gets the L1 (Manhattan) norm of vector v

l2norm(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Gets the L2 (Euclidean) norm of vector v. This is the same with Vector.norm.

l2normSq(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Gets the squared L2 (Euclidean) norm of vector v. This is the same with Vector.normSq.

length(v)
Signature: v:Vector<^T> -> int
Type parameters: ^T

Returns the length of vector v

lpnorm(p v)
Signature: p:^T -> v:Vector<^T> -> ^T
Type parameters: ^T

Gets the Lp norm (or p-norm) of vector v, with the given p

map(f v)
Signature: f:(^T -> ^U) -> v:Vector<^T> -> Vector<^U>
Type parameters: ^T, ^U

Creates a vector whose elements are the results of applying function f to each element of vector v

map2(f v1 v2)
Signature: f:(^T1 -> ^T2 -> ^U) -> v1:Vector<^T1> -> v2:Vector<^T2> -> Vector<^U>
Type parameters: ^T1, ^T2, ^U

Creates a vector whose elements are the results of applying function f to corresponding elements of vectors v1 and v2 pairwise. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

mapi(f v)
Signature: f:(int -> ^T -> ^U) -> v:Vector<^T> -> Vector<^U>
Type parameters: ^T, ^U

Creates a vector whose elements are the results of applying function f to each element of vector v. An element index is also supplied to function f.

mapi2(f v1 v2)
Signature: f:(int -> ^T1 -> ^T2 -> ^U) -> v1:Vector<^T1> -> v2:Vector<^T2> -> Vector<^U>
Type parameters: ^T1, ^T2, ^U

Creates a vector whose elements are the results of applying function f to corresponding elements of vectors v1 and v2 pairwise. The integer passed to function f indicates the index of element. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

max(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Returns the maximum of all elements of vector v

maxBy(f v)
Signature: f:(^T -> 'U) -> v:Vector<^T> -> ^T
Type parameters: ^T, 'U

Returns the maximum of all elements of vector v, compared by using Operators.max on the result of function f

min(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Returns the minimum of all elements of vector v

minBy(f v)
Signature: f:(^T -> 'U) -> v:Vector<^T> -> ^T
Type parameters: ^T, 'U

Returns the minimum of all elements of vector v, compared by using Operators.min on the result of function f

norm(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Gets the L2 (Euclidean) norm of vector v. This is the same with Vector.l2norm.

normSq(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Gets the squared L2 (Euclidean) norm of vector v. This is the same with Vector.l2normSq.

ofArray(v)
Signature: v:^T [] -> Vector<^T>
Type parameters: ^T

Createsa vector from array v

ofSeq(s)
Signature: s:seq<^T> -> Vector<^T>
Type parameters: ^T

Creates a vector from sequence s

reduce(f v)
Signature: f:(^T -> ^T -> ^T) -> v:Vector<^T> -> ^T
Type parameters: ^T

Applies function f to each element of vector v, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN, then computes f (... (f i0 i1)...) iN.

reduceBack(f v)
Signature: f:(^T -> ^T -> ^T) -> v:Vector<^T> -> ^T
Type parameters: ^T

Applies function f to each element of vector v, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN-1 iN)).

replace(f v)
Signature: f:(^T -> ^T) -> v:Vector<^T> -> unit
Type parameters: ^T

Replaces the elements of vector v by mutating them in place, passing them through function f

replace2(f v1 v2)
Signature: f:(^T1 -> ^T2 -> ^T1) -> v1:Vector<^T1> -> v2:Vector<^T2> -> unit
Type parameters: ^T1, ^T2

Replaces the elements of vector v1 by mutating them in place. The new values are computed by applying function f to corresponding elements of vectors v1 and v2 pairwise. The two input vectors must have the same lengths, otherwie ArgumentException is raised.

replacei(f v)
Signature: f:(int -> ^T -> ^T) -> v:Vector<^T> -> unit
Type parameters: ^T

Replaces the elements of vector v by mutating them in place, passing them through function f. An element index is also supplied to function f.

replacei2(f v1 v2)
Signature: f:(int -> ^T1 -> ^T2 -> ^T1) -> v1:Vector<^T1> -> v2:Vector<^T2> -> unit
Type parameters: ^T1, ^T2

Replaces the elements of vector v1 by mutating them in place. The new values are computed by applying function f to corresponding elements of vectors v1 and v2 pairwise. An element index is also supplied to function f. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

replaceWith(v1 v2)
Signature: v1:Vector<^T> -> v2:Vector<^T> -> unit
Type parameters: ^T

Replaces the elements of vector v1 with the elements of vector v2, by mutating them in place. The two input vectors must have the same lengths, otherwise ArgumentException is raised.

scan(f s v)
Signature: f:(^S -> ^T -> ^S) -> s:^S -> v:Vector<^T> -> Vector<^S>
Type parameters: ^S, ^T

Like Vector.fold, but returns the intermediate and final results

scanBack(f s v)
Signature: f:(^T -> ^S -> ^S) -> s:^S -> v:Vector<^T> -> Vector<^S>
Type parameters: ^T, ^S

Like Vector.foldBack, but returns both the intermediate and final results

set(v i a)
Signature: v:Vector<^T> -> i:int -> a:^T -> unit
Type parameters: ^T

Sets the element of vectorv with index i to value a

split(n v)
Signature: n:seq<int> -> v:Vector<^T> -> seq<Vector<^T>>
Type parameters: ^T

Returns a sequence of vectors that are obtained by splitting vector v into subvectors whose lengths are given in the sequence n

splitEqual(n v)
Signature: n:int -> v:Vector<^T> -> seq<Vector<^T>>
Type parameters: ^T

Returns a sequence of vectors that are obtained by splitting vector v into n subvectors of equal length. The length of vector v must be an integer multiple of n, otherwise ArgumentException is raised.

standardBasis(n i)
Signature: n:int -> i:int -> Vector<^T>
Type parameters: ^T

Creates a vector with n elements, where the i-th element is 1 and the rest of the elements are 0

sub(v s c)
Signature: v:Vector<^T> -> s:int -> c:int -> Vector<^T>
Type parameters: ^T

Creates a new vector that contains the given subrange of vector v, specified by start index s and count c

sum(v)
Signature: v:Vector<^T> -> ^T
Type parameters: ^T

Returns the sum of all the elements in vector v

sumBy(f v)
Signature: f:(^T -> ^U) -> v:Vector<^T> -> ^U
Type parameters: ^T, ^U

Returns the sum of the results generated by applying function f to each element of vector v

toArray(v)
Signature: v:Vector<^T> -> ^T []
Type parameters: ^T

Converts vector v to an array

toSeq(v)
Signature: v:Vector<^T> -> seq<^T>
Type parameters: ^T

Returns vector v as a sequence

unitVector(v)
Signature: v:Vector<^T> -> Vector<^T>
Type parameters: ^T

Gets the unit vector codirectional with vector v