From 53559833d2166010eed754027484fb8d5525e710 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Tue, 27 May 2014 20:21:47 +0200 Subject: expose CSR --- packages/base/src/Numeric/LinearAlgebra/Data.hs | 6 +++--- packages/base/src/Numeric/LinearAlgebra/Real.hs | 10 ++++++++++ packages/base/src/Numeric/LinearAlgebra/Util.hs | 7 +++++++ packages/base/src/Numeric/LinearAlgebra/Util/CG.hs | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) (limited to 'packages/base/src/Numeric/LinearAlgebra') diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 3417a5e..33a2c9a 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs @@ -49,8 +49,8 @@ module Numeric.LinearAlgebra.Data( find, maxIndex, minIndex, maxElement, minElement, atIndex, -- * Sparse - GMatrix, AssocMatrix, mkSparse, toDense, - mkDiagR, dense, + AssocMatrix, toDense, + mkSparse, mkDiagR, mkDense, -- * IO disp, @@ -68,7 +68,7 @@ module Numeric.LinearAlgebra.Data( module Data.Complex, - Vector, Matrix + Vector, Matrix, GMatrix, CSR(..), mkCSR ) where diff --git a/packages/base/src/Numeric/LinearAlgebra/Real.hs b/packages/base/src/Numeric/LinearAlgebra/Real.hs index db15705..1e8b544 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Real.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Real.hs @@ -141,6 +141,16 @@ instance (Num (Matrix t), Numeric t) => Num (Dim m (Dim n (Matrix t))) negate = (lift1F . lift1F) negate fromInteger x = Dim (Dim (fromInteger x)) +instance Fractional (Dim n (Vector Double)) + where + fromRational x = Dim (fromRational x) + (/) = lift2F (/) + +instance Fractional (Dim m (Dim n (Matrix Double))) + where + fromRational x = Dim (Dim (fromRational x)) + (/) = (lift2F.lift2F) (/) + -------------------------------------------------------------------------------- class Konst t diff --git a/packages/base/src/Numeric/LinearAlgebra/Util.hs b/packages/base/src/Numeric/LinearAlgebra/Util.hs index 47b1090..aee21b8 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util.hs @@ -37,6 +37,7 @@ module Numeric.LinearAlgebra.Util( mnorm_1, mnorm_2, mnorm_0, mnorm_Inf, unitary, mt, + (~!~), pairwiseD2, rowOuters, null1, @@ -65,6 +66,7 @@ import Numeric.Matrix() import Numeric.Vector() import Numeric.LinearAlgebra.Random import Numeric.LinearAlgebra.Util.Convolution +import Control.Monad(when) type ℝ = Double type ℕ = Int @@ -385,3 +387,8 @@ vtrans p m | r == 0 = fromBlocks . map (map asColumn . takesV (replicate q p)) . where (q,r) = divMod (rows m) p +-------------------------------------------------------------------------------- + +infixl 0 ~!~ +c ~!~ msg = when c (error msg) + diff --git a/packages/base/src/Numeric/LinearAlgebra/Util/CG.hs b/packages/base/src/Numeric/LinearAlgebra/Util/CG.hs index 50372f1..f821b57 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util/CG.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util/CG.hs @@ -115,7 +115,7 @@ instance Testable GMatrix sma = convo2 20 3 x1 = vect [1..20] x2 = vect [1..40] - sm = mkSparse sma + sm = (mkSparse . mkCSR) sma dm = toDense sma s1 = sm !#> x1 -- cgit v1.2.3