Skip to content

getting error in FiniteDifferences.to_vec when test_rrule for structured type #258

Description

@vpuri3
mutable struct Mat{AType<:AbstractMatrix}
    A::AType
    trait::Bool
end
Mat(A::AbstractMatrix) = Mat(A, false)

Base.adjoint(M::Mat) = Mat(M.A')
Base.:*(M::Mat, u::AbstractVector) = M.A * u

function ChainRulesCore.rrule(::typeof(*), M::Mat, u::AbstractVector)
    project_u = ProjectTo(u)

    function pb(dv)
        du = @thunk(project_u( M' * dv ))
        dA = @thunk(project_p( dv * u' ))

        dM = Tangent{Mat}(;A=dA)

        NoTangent(), dM, du
    end

    M*u, pb
end

In this case, test_rrule attempts to perturb the boolean trait causing this error:

Random.seed!(0)
N = 8

M = Mat(rand(N,N), false)
u = rand(N)
test_rrule(*, M, u)
est_rrule: * on Mat{Matrix{Float64}},Vector{Float64}: Error During Test at /Users/vp
/.julia/packages/ChainRulesTestUtils/2VT4F/src/testers.jl:193                        
  Got exception outside of a @test                                                   
  TypeError: non-boolean (Float64) used in boolean context                           
  Stacktrace:                                                                        
    [1] macro expansion
      @ ~/.julia/packages/FiniteDifferences/VpgIT/src/to_vec.jl:0 [inlined]
    [2] _force_construct
      @ ~/.julia/packages/FiniteDifferences/VpgIT/src/to_vec.jl:27 [inlined]

...

  caused by: InexactError: Bool(-0.01)                                               
  Stacktrace:                                                                        
    [1] Bool                                                                         
      @ ./float.jl:158 [inlined]                                                     

...

Test Summary:                                         | Pass  Error  Total  Time
test_rrule: * on Mat{Matrix{Float64}},Vector{Float64} |    3      1      4  5.3s
ERROR: LoadError: Some tests did not pass: 3 passed, 0 failed, 1 errored, 0 broken.
in expression starting at /Users/vp/.julia/dev/smo_adj/test/f3.jl:46

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions