0

Does anyone know how to use ArrayFire's approx1/approx2 functions? I can't find examples of their usage online, and so cannot figure out what exactly the interpolation position arrays should be. I have tried af::approx2(inArray, af::where(inArray some condition), af::where(inArray some other condition), AF_INTERP_NEAREST) along with similar examples where af::where() is replaced with something like af::isNaN() and no matter what I try, I cannot get approx1 or approx2 to work. Thanks for the help!

Edit: The specific issue I am encountering is with the two af::array parameters, where above I state that I have tried af::where(...). I do not know what specific types of af::array to pass. The documentation's description of

array contains the interpolation locations

does not help in identifying what I need to pass to these functions. af::where() and af::isNaN(), both functions that return arrays describing positions of elements, cause an af::exception at runtime.

5
  • If you do not know how to use some library's API you should read the manual and study examples. From your post it is not clear what problem you have, how you tried to solve it and what results you got and expect. Jul 2, 2018 at 21:38
  • The documentation does not have any examples, and the example code packaged with the ArrayFire installation does not have a single example using either interpolation function. Every result on the first 2 pages of Google, using various keywords, did not show any examples. Have you looked at the ArrayFire documentation before? It does not include examples for most functions. It merely states what type of parameter is required for the interpolation functions, and nothing more specific. Giving these functions parameters of the correct type causes an unhandled af::exception error.
    – solyuina
    Jul 2, 2018 at 21:49
  • If I understand you correctly you are having problem with performing a conditional replacement of values in an array, but not with actual approx1/approx2 functions. If so, look here for your answer stackoverflow.com/questions/36263133/… Jul 2, 2018 at 22:00
  • To clarify again, interpolation involves using other values in the inArray to replace the values in certain locations. In my case, I am attempting to implement a nearest neighbor replacement for NAN values in an array. This is not the same as conditional replacement.
    – solyuina
    Jul 2, 2018 at 22:03
  • Do the unit tests for these functions offer any guidance on usage? Jul 5, 2018 at 21:51

2 Answers 2

0

As stated in the docs, approx1 takes the following arguments:

af::approx1 ( const array & in,
        const array & pos,
        const interpType method = AF_INTERP_LINEAR,
        const float offGrid = 0.0f )

While in, method and offGrid are described, the exact effect of pos is not. The solution is straightforward: The input-data in array in are assumed to lie on a grid of spacing 1.

This means you have to scale your pos-array accordingly. Suppose your input data of length N were located at positions x with dx = x[i+1]-x[i] then the interpolated representation of your data lies on the grid x[i]/dx.

E.g. if the whole data were to be interpolated onto a grid xnew, the pos argument would need to be rescaled to pos = xnew/dx.

This implies, of course, that approx1 (and also approx2) can only work on evenly-spaced grids, which is also not mentioned in the docs.

0

This might not resolve your current issue, but we have tried address this shortcoming in the documentation and the fixes will be made public in our next feature release. We have detailed how approx functions work and added new version of the functions that lets you choose the dimension along which interpolation can be carried out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.