-
Notifications
You must be signed in to change notification settings - Fork 134
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
Make Lie algebra construction faster #3937
Make Lie algebra construction faster #3937
Conversation
@@ -21,7 +23,13 @@ | |||
|
|||
R = new(mat) | |||
R.positive_roots = map(r -> RootSpaceElem(R, r), pos_roots) | |||
R.positive_roots_map = Dict( | |||
(coefficients(root), ind) for (ind, root) in enumerate(R.positive_roots::Vector{RootSpaceElem}) | |||
) |
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.
pre-computing this and using this in is_root
instead of a linear search is the main speed improvement of this PR
@@ -438,13 +450,13 @@ function Base.:(*)(q::RationalUnion, r::RootSpaceElem) | |||
end | |||
|
|||
function Base.:(+)(r::RootSpaceElem, r2::RootSpaceElem) | |||
@req root_system(r) === root_system(r2) "$r and $r2 must belong to the same root space" | |||
@req root_system(r) === root_system(r2) "parent root system mismatch" |
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.
these strings get interpolated even in the case that no error is thrown. Withouth string interpolation, there is basically no overhead
@@ -104,6 +114,10 @@ end | |||
return cartan_bilinear_form(cartan_matrix(R); check=false) | |||
end | |||
|
|||
@attr QQMatrix function bilinear_form_QQ(R::RootSystem) |
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 think something like
@attr QQMatrix function bilinear_form_QQ(R::RootSystem) | |
@attr QQMatrix function bilinear_form(::QQField, R::RootSystem) |
would be more OSCAR-y?
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.
Yeah, but this does not allow @attr
to work. Furthermore, this is just supposed to be internal
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 renamed it now to _bilinear_form_QQ
to make it more visible that its internal
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3937 +/- ##
==========================================
+ Coverage 83.99% 84.00% +0.01%
==========================================
Files 591 591
Lines 81387 81440 +53
==========================================
+ Hits 68360 68417 +57
+ Misses 13027 13023 -4
|
d88ff62
to
da9ffd0
Compare
da9ffd0
to
a5298fe
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.
Looks good, thanks.
@@ -274,7 +288,7 @@ This is a more efficient version for `positive_coroots(R)[i]`. | |||
Also see: `positive_coroots`. | |||
""" | |||
function positive_coroot(R::RootSystem, i::Int) | |||
return R.positive_coroots[i]::DualRootSpaceElem | |||
return (R.positive_coroots::Vector{DualRootSpaceElem})[i] |
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.
How about this to avoid the repeated type annotations? (But I am fine with this either way)
return (R.positive_coroots::Vector{DualRootSpaceElem})[i] | |
return positive_coroots(R)[i] |
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.
for the positive (co)roots this indeed works. For the negative ones, however, this is not optimal as it would first negate all positive roots to then only take one of them. And I rather have positive and negative consistent here.
i = get(root_system(r).positive_coroots_map, coefficients(r), nothing) | ||
if isnothing(i) | ||
return false, 0 | ||
else | ||
return true, i | ||
end |
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.
Obv. this is existing code, and it is fine, but just as food for thought:
i = get(root_system(r).positive_coroots_map, coefficients(r), nothing) | |
if isnothing(i) | |
return false, 0 | |
else | |
return true, i | |
end | |
i = get(root_system(r).positive_coroots_map, coefficients(r), 0) | |
return !is_zero(i), i |
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.
will be included in the next round of refactoring :)
Follow-up to #3831 that implements some performance improvements and fixes some type instabilities and other issues reported by JET.
The following diagram shows the enormous improvement. In particular, we are now almost a third faster than GAP for all of these test cases.
created using: