Browse Source

LA: F# modules matrix sumRows, sumAbsRows, normRows and same for columns

provider
Christoph Ruegg 12 years ago
parent
commit
057f19c04c
  1. 9
      src/FSharp/LinearAlgebra.Matrix.fs

9
src/FSharp/LinearAlgebra.Matrix.fs

@ -319,6 +319,12 @@ module Matrix =
/// Returns the sum of all elements of a matrix.
let inline sum (A: #Matrix<'a>) = A |> foldSkipZeros (+) Matrix<'a>.Zero
let inline sumRows (A: #Matrix<_>) = A.RowSums()
let inline sumCols (A: #Matrix<_>) = A.ColumnSums()
let inline sumAbsRows (A: #Matrix<_>) = A.RowAbsoluteSums()
let inline sumAbsCols (A: #Matrix<_>) = A.ColumnAbsoluteSums()
/// Returns the sum of the results generated by applying a position dependent function to each column of the matrix.
let inline sumColsBy f (A: #Matrix<_>) =
A.EnumerateColumnsIndexed() |> Seq.map (fun (j,col) -> f j col) |> Seq.reduce (+)
@ -337,6 +343,9 @@ module Matrix =
let inline inverse (A: #Matrix<_>) = A.Inverse()
let inline norm (A: #Matrix<_>) = A.L2Norm()
let inline normRows (A: #Matrix<_>) = A.RowNorms 2.0
let inline normCols (A: #Matrix<_>) = A.ColumnNorms 2.0
let inline rank (A: #Matrix<_>) = A.Rank()
let inline trace (A: #Matrix<_>) = A.Trace()
let inline determinant (A: #Matrix<_>) = A.Determinant()

Loading…
Cancel
Save