Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ struct ExplicitTangent{P <: Tuple} <: AbstractTangentSpace
partials::P
end


@eval struct TaylorTangent{C <: Tuple} <: AbstractTangentSpace
coeffs::C
TaylorTangent(coeffs) = $(Expr(:new, :(TaylorTangent{typeof(coeffs)}), :coeffs))
function TaylorTangent(coeffs)
bad_tangent_type = Union{DataType, Symbol, String, Nothing} # protect against obvious mistakes
any(c->isa(c, bad_tangent_type), coeffs) && throw(DomainError(coeffs, "Nonvector-space partial type"))
$(Expr(:new, :(TaylorTangent{typeof(coeffs)}), :coeffs))
end
end

"""
Expand Down
10 changes: 9 additions & 1 deletion test/tangent.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module tagent
module tangent
using Diffractor
using Diffractor: AbstractZeroBundle, ZeroBundle, DNEBundle
using Diffractor: TaylorBundle, TaylorTangentIndex
Expand Down Expand Up @@ -54,4 +54,12 @@ end
@test truncate(et, Val(1)) == TaylorTangent((1.0,))
end


@testset "Bad Partial Types" begin
@test_throws DomainError TaylorBundle{1}(1.5, (ZeroTangent,)) # mistakenly passing a type rather than a value
@test_throws DomainError TaylorBundle{1}(1.5, (:a,))
@test_throws DomainError TaylorBundle{1}(1.5, (nothing,))
@test_throws DomainError TaylorBundle{1}(1.5, ("x",))
end

end # module