arrayfire-python
arrayfire-python copied to clipboard
Interpolation along particular axis
Currently, the interpolation function performs the interpolation along the 0th and the 1st axis. However, in my problem of interest, I need to interpolate along all the 4 axes. Could the feature of having interpolation along a particular axis be added on in af.approx2
. Right now, I'm reordering the arrays such that the axes along which I need to interpolate are moved to the 0th and 1st axes. After which I need to reorder the resulting array to bring it back to the original convention.
This is what I'm currently doing right now:
# vel_y_interpolant is stacked along axis 2
# vel_x_interpolant is stacked along axis 3
f_interp = af.approx2(af.reorder(f, 2, 3, 0, 1),\
af.reorder(vel_y_interpolant, 2, 3, 0, 1),\
af.reorder(vel_x_interpolant, 2, 3, 0, 1),\
af.INTERP.BICUBIC_SPLINE
)
f_interp = af.reorder(f_interp, 2, 3, 0, 1)
@ShyamSS-95 How is the data being created?
The convention I'm following throughout is that y
varies along axis 0, x
varies along axis 1, vel_y
varies along axis 2 and vel_x
varies along axis 3.
I'm creating vel_x
and vel_y
using:
vel_x = np.linspace(-vel_x_max, vel_x_max, N_vel_x)
vel_x = af.Array.as_type(af.to_array(vel_x), af.Dtype.f64)
vel_x = af.reorder(vel_x, 3, 2, 1, 0)
vel_x = af.tile(vel_x,\
N_y, \
N_x, \
N_vel_y, \
1
)
vel_y = np.linspace(-vel_y_max, vel_y_max, N_vel_y)
vel_y = af.Array.as_type(af.to_array(vel_y), af.Dtype.f64)
vel_y = af.reorder(vel_y, 3, 2, 0, 1)
vel_y = af.tile(vel_y,\
N_y, \
N_x, \
1, \
N_vel_x
)
Mentioned below is the code for assigning x
and y
:
dy = (length_y)/(N_y - 1)
j = np.arange(0, N_y, 1)
y = j * dy
y = af.Array.as_type(af.to_array(y), af.Dtype.f64)
y = af.tile(y, 1, N_x, N_vel_y, N_vel_x)
dx = (length_x)/(N_x - 1)
i = np.arange(0, N_x, 1)
x = i * dx
x = af.Array.as_type(af.to_array(x), af.Dtype.f64)
x = af.tile(af.reorder(x), N_y, 1, N_vel_y, N_vel_x)
f is a probability distribution function which is created using:
f = af.sin(2*np.pi*x + 4*np.pi*y) * (1/(2*np.pi)) * \
af.exp(-0.5 * vel_x**2) * af.exp(-0.5 *vel_y**2)
Where N_x, N_y, N_vel_x, N_vel_y, vel_x_max, vel_y_max, length_x
and length_y
are all user defined parameters. Is this what you were looking for?