Skip to content

Commit

Permalink
renamed _input_validation to _is_valid_input
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Hernandez Acosta committed Sep 27, 2023
1 parent b734cfb commit 27435b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/interfaces/setup_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ quantity depends on is kept constant.
Every subtype of `AbstractComputationSetup` should implement the interface function
```Julia
_input_validation(stp::AbstractComputationSetup, input) # default: true
_is_valid_input(stp::AbstractComputationSetup, input) # default: true
```
which should return true iff the `input` is valid for the computation of the associated quantity (see [`_input_validation`](@ref) for more details).
which should return true iff the `input` is valid for the computation of the associated quantity (see [`_is_valid_input`](@ref) for more details).
The default implementation always returns `true`. Provide a custom implementation if a different behavior is required.
## Actual computation
Expand Down Expand Up @@ -75,7 +75,7 @@ This function is called to validate the input of [`compute`](@ref) before callin
This behavior can be overwritten if actual validation is necessary.
"""
@inline function _input_validation(stp::AbstractComputationSetup, input)
@inline function _is_valid_input(stp::AbstractComputationSetup, input)
return true
end

Expand Down Expand Up @@ -103,7 +103,7 @@ Interface function that returns the value of the associated quantity evaluated o
!!! note "unsafe implementation"
This function must be implemented for any subtype of [`AbstractComputationSetup`]. It should not do any input validation or post processing (see [`_input_validation`](@ref) and [`_post_computation`](@ref)), as those two are performed while calling
This function must be implemented for any subtype of [`AbstractComputationSetup`]. It should not do any input validation or post processing (see [`_is_valid_input`](@ref) and [`_post_computation`](@ref)), as those two are performed while calling
the safe version of this function [`compute`](@ref).
"""
Expand All @@ -115,11 +115,11 @@ function _compute end
Return the value of the quantity associated with `stp` for a given `input`.
In addition to the actual call of the associated unsafe version [`_compute`](@ref),
input validation (using [`_input_validation`](@ref)) and post computation
input validation (using [`_is_valid_input`](@ref)) and post computation
(using [`_post_computation`](@ref)) are wrapped around the calculation (see [`AbstractComputationSetup`](@ref) for details).
"""
function compute(stp::AbstractComputationSetup, input)
_input_validation(stp,input) || error("InvalidInputError: there is something wrong with the input!\n setup:$stp \n input:$input")
_is_valid_input(stp,input) || error("InvalidInputError: there is something wrong with the input!\n setup:$stp \n input:$input")
raw_result = _compute(stp,input)
return _post_computation(stp, input,raw_result)
end
Expand Down
16 changes: 8 additions & 8 deletions test/interfaces/setup_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ struct TestSetupDefault <: AbstractTestSetup end

# setup with custom input validation
struct TestSetupCustomValidation <: AbstractTestSetup end
QEDprocesses._input_validation(::TestSetupCustomValidation, x) = _groundthruth_input_validation(x)
QEDprocesses._is_valid_input(::TestSetupCustomValidation, x) = _groundthruth_input_validation(x)

# setup with custom post computation
struct TestSetupCustomPostComputation <: AbstractTestSetup end
QEDprocesses._post_computation(::TestSetupCustomPostComputation,x,y) = _groundtruth_post_computation(x,y)

# setup with custom input validation and post computation
struct TestSetupCustom <: AbstractTestSetup end
QEDprocesses._input_validation(::TestSetupCustom, x) = _groundthruth_input_validation(x)
QEDprocesses._is_valid_input(::TestSetupCustom, x) = _groundthruth_input_validation(x)
QEDprocesses._post_computation(::TestSetupCustom,x,y) = _groundtruth_post_computation(x,y)

# setup which fail on computation with default implementations
struct TestSetupFAIL <: AbstractComputationSetup end

# setup which fail on computation with custom input validation
struct TestSetupCustomValidationFAIL <: AbstractComputationSetup end
QEDprocesses._input_validation(::TestSetupCustomValidationFAIL, x) = _groundthruth_input_validation(x)
QEDprocesses._is_valid_input(::TestSetupCustomValidationFAIL, x) = _groundthruth_input_validation(x)

# setup which fail on computation with custom post computation
struct TestSetupCustomPostComputationFAIL <: AbstractComputationSetup end
Expand All @@ -62,7 +62,7 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputationFAIL,x,y) = _grou

rnd_input = rand(RNG)
rnd_output = rand(RNG)
@test QEDprocesses._input_validation(stp,rnd_input)
@test QEDprocesses._is_valid_input(stp,rnd_input)
@test QEDprocesses._post_computation(stp,rnd_input,rnd_output) == rnd_output
@test isapprox(QEDprocesses._compute(stp, rnd_input), _groundthruth_compute(rnd_input), atol=ATOL,rtol=RTOL)
@test isapprox(compute(stp, rnd_input), _groundthruth_compute(rnd_input), atol=ATOL,rtol=RTOL)
Expand All @@ -71,8 +71,8 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputationFAIL,x,y) = _grou
@testset "custom input validation" begin
stp = TestSetupCustomValidation()
rnd_input = rand(RNG)
@test QEDprocesses._input_validation(stp, _groundthruth_input_validation(rnd_input))
@test !QEDprocesses._input_validation(stp, !_groundthruth_input_validation(rnd_input))
@test QEDprocesses._is_valid_input(stp, _groundthruth_input_validation(rnd_input))
@test !QEDprocesses._is_valid_input(stp, !_groundthruth_input_validation(rnd_input))
@test isapprox(compute(stp, rnd_input), _groundthruth_compute(rnd_input), atol=ATOL,rtol=RTOL)
@test_throws ErrorException compute(stp, _transform_to_invalid(rnd_input))
end
Expand All @@ -90,8 +90,8 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputationFAIL,x,y) = _grou
rnd_input = rand(RNG)
rnd_output = rand(RNG)

@test QEDprocesses._input_validation(stp, _groundthruth_input_validation(rnd_input))
@test !QEDprocesses._input_validation(stp, !_groundthruth_input_validation(rnd_input))
@test QEDprocesses._is_valid_input(stp, _groundthruth_input_validation(rnd_input))
@test !QEDprocesses._is_valid_input(stp, !_groundthruth_input_validation(rnd_input))
@test_throws ErrorException compute(stp, _transform_to_invalid(rnd_input))
@test isapprox(QEDprocesses._post_computation(stp,rnd_input,rnd_output), _groundtruth_post_computation(rnd_input,rnd_output))
@test isapprox(compute(stp,rnd_input), _groundtruth_post_computation(rnd_input,_groundthruth_compute(rnd_input)))
Expand Down

0 comments on commit 27435b0

Please sign in to comment.