Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DualCache doesn't work for BigFloat? #72

Closed
JianghuiDu opened this issue Sep 3, 2023 · 2 comments
Closed

DualCache doesn't work for BigFloat? #72

JianghuiDu opened this issue Sep 3, 2023 · 2 comments

Comments

@JianghuiDu
Copy link

Using the example on the website but change to BigFloat

using ForwardDiff, PreallocationTools
randmat = big.(rand(5, 3))
sto = similar(randmat)
stod = DiffCache(sto)

function claytonsample!(sto, τ, α; randmat = randmat)
    sto = get_tmp(sto, τ)
    sto .= randmat
    τ == zero(eltype(sto)) && return sto

    n = size(sto, 1)
    for i in 1:n
        v = sto[i, 2]
        u = sto[i, 1]
        sto[i, 1] = (1 - u^(-τ) + u^(-τ) * v^(-/ (1 + τ))))^(-1 / τ) * α
        sto[i, 2] = (1 - u^(-τ) + u^(-τ) * v^(-/ (1 + τ))))^(-1 / τ)
    end
    return sto
end

ForwardDiff.derivative-> claytonsample!(stod, τ, big(0.0)), big(0.3))

Throws error:

ERROR: ArgumentError: cannot reinterpret `BigFloat`
as `ForwardDiff.Dual{ForwardDiff.Tag{var"#61#62", Bi
gFloat}, BigFloat, 1}`, type `ForwardDiff.Dual{Forwa
rdDiff.Tag{var"#61#62", BigFloat}, BigFloat, 1}` is
not a bits type
Stacktrace:
 [1] (::Base.var"#throwbits#323")(S::Type, T::Type,
U::Type)
   @ Base .\reinterpretarray.jl:16
 [2] reinterpret(#unused#::Type{ForwardDiff.Dual{For
wardDiff.Tag{var"#61#62", BigFloat}, BigFloat, 1}},
a::SubArray{BigFloat, 1, Vector{BigFloat}, Tuple{Uni
tRange{Int64}}, true})
   @ Base .\reinterpretarray.jl:62
 [3] get_tmp(dc::DiffCache{Matrix{BigFloat}, Vector{
BigFloat}}, u::ForwardDiff.Dual{ForwardDiff.Tag{var"
#61#62", BigFloat}, BigFloat, 1})
   @ PreallocationTools C:\Users\Jianghui\.julia\pac
kages\PreallocationTools\nhCNl\src\PreallocationTool
s.jl:120
 [4] claytonsample!(sto::DiffCache{Matrix{BigFloat},
 Vector{BigFloat}}, τ::ForwardDiff.Dual{ForwardDiff.
Tag{var"#61#62", BigFloat}, BigFloat, 1}, α::BigFloa
t; randmat::Matrix{BigFloat})
   @ Main c:\Users\Jianghui\Documents\Manuscripts\Ha
waiiREE\model\DOM\REE\main.HawaiiREEDOC.jl:437
 [5] claytonsample!(sto::DiffCache{Matrix{BigFloat},
 Vector{BigFloat}}, τ::ForwardDiff.Dual{ForwardDiff.
Tag{var"#61#62", BigFloat}, BigFloat, 1}, α::BigFloa
t)
   @ Main c:\Users\Jianghui\Documents\Manuscripts\Ha
waiiREE\model\DOM\REE\main.HawaiiREEDOC.jl:436
 [6] (::var"#61#62")(τ::ForwardDiff.Dual{ForwardDiff
.Tag{var"#61#62", BigFloat}, BigFloat, 1})
   @ Main c:\Users\Jianghui\Documents\Manuscripts\Ha
waiiREE\model\DOM\REE\main.HawaiiREEDOC.jl:451
 [7] derivative(f::var"#61#62", x::BigFloat)
   @ ForwardDiff C:\Users\Jianghui\.julia\packages\F
orwardDiff\PcZ48\src\derivative.jl:14
 [8] top-level scope
   @ c:\Users\Jianghui\Documents\Manuscripts\HawaiiR
EE\model\DOM\REE\main.HawaiiREEDOC.jl:451
@ChrisRackauckas ChrisRackauckas changed the title Doesn't work for BigFloat? DualCache doesn't work for BigFloat? Sep 3, 2023
@ChrisRackauckas
Copy link
Member

Yes DualCache needs bitstypes. FixedSizeDiffCache and LazyBufferCache should be fine with BigFloat though. Since BigFloat always allocates it's a little silly to cache it though.

@ChrisRackauckas
Copy link
Member

Fixed with #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants