|
|
|
@ -126,6 +126,14 @@ module Matrix = |
|
|
|
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, row) -> f j row) |
|
|
|
|
|
|
|
/// 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) |
|
|
|
|
|
|
|
/// In-place assignment. |
|
|
|
let inline inplaceAssign (f: int -> int -> float) (A: #Matrix<float>) = |
|
|
|
for i=0 to A.RowCount-1 do |
|
|
|
@ -151,7 +159,15 @@ module Matrix = |
|
|
|
for j=0 to A.ColumnCount-1 do |
|
|
|
f <- f + A.Item(i,j) |
|
|
|
f |
|
|
|
|
|
|
|
/// Returns the sum of the results generated by applying the function to each column of the matrix. |
|
|
|
let inline sumColsBy (f: int -> Vector<float> -> float) (A: #Matrix<float>) = |
|
|
|
mapCols f A |> Seq.fold (+) 0.0 |
|
|
|
|
|
|
|
/// Returns the sum of the results generated by applying the function to each row of the matrix. |
|
|
|
let inline sumRowsBy (f: int -> Vector<float> -> float) (A: #Matrix<float>) = |
|
|
|
mapRows f A |> Seq.fold (+) 0.0 |
|
|
|
|
|
|
|
/// Iterates over all elements of a matrix. |
|
|
|
let inline iter (f: float -> unit) (A: #Matrix<float>) = |
|
|
|
for i=0 to A.RowCount-1 do |
|
|
|
|