|
|
|
@ -135,14 +135,30 @@ module Matrix = |
|
|
|
for j=0 to M-1 do |
|
|
|
C.[i,j] <- f i j (C.Item(i,j)) |
|
|
|
C |
|
|
|
|
|
|
|
/// Map every matrix column into an element in a sequence using the given position dependent function. |
|
|
|
let inline mapCols (f: int -> Vector<float> -> 'a) (A: #Matrix<float>) = |
|
|
|
A.ColumnEnumerator() |> Seq.map (fun (j, col) -> f j col) |
|
|
|
|
|
|
|
/// In-place map every matrix column using the given position dependent function. |
|
|
|
let inline inplaceMapCols (f: int -> Vector<float> -> Vector<float>) (A: #Matrix<float>) = |
|
|
|
for j = 0 to A.ColumnCount-1 do |
|
|
|
A.SetColumn(j, f j (A.Column(j))) |
|
|
|
() |
|
|
|
|
|
|
|
/// In-place map every matrix row using the given position dependent function. |
|
|
|
let inline inplaceMapRows (f: int -> Vector<float> -> Vector<float>) (A: #Matrix<float>) = |
|
|
|
for i = 0 to A.RowCount-1 do |
|
|
|
A.SetRow(i, f i (A.Row(i))) |
|
|
|
() |
|
|
|
|
|
|
|
/// Map every matrix column using the given position dependent function. |
|
|
|
let inline mapCols (f: int -> Vector<float> -> Vector<float>) (A: #Matrix<float>) = |
|
|
|
let A = A.Clone() |
|
|
|
inplaceMapCols f A |
|
|
|
A |
|
|
|
|
|
|
|
/// Map every matrix row into an element in a sequence using the given position dependent function. |
|
|
|
let inline mapRows (f: int -> Vector<float> -> 'a) (A: #Matrix<float>) = |
|
|
|
A.RowEnumerator() |> Seq.map (fun (i, row) -> f i row) |
|
|
|
/// Map every matrix row using the given position dependent function. |
|
|
|
let inline mapRows (f: int -> Vector<float> -> Vector<float>) (A: #Matrix<float>) = |
|
|
|
let A = A.Clone() |
|
|
|
inplaceMapRows f A |
|
|
|
A |
|
|
|
|
|
|
|
/// In-place assignment. |
|
|
|
let inline inplaceAssign (f: int -> int -> float) (A: #Matrix<float>) = |
|
|
|
@ -170,13 +186,13 @@ module Matrix = |
|
|
|
f <- f + A.Item(i,j) |
|
|
|
f |
|
|
|
|
|
|
|
/// Returns the sum of the results generated by applying the function to each column of the matrix. |
|
|
|
/// Returns the sum of the results generated by applying a position dependent function to each column of the matrix. |
|
|
|
let inline sumColsBy (f: int -> Vector<float> -> 'a) (A: #Matrix<float>) = |
|
|
|
mapCols f A |> Seq.reduce (+) |
|
|
|
A.ColumnEnumerator() |> Seq.map (fun (j,col) -> f j col) |> Seq.reduce (+) |
|
|
|
|
|
|
|
/// Returns the sum of the results generated by applying the function to each row of the matrix. |
|
|
|
/// Returns the sum of the results generated by applying a position dependent function to each row of the matrix. |
|
|
|
let inline sumRowsBy (f: int -> Vector<float> -> 'a) (A: #Matrix<float>) = |
|
|
|
mapRows f A |> Seq.reduce (+) |
|
|
|
A.RowEnumerator() |> Seq.map (fun (i,row) -> f i row) |> Seq.reduce (+) |
|
|
|
|
|
|
|
/// Iterates over all elements of a matrix. |
|
|
|
let inline iter (f: float -> unit) (A: #Matrix<float>) = |
|
|
|
|