1
0
mirror of https://github.com/kalmarek/SmallHyperbolic synced 2024-11-23 23:40:28 +01:00

integrate precision into Acb

This commit is contained in:
kalmarek 2020-05-15 14:52:36 +02:00
parent c62d59811f
commit d9bb982c84
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15

View File

@ -43,11 +43,13 @@ const libarb = Nemo.libarb
mutable struct AcbVector <: AbstractVector{acb_struct} mutable struct AcbVector <: AbstractVector{acb_struct}
ptr::Ptr{acb_struct} ptr::Ptr{acb_struct}
length::Int length::Int
precision::Int
function AcbVector(n::Int) function AcbVector(n::Integer, precision::Integer)
v = new( v = new(
ccall((:_acb_vec_init, libarb), Ptr{acb_struct}, (Clong,), n), ccall((:_acb_vec_init, libarb), Ptr{acb_struct}, (Clong,), n),
n, n,
precision
) )
finalizer(clear!, v) finalizer(clear!, v)
return v return v
@ -56,6 +58,7 @@ end
Base.cconvert(::Type{Ptr{acb_struct}}, acb_v::AcbVector) = acb_v.ptr Base.cconvert(::Type{Ptr{acb_struct}}, acb_v::AcbVector) = acb_v.ptr
Base.size(acb_v::AcbVector) = (acb_v.length,) Base.size(acb_v::AcbVector) = (acb_v.length,)
Base.precision(acb_v::AcbVector) = acb_v.precision
function clear!(acb_v::AcbVector) function clear!(acb_v::AcbVector)
ccall( ccall(
@ -67,22 +70,16 @@ function clear!(acb_v::AcbVector)
) )
end end
function (C::AcbField)(z::acb_struct)
res = zero(C)
ccall((:acb_set, libarb), Cvoid, (Ref{acb}, Ref{acb_struct}), res, z)
return res
end
_get_ptr(acb_v::AcbVector, i::Int = 1) =
acb_v.ptr + (i - 1) * sizeof(acb_struct)
Base.@propagate_inbounds function Base.getindex(acb_v::AcbVector, i::Integer) Base.@propagate_inbounds function Base.getindex(acb_v::AcbVector, i::Integer)
@boundscheck checkbounds(acb_v, i) @boundscheck checkbounds(acb_v, i)
return unsafe_load(acb_v.ptr, i) return unsafe_load(acb_v.ptr, i)
end end
function AcbVector(v::AbstractVector{Nemo.acb}) _get_ptr(acb_v::AcbVector, i::Int = 1) =
acb_v = AcbVector(length(v)) acb_v.ptr + (i - 1) * sizeof(acb_struct)
function AcbVector(v::AbstractVector{Nemo.acb}, p = prec(parent(first(v))))
acb_v = AcbVector(length(v), p)
for (i, val) in zip(eachindex(acb_v), v) for (i, val) in zip(eachindex(acb_v), v)
ccall( ccall(
(:acb_set, libarb), (:acb_set, libarb),
@ -96,7 +93,6 @@ function AcbVector(v::AbstractVector{Nemo.acb})
end end
function approx_eig_qr!(v::AcbVector, R::acb_mat, A::acb_mat) function approx_eig_qr!(v::AcbVector, R::acb_mat, A::acb_mat)
n = nrows(A)
ccall( ccall(
(:acb_mat_approx_eig_qr, Nemo.libarb), (:acb_mat_approx_eig_qr, Nemo.libarb),
Cint, Cint,
@ -120,13 +116,21 @@ function approx_eig_qr!(v::AcbVector, R::acb_mat, A::acb_mat)
return v return v
end end
function (C::AcbField)(z::acb_struct)
res = zero(C)
ccall((:acb_set, libarb), Cvoid, (Ref{acb}, Ref{acb_struct}), res, z)
return res
end
function LinearAlgebra.eigvals(A::Nemo.acb_mat) function LinearAlgebra.eigvals(A::Nemo.acb_mat)
n = nrows(A) n = nrows(A)
λ_approx = AcbVector(n) CC = base_ring(A)
p = prec(CC)
λ_approx = AcbVector(n, p)
R_approx = similar(A) R_approx = similar(A)
v = approx_eig_qr!(λ_approx, R_approx, A) v = approx_eig_qr!(λ_approx, R_approx, A)
λ = AcbVector(n) λ = AcbVector(n, p)
b = ccall( b = ccall(
(:acb_mat_eig_multiple, Nemo.libarb), (:acb_mat_eig_multiple, Nemo.libarb),
Cint, Cint,
@ -135,10 +139,9 @@ function LinearAlgebra.eigvals(A::Nemo.acb_mat)
A, A,
λ_approx, λ_approx,
R_approx, R_approx,
prec(base_ring(A)), p,
) )
CC = base_ring(A)
return CC.(λ) return CC.(λ)
end end