Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary Linear Algebra #208

Merged
merged 59 commits into from
Aug 5, 2020
Merged

Binary Linear Algebra #208

merged 59 commits into from
Aug 5, 2020

Conversation

federico-bongiorno
Copy link
Contributor

An implementation of sparse binary vectors and matrices with linear algebra solver.

Copy link
Owner

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase your branch atop of master.

Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
app/LinearAlgebra.hs Outdated Show resolved Hide resolved
Copy link
Owner

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check that time grows proportionally to n^2, benchmarking matrices of growing sizes? If this is the case, then having a large constant factor is eventually manageable, but if it is not so, we are in a bigger trouble.

Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
@Bodigrim
Copy link
Owner

Bodigrim commented Jul 18, 2020

There is a couple of hlint suggestions: https://travis-ci.org/github/Bodigrim/arithmoi/jobs/709224118#L1018

@Bodigrim
Copy link
Owner

And one more thing to make Travis build happy: add mod-0.1.2.0 to extra-deps in stack-8.8.3.yaml.

@Bodigrim
Copy link
Owner

Continuing our discussion elsewhere. The current submission does not eat all the RAM. Yes, allocating 5 millions of (Integer, SignedPrimeIntSet) takes quite a lot of space, more than 500 Mb, but it works fine (and returns correct answer) with 2 Gb limit.

While you generate sievingInterval of length 5000000 further computations operate over much smaller subset of smooth numbers, about 30000 elements. Instead of sieving 5000000 elements in one go (which causes a spike in memory allocations and does not scale), you can take first 10^5 values, sieve out non-smooth ones, than take next 10^5 elements and sieve them, etc., concatenating smooth vectors together.

Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/LinearAlgebra.hs Outdated Show resolved Hide resolved
Math/NumberTheory/Primes/Factorisation/QuadraticSieve.hs Outdated Show resolved Hide resolved
go lowerIndex upperIndex allItems@(item : otherItems) vector = case item `compare` entry of
LT -> go lowerIndex (currentIndex - 1) allItems vector
-- @(currentIndex + 1)@ makes sure no prime number index is 0
-- 0 is reserved for negative numbers
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really unexpected semantics for a function, named binarySearch. If users of this function need indices starting from 1, they can apply map (+1) themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment to explain it better. Suppose I have Prime 2, Prime 3 and Prime 5. I want to send them respectively to 1,2,3. I use 0 to when the number is negative (its sign is true).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it clearer 30 would be given by [1,2,3] whereas -30 by [0,1,2,3].

Math/NumberTheory/Primes/Factorisation/QuadraticSieve.hs Outdated Show resolved Hide resolved
@Bodigrim Bodigrim merged commit d6653e6 into Bodigrim:master Aug 5, 2020
@Bodigrim
Copy link
Owner

Bodigrim commented Aug 5, 2020

Yay! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants