-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
In FiniteDifferences, this PR allowed custom constructors to be handled as part of to_vec: JuliaDiff/FiniteDifferences.jl#181 here
However iiuc construct in CRC here doesn't handle this. In this case however, the constructor requirements are mentioned in the docstring.
However, tests in CRTU will construct the new type as part of the call to FiniteDifferences but then fail later as the constructor is not found in the call to construct.
Allowing this here, or otherwise, it would be easier if these behaviours were consistent in terms of custom types as part of the CTRU testing pipeline.
EDIT: MWE:
struct CustomType{T}
x
function CustomType(X::T) where {T}
new{T}(X)
end
end
# This misses the constructor:
CustomType{Int64}(5) # ERROR: MethodError: no method matching CustomType{Int64}(::Int64)
val = CustomType(5) # CustomType{Int64}(5)
diff = Tangent{typeof(val)}(x = 5) # Tangent{CustomType{Int64}}(x = 5,)
val + diff #ERROR: MethodError: no method matching CustomType{Int64}(::Int64)
# FiniteDifferences handles this in the vec to x:
to_vec(CustomType(5))[2]([6.0]) #CustomType{Int64}(6.0)Defining CustomType{T}(x) where {T} = CustomType(x) allows this pass.
cc @mzgubic
Metadata
Metadata
Assignees
Labels
No labels