-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d2e9fb
commit 855e86f
Showing
5 changed files
with
87 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Math.NumberTheory.Primes.Factorisation.LinearAlgebra | ||
|
||
main :: IO () | ||
main = print $ testLinearSolver 100 0.1 | ||
main = print $ testLinearSolver 10 0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Math.NumberTheory.Primes.LinearAlgebraTests | ||
( testSuite | ||
) where | ||
|
||
import Test.Tasty | ||
import Math.NumberTheory.TestUtils | ||
import Math.NumberTheory.Primes.Factorisation.LinearAlgebra | ||
import qualified Data.List as L | ||
import qualified Data.IntSet as S | ||
import qualified Data.Vector as V | ||
import System.Random | ||
import System.IO.Unsafe | ||
import GHC.Clock | ||
|
||
testLinear :: Int -> Bool | ||
testLinear dim = dim < 2 || (mat `mult` sol == mempty) | ||
where | ||
sol = linearSolve mat | ||
mat = SBMatrix (V.fromList listOfColumns) | ||
-- -2 is arbitrary. It means that the number of rows is at most one less than | ||
-- the number of columns | ||
listOfColumns = L.take dim $ getRandomColumns [0..(dim - 2)] 0.3 $ mkStdGen $ fromIntegral $ unsafePerformIO getMonotonicTimeNSec | ||
|
||
getRandomColumns :: [Int] -> Double -> StdGen -> [SBVector] | ||
getRandomColumns rows sparsity gen = go randomEntries | ||
where | ||
randomEntries = zip (cycle rows) (randomRs (0, 1) gen) | ||
go :: [(Int, Double)] -> [SBVector] | ||
go list = newVector : go backOfList | ||
where | ||
newVector = SBVector (S.fromList listOfEntries) | ||
listOfEntries = fmap fst $ filter (\(_, rDouble) -> rDouble < sparsity) frontOfList | ||
(frontOfList, backOfList) = L.splitAt (length rows) list | ||
|
||
testSuite :: TestTree | ||
testSuite = testGroup "QuadraticSieve" | ||
[ testSmallAndQuick "LinearSolver" testLinear | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters