Gridap.Inference

Gridap.Inference.return_typeMethod
return_type(f::Function, Ts::Vararg{Any,N} where N) -> DataType

Returns the type returned by function f when called with arguments of the types in Ts.

The underlying implementation uses the function testargs to generate some test values in order to call the function and determine the returned type. This mechanism does not use Base._return_type. One of the advantages is that the given function f is called, and thus, meaningful error messages will be displayed if there is any error in f.

source
Gridap.Inference.testargsFunction
testargs(f::Function,Ts::DataType...) -> Tuple

Returns a tuple with valid arguments of the types in Ts in order to call function f. It defaults to testvalues(Ts...), see the testvalues function. The user can overload the testargs function for particular functions if the default test arguments are not in the domain of the function and a DomainError is raised.

Examples

For the following function, the default test argument (which is a zero) is not in the domain. We can overload the testargs function to provide a valid test argument.

using Gridap.Inference
import Gridap.Inference: testargs
foo(x) = sqrt(x-1)
testargs(::typeof(foo),T::DataType) = (one(T),)
return_type(foo, Int)
# output
Float64
source
Gridap.Inference.testvalueFunction
testvalue(::Type{T}) where T

Returns an arbitrary instance of type T. It defaults to zero(T) for non-array types and to an empty array for array types. This function is used to compute the default test arguments in testargs. It can be overloaded for new types T if zero(T) does not makes sense.

source
Gridap.Inference.testvaluesFunction
testvalues(Ts::DataType...) -> Tuple

Returns a tuple with test values for each of the types in Ts. Equivalent to map(testvalue,Ts).

source