@@ -32,13 +32,21 @@ struct mpfr_t <: AbstractFloat
32
32
d:: Ptr{Limb}
33
33
end
34
34
35
- mpfr_t (x:: BigFloat ) = mpfr_t (x. prec, x. sign, x. exp, x. d)
35
+ """
36
+ `BigFloat` is a mutable struct and there is no guarantee that each entry in
37
+ an `Array{BigFloat}` has unique pointers. For example, looking at the `Limb`s,
38
+
39
+ Id = Matrix{BigFloat}(I, 3, 3)
40
+ map(x->x.d, Id)
36
41
37
- function BigFloat (x:: mpfr_t )
38
- nb = ccall ((:mpfr_custom_get_size ,:libmpfr ), Csize_t, (Clong,), precision (BigFloat))
39
- nb = (nb + Core. sizeof (Limb) - 1 ) ÷ Core. sizeof (Limb) # align to number of Limb allocations required for this
40
- str = unsafe_string (Ptr {UInt8} (x. d), nb * Core. sizeof (Limb))
41
- _BigFloat (x. prec, x. sign, x. exp, str)
42
+ shows that the ones and the zeros all share the same pointers. If a C function
43
+ assumes unicity of each datum, then the array must be renewed with a `deepcopy`.
44
+ """
45
+ function renew! (x:: Array{BigFloat} )
46
+ for i in eachindex (x)
47
+ @inbounds x[i] = deepcopy (x[i])
48
+ end
49
+ return x
42
50
end
43
51
44
52
set_num_threads (n:: Integer ) = ccall ((:ft_set_num_threads , libfasttransforms), Cvoid, (Cint, ), n)
@@ -602,31 +610,22 @@ for (fJ, fC, elty) in ((:lmul!, :ft_bfmvf, :Float32),
602
610
end
603
611
end
604
612
605
- for (fJ, fC) in ((:lmul! , :ft_mpfr_trmv ),
606
- (:ldiv! , :ft_mpfr_trsv ))
613
+ for (fJ, fC) in ((:lmul! , :ft_mpfr_trmv_ptr ),
614
+ (:ldiv! , :ft_mpfr_trsv_ptr ))
607
615
@eval begin
608
616
function $fJ (p:: FTPlan{BigFloat, 1} , x:: Vector{BigFloat} )
609
617
checksize (p, x)
610
- xt = deepcopy .(x)
611
- xc = mpfr_t .(xt)
612
- ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{mpfr_t}, Int32), ' N' , p. n, p, p. n, xc, Base. MPFR. ROUNDING_MODE[])
613
- x .= BigFloat .(xc)
618
+ ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{BigFloat}, Int32), ' N' , p. n, p, p. n, renew! (x), Base. MPFR. ROUNDING_MODE[])
614
619
return x
615
620
end
616
621
function $fJ (p:: AdjointFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Vector{BigFloat} ) where K
617
622
checksize (p, x)
618
- xt = deepcopy .(x)
619
- xc = mpfr_t .(xt)
620
- ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{mpfr_t}, Int32), ' T' , p. parent. n, p, p. parent. n, xc, Base. MPFR. ROUNDING_MODE[])
621
- x .= BigFloat .(xc)
623
+ ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{BigFloat}, Int32), ' T' , p. parent. n, p, p. parent. n, renew! (x), Base. MPFR. ROUNDING_MODE[])
622
624
return x
623
625
end
624
626
function $fJ (p:: TransposeFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Vector{BigFloat} ) where K
625
627
checksize (p, x)
626
- xt = deepcopy .(x)
627
- xc = mpfr_t .(xt)
628
- ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{mpfr_t}, Int32), ' T' , p. parent. n, p, p. parent. n, xc, Base. MPFR. ROUNDING_MODE[])
629
- x .= BigFloat .(xc)
628
+ ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{BigFloat}, Int32), ' T' , p. parent. n, p, p. parent. n, renew! (x), Base. MPFR. ROUNDING_MODE[])
630
629
return x
631
630
end
632
631
end
@@ -655,31 +654,22 @@ for (fJ, fC, elty) in ((:lmul!, :ft_bfmmf, :Float32),
655
654
end
656
655
end
657
656
658
- for (fJ, fC) in ((:lmul! , :ft_mpfr_trmm ),
659
- (:ldiv! , :ft_mpfr_trsm ))
657
+ for (fJ, fC) in ((:lmul! , :ft_mpfr_trmm_ptr ),
658
+ (:ldiv! , :ft_mpfr_trsm_ptr ))
660
659
@eval begin
661
660
function $fJ (p:: FTPlan{BigFloat, 1} , x:: Matrix{BigFloat} )
662
661
checksize (p, x)
663
- xt = deepcopy .(x)
664
- xc = mpfr_t .(xt)
665
- ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{mpfr_t}, Cint, Cint, Int32), ' N' , p. n, p, p. n, xc, size (x, 1 ), size (x, 2 ), Base. MPFR. ROUNDING_MODE[])
666
- x .= BigFloat .(xc)
662
+ ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{BigFloat}, Cint, Cint, Int32), ' N' , p. n, p, p. n, renew! (x), size (x, 1 ), size (x, 2 ), Base. MPFR. ROUNDING_MODE[])
667
663
return x
668
664
end
669
665
function $fJ (p:: AdjointFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Matrix{BigFloat} ) where K
670
666
checksize (p, x)
671
- xt = deepcopy .(x)
672
- xc = mpfr_t .(xt)
673
- ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{mpfr_t}, Cint, Cint, Int32), ' T' , p. parent. n, p, p. parent. n, xc, size (x, 1 ), size (x, 2 ), Base. MPFR. ROUNDING_MODE[])
674
- x .= BigFloat .(xc)
667
+ ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{BigFloat}, Cint, Cint, Int32), ' T' , p. parent. n, p, p. parent. n, renew! (x), size (x, 1 ), size (x, 2 ), Base. MPFR. ROUNDING_MODE[])
675
668
return x
676
669
end
677
670
function $fJ (p:: TransposeFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Matrix{BigFloat} ) where K
678
671
checksize (p, x)
679
- xt = deepcopy .(x)
680
- xc = mpfr_t .(xt)
681
- ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{mpfr_t}, Cint, Cint, Int32), ' T' , p. parent. n, p, p. parent. n, xc, size (x, 1 ), size (x, 2 ), Base. MPFR. ROUNDING_MODE[])
682
- x .= BigFloat .(xc)
672
+ ccall (($ (string (fC)), libfasttransforms), Cvoid, (Cint, Cint, Ptr{mpfr_t}, Cint, Ptr{BigFloat}, Cint, Cint, Int32), ' T' , p. parent. n, p, p. parent. n, renew! (x), size (x, 1 ), size (x, 2 ), Base. MPFR. ROUNDING_MODE[])
683
673
return x
684
674
end
685
675
end
0 commit comments