-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaks down on parametric types #39
Comments
You need to define |
But would it be impossible for the example above to "just" work out-of-the-box? |
It is possible, but we like it simple stupid 😄 see also JuliaObjects/ConstructionBase.jl#27 |
Is it possible to provide an example to how we should define struct ugo_control_type{T}
error::Cint
out::Cint
print_level::Cint
start_print::Cint
stop_print::Cint
print_gap::Cint
maxit::Cint
initial_points::Cint
storage_increment::Cint
buffer::Cint
lipschitz_estimate_used::Cint
next_interval_selection::Cint
refine_with_newton::Cint
alive_unit::Cint
alive_file::NTuple{31,Cchar}
stop_length::T
small_g_for_newton::T
small_g::T
obj_sufficient::T
global_lipschitz_constant::T
reliability_parameter::T
lipschitz_lower_bound::T
cpu_time_limit::T
clock_time_limit::T
second_derivative_available::Bool
space_critical::Bool
deallocate_error_fatal::Bool
prefix::NTuple{31,Cchar}
ugo_control_type{T}(error::Cint, out::Cint, print_level::Cint, start_print::Cint,
stop_print::Cint, print_gap::Cint, maxit::Cint, initial_points::Cint, storage_increment::Cint,
buffer::Cint, lipschitz_estimate_used::Cint, next_interval_selection::Cint, refine_with_newton::Cint, alive_unit::Cint,
alive_file::NTuple{31,Cchar}, stop_length::T, small_g_for_newton::T, small_g::T, obj_sufficient::T, global_lipschitz_constant::T,
reliability_parameter::T, lipschitz_lower_bound::T, cpu_time_limit::T, clock_time_limit::T, second_derivative_available::Bool,
space_critical::Bool, deallocate_error_fatal::Bool, prefix::NTuple{31,Cchar}) where T = new(error, out, print_level, start_print, stop_print,
print_gap, maxit, initial_points, storage_increment, buffer, lipschitz_estimate_used, next_interval_selection, refine_with_newton,
alive_unit, alive_file, stop_length, small_g_for_newton, small_g, obj_sufficient, global_lipschitz_constant, reliability_parameter,
lipschitz_lower_bound, cpu_time_limit, clock_time_limit, second_derivative_available, space_critical, deallocate_error_fatal,
prefix)
ugo_control_type{T}() where T = new()
end
using Accessors
control = ugo_control_type{Float64}()
@reset control.print_level = Cint(1) The parameter MethodError: no method matching ugo_control_type(::Int32, ::Int32, ::Int64, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::Int32, ::NTuple{31, Int8}, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Bool, ::Bool, ::Bool, ::NTuple{31, Int8})
Stacktrace:
[1] setproperties_object(obj::ugo_control_type{Float64}, patch::@NamedTuple{print_level::Int64})
@ ConstructionBase ~/.julia/packages/ConstructionBase/JFKjZ/src/ConstructionBase.jl:217
[2] setproperties(obj::ugo_control_type{Float64}, patch::@NamedTuple{print_level::Int64})
@ ConstructionBase ~/.julia/packages/ConstructionBase/JFKjZ/src/ConstructionBase.jl:131
[3] set(obj::ugo_control_type{Float64}, l::PropertyLens{:print_level}, val::Int64)
@ Accessors ~/.julia/packages/Accessors/hjkBO/src/optics.jl:375
[4] top-level scope
@ REPL[9]:1 |
Update: One solution is to define this alternative constructor: ugo_control_type(error::Cint, out::Cint, print_level::Cint, start_print::Cint,
stop_print::Cint, print_gap::Cint, maxit::Cint, initial_points::Cint, storage_increment::Cint,
buffer::Cint, lipschitz_estimate_used::Cint, next_interval_selection::Cint, refine_with_newton::Cint, alive_unit::Cint,
alive_file::NTuple{31,Cchar}, stop_length::T, small_g_for_newton::T, small_g::T, obj_sufficient::T, global_lipschitz_constant::T,
reliability_parameter::T, lipschitz_lower_bound::T, cpu_time_limit::T, clock_time_limit::T, second_derivative_available::Bool,
space_critical::Bool, deallocate_error_fatal::Bool, prefix::NTuple{31,Cchar}) where T = new{T}(error, out, print_level, start_print, stop_print,
print_gap, maxit, initial_points, storage_increment, buffer, lipschitz_estimate_used, next_interval_selection, refine_with_newton,
alive_unit, alive_file, stop_length, small_g_for_newton, small_g, obj_sufficient, global_lipschitz_constant, reliability_parameter,
lipschitz_lower_bound, cpu_time_limit, clock_time_limit, second_derivative_available, space_critical, deallocate_error_fatal,
prefix) |
Do you really need the inner constructor defined manually? The condition required for everything to work automatically is that your type can be created from its field values, without manually specifying type parameters. In your case, it corresponds to |
Yes, I need the inner constructor defined manually because A C routine will set the default values of this structure so ugo_control_type control But I find a way to add automatically the "long" constructors when I generate the structures with Clang.jl. An example of |
Yeah, I guess https://juliaobjects.github.io/ConstructionBase.jl/ doesn't give all the details needed to explain
Btw, there's a (poorly documented) way to create a struct like @generated ugo_control_type{T}() where {T} = Expr(:new, ugo_control_type{T}) Unlike inner constructors, it doesn't overwrite the default one, so everything should work without all that repetition of fieldnames. |
In Accessors v0.1.5.
Breaks down when the type parameter is not "used" in the struct.
The text was updated successfully, but these errors were encountered: