Home > Mobile >  Julia imresize function definition is vague
Julia imresize function definition is vague

Time:12-02

Here the function imresize from ImageTransformation.jl is defined. On line 164 there is this expression:

resized[I] = original(I_o...)

From Julia's documentation I understood the triple dot is called splatting and it unpacks an argument into multiple arguments. For example I_o is a tuple here. My issue is that I cannot find any trace of a function called original in the mentioned Julia file. Where is original? From the code itself I have the impression that original should be an array and indeed on line 147 the type of original is annotated as AbstractInterpolation yet in turn I could not find any object of such type in the rest of the code.

CodePudding user response:

The function declaration reads:

function imresize!(resized::AbstractArray{T,N}, original::AbstractInterpolation{S,N}) where {T,S,N}

Hence, original is the parameter of the imresize! function.

Now, you can see that this is called with paranthesis (). This happens because a functor has been defined.

This functor seems to be defined outside of this package but you can see in the package how it is used:

@inline _getindex(A, v) = A[v...]
@inline _getindex(A::AbstractInterpolation, v) = A(v...)

so simply it is used to yield an interpolation element.

You can find the actual declaration of this functor in the Interpolations package (for each interpolation type). For an example:

@inline function (itp::BSplineInterpolation)(x::Vararg{UnexpandedIndexTypes})
    itp(to_indices(itp, x)...)
end

Source: https://github.com/JuliaMath/Interpolations.jl/blob/33409a657cacabf877681439605f16431f4bc8f4/src/b-splines/indexing.jl#L46

  • Related