-
Notifications
You must be signed in to change notification settings - Fork 81
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
Introduce bitMatrix to replace mat.Dense #33
Conversation
As requested, this PR also replaces gonum now. It would have been nice to measure the impact with benchmarks but we already know the ballpark of improvment (see #22). |
2d7373d
to
945314b
Compare
945314b
to
c1330f1
Compare
…minor refactoring
c1330f1
to
7346cfe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to use big.Int
as the backing type instead of a []uint64
?
func TestFuzzTestBlockRecovery(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), time.Second*10)
for {
select {
case <-ctx.Done():
return
default:
TestBlockRecovery(t)
}
}
}
edit: see below comment, the square was being repaired fine, but an error was being returned along with the properly repaired square. |
extendeddatacrossword.go
Outdated
if solved { | ||
break | ||
} else if !progressMade { | ||
if !progressMade { | ||
return ErrUnrepairableDataSquare | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I think this is issue for the failing lazyledger-core test mentioned in the other comment, the square is being repaired fine, but an error is being returned. Reverting this change allows for the other tests to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!! I'll revert these changes in the for-loop here. They are orthogonal to the bit-mask anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 3eca580.
I'll retest with the above test to make sure that this fixed the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative could be to change that if-else-if to: if !progressMade && !solved
(or !(progressMade || solved)
) and make the for loop for !solved
. That should be equivalent. I think the for-loop would be easier to grasp directly as "repeat until solved". Currently, you either trust the comment Keep repeating until the square is solved
or you have to scroll 105 complex looking lines of code to make sure that this what is indeed happening: https://github.com/lazyledger/rsmt2d/blob/master/extendeddatacrossword.go#L92-L207
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, thanks for finding that issue and for pointing me to the solution even :-)
Is there a good reason to use bigInt instead? With big.Int can not directly operate on the underlying
Then, big.Int is signed which do not need. Using big.Int is possible but it would just make the code more difficult to read imo. |
@@ -16,7 +16,7 @@ type dataSquare struct { | |||
|
|||
func newDataSquare(data [][]byte, treeCreator TreeConstructorFn) (*dataSquare, error) { | |||
width := int(math.Ceil(math.Sqrt(float64(len(data))))) | |||
if int(math.Pow(float64(width), 2)) != len(data) { | |||
if width*width != len(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've sneaked in another unrelated change here: int(math.Pow(float64(width), 2))
is just a complicated way of computing width*width
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw that, and approve.
can someone with write access approve the PR (or request changes): cc @musalbas @evan-forbes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome 👍 👍
This PR introduces a structure that replaces mat.Dense and gets rid of the gonum dependency.
Hence, it is half the story ofcloses #22.It could use some light fuzzing but given that this is essentially a simple bit-mask I don't think that is urgent.
Can open a separate PR to actually use the structure, or, replace mat.Dense in here.