Convert matrix from Nemo.jl to regular Julia Array?

Here I will copy the following code snippet from this answer :

using Nemo # install with Pkg.add("Nemo") S = MatrixSpace(ZZ, 3, 4) mm = rand(-10:10,3,4) m = S(mm) (bmat,d) = nullspace(m) 

Now bmat is of type Nemo.fmpz_mat . I want to convert it to regular Julia Matrix{Int} . I tried Matrix{Int}(bmat) , but it does not work.

See also: https://github.com/wbhart/Nemo.jl/issues/57

+2
arrays julia-lang
source share
1 answer

I defined my own convert :

 function Base.convert(::Type{Matrix{Int}}, x::Nemo.fmpz_mat) m,n = size(x) mat = Int[x[i,j] for i = 1:m, j = 1:n] return mat end Base.convert(::Type{Matrix}, x::Nemo.fmpz_mat) = convert(Matrix{Int}, x) 
+3
source share

All Articles