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

similar(::NemoMatrix, ::Ring) does not produce Nemo matrices #1826

Closed
lgoettgens opened this issue Jul 16, 2024 · 2 comments · Fixed by Nemocas/AbstractAlgebra.jl#1890
Closed

Comments

@lgoettgens
Copy link
Collaborator

lgoettgens commented Jul 16, 2024

julia> s = matrix(QQ, 2, 2, [1,2,3,4])
[1   2]
[3   4]

julia> t = similar(s, ZZ)
[#undef   #undef]
[#undef   #undef]

julia> typeof(s)
QQMatrix

julia> typeof(t)
AbstractAlgebra.Generic.MatSpaceElem{ZZRingElem}

I would expect t to be of type dense_matrix_type(ZZ) = ZZMatrix instead.

This is due to this line in AbstractAlgebra, but I am not sure how to easily fix this.
https://github.com/Nemocas/AbstractAlgebra.jl/blob/762eab1920547d2e4c3f3e77a4976fff119bf206/src/Matrix.jl#L348
(#1791 should make it easier to fix)

@fingolfin
Copy link
Member

While dense_matrix_type(R)(R, r, c) does not currently work, this does:

parent_type(dense_matrix_type(R))(R, r, c)()

Thus we could replace

   M = Matrix{TT}(undef, (r, c))
   z = x isa MatElem ? Generic.MatSpaceElem{TT}(R, M) : Generic.MatRingElem{TT}(R, M)

by something like this, at least for now:

  if x isa MatElem
    return parent_type(dense_matrix_type(R))(R, r, c)()
  end
  M = Matrix{TT}(undef, (r, c))
  return Generic.MatRingElem{TT}(R, M)

@thofma
Copy link
Member

thofma commented Oct 17, 2024

Or zero_matrix(R, r, c), my all time favorite.

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 a pull request may close this issue.

3 participants