Skip to content
2 changes: 1 addition & 1 deletion ext/MeshIntegralsEnzymeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.Geometry}) = true
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.Domain}) = true
# except for those that throw errors (see GitHub Issue #154)
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.BezierCurve}) = false
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.CylinderSurface}) = false
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.Cylinder}) = false
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.CylinderSurface}) = false
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.ParametrizedCurve}) = false

end
62 changes: 39 additions & 23 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ end

@testitem "Utilities" setup=[Utils] begin
# _KVector
v = Meshes.Vec(3, 4)
@test norm(MeshIntegrals._KVector(v)) ≈ 5.0u"m"
let v = Meshes.Vec(3, 4)
@test norm(MeshIntegrals._KVector(v)) ≈ 5.0u"m"
end

# _units
p = Point(1.0u"cm", 2.0u"mm", 3.0u"m")
@test _units(p) == u"m"
let p = Point(1.0u"cm", 2.0u"mm", 3.0u"m")

@test _units(p) == u"m"
end

# _zeros
@test _zeros(2) == (0.0, 0.0)
Expand All @@ -25,37 +28,50 @@ end
@test _ones(Float32, 2) == (1.0f0, 1.0f0)
end

@testitem "Differentiation (EnzymeExt loaded)" setup=[Utils] begin
# supports_autoenzyme(::Type{<:Any})
@test MeshIntegrals.supports_autoenzyme(Nothing) == false

# _default_diff_method -- using type or instance, Enzyme-supported combination
@testitem "Differentiation (MeshIntegralsEnzymeExt loaded)" setup=[Utils] begin
# supports_autoenzyme & _default_diff_method
# Nominal usage: Enzyme-supported geometry and FP type
let sphere = Sphere(Point(0, 0, 0), 1.0)
@test _default_diff_method(Meshes.Sphere, Float64) isa AutoEnzyme
@test _default_diff_method(sphere, Float64) isa AutoEnzyme
end

# _default_diff_method -- Enzyme-unsupported FP types
# supports_autoenzyme(::Type{<:Any}) for CI completeness
@test MeshIntegrals.supports_autoenzyme(Nothing) == false
# BezierCurve: blocked by upstream Meshes-Enzyme incompatibility
let curve = BezierCurve([Point(t, 0) for t in range(-π, π, length = 361)])
@test_throws "proven readonly" jacobian(curve, (0.5,), AutoEnzyme())
@test _default_diff_method(Meshes.BezierCurve, Float64) isa FiniteDifference
end
# Cylinder: blocked by version-dependent upstream Meshes-Enzyme incompatibility
let cyl = Cylinder(Point(0, 0, 0), Point(0, 0, 1), 2.0)
@test _default_diff_method(Meshes.Cylinder, Float64) isa FiniteDifference
end
# CylinderSurface: blocked by version-dependent upstream Meshes-Enzyme incompatibility
let cylsurf = CylinderSurface(Point(0, 0, 0), Point(0, 0, 1), 2.0)
@test _default_diff_method(Meshes.CylinderSurface, Float64) isa FiniteDifference
end
# ParametrizedCurve: parametric functions are user-defined, can't guarantee behavior
@test _default_diff_method(Meshes.ParametrizedCurve, Float64) isa FiniteDifference
# Non-Float64: other FP types not supported by Enzyme
@test _default_diff_method(Meshes.Sphere, Float16) isa FiniteDifference
@test _default_diff_method(Meshes.Sphere, BigFloat) isa FiniteDifference

# _default_diff_method -- geometries that currently error with AutoEnzyme
@test _default_diff_method(Meshes.BezierCurve, Float64) isa FiniteDifference
@test _default_diff_method(Meshes.CylinderSurface, Float64) isa FiniteDifference
@test _default_diff_method(Meshes.Cylinder, Float64) isa FiniteDifference
@test _default_diff_method(Meshes.ParametrizedCurve, Float64) isa FiniteDifference

# FiniteDifference
@test FiniteDifference().ε ≈ 1e-6
let diff = FiniteDifference()
@test typeof(diff.ε) == Float64
@test diff.ε ≈ 1e-6
end

# Two-argument jacobian
segment = Segment(Point(0), Point(1))
@test MeshIntegrals.jacobian(segment, (0.5,)) == (Vec(1),)
let segment = Segment(Point(0), Point(1))
@test MeshIntegrals.jacobian(segment, (0.5,)) == (Vec(1),)
end

# Test jacobian with wrong number of parametric coordinates
box = Box(Point(0, 0), Point(1, 1))
@test_throws ArgumentError jacobian(box, zeros(3), FiniteDifference())
@test_throws ArgumentError jacobian(box, zeros(3), AutoEnzyme())
let box = Box(Point(0, 0), Point(1, 1))
@test_throws ArgumentError jacobian(box, zeros(3), FiniteDifference())
@test_throws ArgumentError jacobian(box, zeros(3), AutoEnzyme())
end
end

@testitem "_ParametricGeometry" setup=[Utils] begin
Expand Down
Loading