Skip to content

Commit 9ed86c2

Browse files
committed
nfloat: Proof of concept wrapping of new nfloat module in Flint
1 parent 32d7585 commit 9ed86c2

File tree

10 files changed

+506
-14
lines changed

10 files changed

+506
-14
lines changed

src/ArbCall/ArbArgTypes.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Struct for conversion between C argument types in the Arb
99
documentation and Julia types.
1010
"""
1111
struct ArbArgTypes
12-
supported::Dict{String,DataType}
12+
supported::Dict{String,Union{DataType,UnionAll}}
1313
unsupported::Set{String}
14-
supported_reversed::Dict{DataType,String}
14+
supported_reversed::Dict{Union{DataType,UnionAll},String}
1515
end
1616

1717
function Base.getindex(arbargtypes::ArbArgTypes, key::AbstractString)
@@ -22,7 +22,7 @@ end
2222

2323
# Define the conversions we use for the rest of the code
2424
const arbargtypes = ArbArgTypes(
25-
Dict{String,DataType}(
25+
Dict{String,Union{DataType,UnionAll}}(
2626
"void" => Cvoid,
2727
"void *" => Ptr{Cvoid},
2828
"int" => Cint,
@@ -37,6 +37,9 @@ const arbargtypes = ArbArgTypes(
3737
"arb_t" => Arb,
3838
"acb_t" => Acb,
3939
"mag_t" => Mag,
40+
"nfloat_ptr" => NFloat,
41+
"nfloat_srcptr" => NFloat,
42+
"gr_ctx_t" => nfloat_ctx_struct,
4043
"arb_srcptr" => ArbVector,
4144
"arb_ptr" => ArbVector,
4245
"acb_srcptr" => AcbVector,
@@ -54,7 +57,7 @@ const arbargtypes = ArbArgTypes(
5457
"ulong *" => Vector{UInt},
5558
),
5659
Set(["FILE *", "fmpr_t", "fmpr_rnd_t", "flint_rand_t", "bool_mat_t"]),
57-
Dict{DataType,String}(
60+
Dict{Union{DataType,UnionAll},String}(
5861
Cvoid => "void",
5962
Ptr{Cvoid} => "void *",
6063
Cint => "int",
@@ -69,6 +72,8 @@ const arbargtypes = ArbArgTypes(
6972
Arb => "arb_t",
7073
Acb => "acb_t",
7174
Mag => "mag_t",
75+
NFloat => "nfloat_ptr",
76+
nfloat_ctx_struct => "gr_ctx_t",
7277
ArbVector => "arb_ptr",
7378
AcbVector => "acb_ptr",
7479
ArbPoly => "arb_poly_t",

src/ArbCall/ArbCall.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import ..Arblib:
1212
cstructtype,
1313
arb_rnd,
1414
mag_struct,
15+
nfloat_struct,
16+
nfloat_ctx_struct,
17+
_get_nfloat_ctx_struct,
1518
arf_struct,
1619
acf_struct,
1720
arb_struct,
@@ -23,6 +26,7 @@ import ..Arblib:
2326
arb_mat_struct,
2427
acb_mat_struct,
2528
MagLike,
29+
NFloatLike,
2630
ArfLike,
2731
AcfLike,
2832
ArbLike,

src/ArbCall/ArbFunction.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const jlfname_prefixes = (
6969
"arb",
7070
"acb",
7171
"mag",
72+
"nfloat",
73+
"ctx",
7274
"mat",
7375
"vec",
7476
"poly",
@@ -78,7 +80,7 @@ const jlfname_prefixes = (
7880
"cdouble",
7981
)
8082
const jlfname_suffixes =
81-
("si", "ui", "d", "mag", "arf", "acf", "arb", "acb", "mpz", "mpfr", "str")
83+
("si", "ui", "d", "mag", "nfloat", "arf", "acf", "arb", "acb", "mpz", "mpfr", "str")
8284

8385
function jlfname(
8486
arbfname::AbstractString;
@@ -146,6 +148,8 @@ function jlargs(af::ArbFunction; argument_detection::Bool = true)
146148
push!(kwargs, extract_rounding_argument(carg))
147149
elseif i > 1 && is_length_argument(carg, cargs[i-1])
148150
push!(kwargs, extract_length_argument(carg, cargs[i-1]))
151+
elseif is_ctx_argument(carg)
152+
push!(kwargs, extract_ctx_argument(carg, first(cargs)))
149153
else
150154
push!(jl_arg_names_types, (name(carg), jltype(carg)))
151155
end

src/ArbCall/Carg.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jltype(::Carg{Vector{UInt}}) = Vector{<:Unsigned}
6969
jltype(::Carg{Vector{Float64}}) = Vector{<:Base.GMP.CdoubleMax}
7070
jltype(::Carg{Vector{ComplexF64}}) = Vector{<:Union{ComplexF16,ComplexF32,ComplexF64}}
7171
jltype(::Carg{Mag}) = MagLike
72+
jltype(::Carg{NFloat}) = NFloatLike
7273
jltype(::Carg{Arf}) = ArfLike
7374
jltype(::Carg{Acf}) = AcfLike
7475
jltype(::Carg{Arb}) = ArbLike
@@ -92,6 +93,8 @@ ctype(::Carg{T}) where {T<:Union{Mag,Arf,Acf,Arb,Acb,ArbPoly,AcbPoly,ArbMatrix,A
9293
Ref{cstructtype(T)}
9394
ctype(::Carg{T}) where {T<:Union{BigFloat,BigInt}} = Ref{T}
9495
ctype(::Carg{Vector{T}}) where {T} = Ref{T}
96+
ctype(::Carg{T}) where {T<:NFloat} = Ref{nfloat_struct}
97+
ctype(::Carg{T}) where {T<:nfloat_ctx_struct} = Ref{nfloat_ctx_struct}
9598

9699
is_precision_argument(ca::Carg) = ca == Carg{Int}(:prec, false)
97100

@@ -105,6 +108,8 @@ is_length_argument(ca::Carg, prev_ca::Carg) =
105108
rawtype(ca) == Int &&
106109
rawtype(prev_ca) (ArbVector, AcbVector)
107110

111+
is_ctx_argument(ca::Carg{T}) where {T} = T <: nfloat_ctx_struct
112+
108113
function extract_precision_argument(ca::Carg, first_ca::Carg)
109114
is_precision_argument(ca) ||
110115
throw(ArgumentError("argument is not a valid precision argument, $ca"))
@@ -143,6 +148,18 @@ function extract_length_argument(ca::Carg, prev_ca::Carg)
143148
return Expr(:kw, :($(name(ca))::Integer), :(length($(name(prev_ca)))))
144149
end
145150

151+
# TODO: This needs to handle the case when it is not the first
152+
# argument we should get the context from. This happens for e.g.
153+
# nfloat_get_arf.
154+
function extract_ctx_argument(ca::Carg, first_ca::Carg)
155+
is_ctx_argument(ca) || throw(ArgumentError("argument is not a valid ctx argument, $ca"))
156+
return Expr(
157+
:kw,
158+
:($(name(ca))::nfloat_ctx_struct),
159+
:(_get_nfloat_ctx_struct($(name(first_ca)))),
160+
)
161+
end
162+
146163
"""
147164
is_fpwrap_res_argument(ca::Carg, T::Union{Float64,ComplexF64})
148165

src/ArbCall/parse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ function parse_and_generate_arbdoc(
192192
out_dir = "src/arbcalls/";
193193
filenames = [
194194
"mag",
195+
"nfloat",
195196
"arf",
196197
"acf",
197198
"arb",

src/Arblib.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ include("types.jl")
5454
include("hash.jl")
5555
include("serialize.jl")
5656

57+
include("nfloat.jl")
58+
5759
include("ArbCall/ArbCall.jl")
5860
import .ArbCall: @arbcall_str, @arbfpwrapcall_str
5961
include("manual_overrides.jl")
@@ -84,6 +86,7 @@ include("calc_integrate.jl")
8486
include("special-functions.jl")
8587

8688
include("arbcalls/mag.jl")
89+
include("arbcalls/nfloat.jl")
8790
include("arbcalls/arf.jl")
8891
include("arbcalls/acf.jl")
8992
include("arbcalls/arb.jl")

0 commit comments

Comments
 (0)