@@ -32,13 +32,21 @@ struct mpfr_t <: AbstractFloat
3232 d:: Ptr{Limb}
3333end
3434
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)
3641
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
4250end
4351
4452set_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),
602610 end
603611end
604612
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 ))
607615 @eval begin
608616 function $fJ (p:: FTPlan{BigFloat, 1} , x:: Vector{BigFloat} )
609617 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[])
614619 return x
615620 end
616621 function $fJ (p:: AdjointFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Vector{BigFloat} ) where K
617622 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[])
622624 return x
623625 end
624626 function $fJ (p:: TransposeFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Vector{BigFloat} ) where K
625627 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[])
630629 return x
631630 end
632631 end
@@ -655,31 +654,22 @@ for (fJ, fC, elty) in ((:lmul!, :ft_bfmmf, :Float32),
655654 end
656655end
657656
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 ))
660659 @eval begin
661660 function $fJ (p:: FTPlan{BigFloat, 1} , x:: Matrix{BigFloat} )
662661 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[])
667663 return x
668664 end
669665 function $fJ (p:: AdjointFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Matrix{BigFloat} ) where K
670666 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[])
675668 return x
676669 end
677670 function $fJ (p:: TransposeFTPlan{BigFloat, FTPlan{BigFloat, 1, K}} , x:: Matrix{BigFloat} ) where K
678671 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[])
683673 return x
684674 end
685675 end
0 commit comments