Skip to content

Fix warnings in second order tests #85

Closed as not planned
Closed as not planned
@gdalle

Description

@gdalle

They are caused by EnzymeAD/Enzyme.jl#1354, because we define our array-to-scalar scenarios as:

f_vector_scalar(x::AbstractVector)::Number = sum(sin, x)
f_matrix_scalar(x::AbstractMatrix)::Number = sum(sin, x)

If instead we do the following, problem solved, but it allocates:

f_vector_scalar(x::AbstractVector)::Number = sum(sin.(x))
f_matrix_scalar(x::AbstractMatrix)::Number = sum(sin.(x))

We need scalar-valued functions which

  • do not allocate
  • do not use LinearAlgebra
  • have different derivatives for every component

My suggestion would be

function f_vector_scalar(x::AbstractVector)::Number
    s = zero(eltype(x))
    for i in eachindex(x)
        s += sin(i * x[i])
    end
    return s
end

but it causes JuliaDiff/Diffractor.jl#280

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