-
Notifications
You must be signed in to change notification settings - Fork 58
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
Optimize mat_entry_ptr methods #1871
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1010,9 +1010,7 @@ end | |||||
# | ||||||
################################################################################ | ||||||
|
||||||
@inline mat_entry_ptr(A::QQMatrix, i::Int, j::Int) = | ||||||
ccall((:fmpq_mat_entry, libflint), | ||||||
Ptr{QQFieldElem}, (Ref{QQMatrix}, Int, Int), A, i-1, j-1) | ||||||
mat_entry_ptr(A::QQMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*2*sizeof(Ptr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
################################################################################ | ||||||
# | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2107,4 +2107,4 @@ end | |||||
# | ||||||
################################################################################ | ||||||
|
||||||
@inline mat_entry_ptr(A::ZZMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(UInt) | ||||||
mat_entry_ptr(A::ZZMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(Ptr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -900,6 +900,4 @@ end | |||||
# | ||||||
################################################################################ | ||||||
|
||||||
@inline mat_entry_ptr(A::ZZModMatrix, i::Int, j::Int) = | ||||||
ccall((:fmpz_mod_mat_entry, libflint), Ptr{ZZRingElem}, | ||||||
(Ref{ZZModMatrix}, Int, Int), A, i - 1, j - 1) | ||||||
mat_entry_ptr(A::ZZModMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(Ptr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -764,6 +764,4 @@ end | |||||||||||||||||
# | ||||||||||||||||||
################################################################################ | ||||||||||||||||||
|
||||||||||||||||||
@inline mat_entry_ptr(A::FqPolyRepMatrix, i::Int, j::Int) = | ||||||||||||||||||
ccall((:fq_mat_entry, libflint), Ptr{FqPolyRepFieldElem}, | ||||||||||||||||||
(Ref{FqPolyRepMatrix}, Int, Int), A, i - 1, j - 1) | ||||||||||||||||||
mat_entry_ptr(A::FqPolyRepMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*(sizeof(Ptr)+2*sizeof(Int)) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing, perhaps I should add a comment
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -753,6 +753,4 @@ end | |||||||||||||||||||||||
# | ||||||||||||||||||||||||
################################################################################ | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
@inline mat_entry_ptr(A::fqPolyRepMatrix, i::Int, j::Int) = | ||||||||||||||||||||||||
ccall((:fq_nmod_mat_entry, libflint), Ptr{fqPolyRepFieldElem}, | ||||||||||||||||||||||||
(Ref{fqPolyRepMatrix}, Int, Int), A, i - 1, j - 1) | ||||||||||||||||||||||||
mat_entry_ptr(A::fqPolyRepMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*(sizeof(Ptr)+5*sizeof(Int)) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -457,6 +457,4 @@ end | |||||
# | ||||||
################################################################################ | ||||||
|
||||||
@inline mat_entry_ptr(A::FpMatrix, i::Int, j::Int) = | ||||||
ccall((:fmpz_mod_mat_entry, libflint), Ptr{ZZRingElem}, | ||||||
(Ref{FpMatrix}, Int, Int), A, i - 1, j - 1) | ||||||
mat_entry_ptr(A::FpMatrix, i::Int, j::Int) = unsafe_load(A.rows, i) + (j-1)*sizeof(Ptr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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 this is not 100% true, since otherwise I would expect the following to work (before this PR, with htis PR the Ptr conversion becomes unnecessary):
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.
It definitely is a lie, just like with many other
Ptr{ZZRingElem}
etc. etc. in our code base -- our Julia types are "supersets" of the FLINT types.BTW you can get the same crash in
master
viaunsafe_load(Nemo.mat_entry_ptr(a, 1, 1))
. I simply chose the signatures here to make the implementation ofmat_entry_ptr
as simple as possible for each type.We could of course also resolve this by adding a separate struct
fq_nmod_t
(andfmpz_t
etc. etc.) which faithfully replicate the FLINT structs, nothing more and nothing less. Then e.g.fqPolyRepFieldElem
could start with a memberx:: fq_nmod_t
.That way, we could resolve all the lies everywhere. But that would be a major piece of work for relatively limited gain (if I were to start Nemo today, that's more or less what I'd do anyway, but as it is now...).
Anyway: I am happy to discuss this further, but I think for the purpose of this PR, it doesn't really make anything worse, as nothing in Nemo.jl ever accesses
.entries
fields, and the access to.rows
is limited to very, very few places. And to me at least it was helpful to get a better idea of what eachentries
androws
points to. But I am also ok with changing them back toNothing
and adjust themat_entry_ptr
to insert suitablereinterpret
calls.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.
Thanks for the explanation. I am fine with merging this. Could you open an issue with basically what you explained here, so that we keep it somewhere? (even though that's nothing to be changed in the near future (unless someone has way too much time))