Skip to content

Commit 7709bb3

Browse files
shyams2pavanky
authored andcommitted
Made changes to retain earlier approx1 behaviour as well
1 parent 84b2f2f commit 7709bb3

File tree

2 files changed

+57
-27
lines changed

2 files changed

+57
-27
lines changed

arrayfire/signal.py

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,57 @@ def _scale_pos_axis1(y_curr, y_orig):
2727
dy = y_orig[0, 1, 0, 0] - y0
2828
return((y_curr - y0) / dy)
2929

30-
def approx1(x_interpolated, x_input, signal_input, method=INTERP.LINEAR, off_grid=0.0):
30+
def approx1(signal, x_interpolated, method=INTERP.LINEAR, off_grid=0.0, x_input = None):
3131
"""
3232
Interpolate along a single dimension.Interpolation is performed along axis 0
3333
of the input array.
3434
3535
Parameters
3636
----------
3737
38+
signal: af.Array
39+
Input signal array (signal = f(x))
40+
3841
x_interpolated : af.Array
3942
The x-coordinates of the interpolation points. The interpolation
4043
function is queried at these set of points.
4144
42-
x_input : af.Array
43-
The x-coordinates of the input data points
44-
45-
signal_input: af.Array
46-
Input signal array (signal = f(x))
47-
48-
4945
method: optional: af.INTERP. default: af.INTERP.LINEAR.
5046
Interpolation method.
5147
5248
off_grid: optional: scalar. default: 0.0.
5349
The value used for positions outside the range.
5450
51+
x_input : af.Array
52+
The x-coordinates of the input data points
53+
5554
Returns
5655
-------
5756
5857
output: af.Array
5958
Values calculated at interpolation points.
59+
60+
61+
Note
62+
-----
63+
This holds applicable when x_input isn't provided:
64+
The initial measurements are assumed to have taken place at equal steps between [0, N - 1],
65+
where N is the length of the first dimension of `signal`.
6066
"""
67+
6168
output = Array()
62-
pos0 = _scale_pos_axis0(x_interpolated, x_input)
63-
safe_call(backend.get().af_approx1(c_pointer(output.arr), signal_input.arr, pos0.arr,
69+
70+
if(x_input is not None):
71+
pos0 = _scale_pos_axis0(x_interpolated, x_input)
72+
else:
73+
pos0 = x_interpolated
74+
75+
safe_call(backend.get().af_approx1(c_pointer(output.arr), signal.arr, pos0.arr,
6476
method.value, c_float_t(off_grid)))
6577
return output
6678

67-
def approx2(x_interpolated, x_input, y_interpolated, y_input, signal_input,
68-
method=INTERP.LINEAR, off_grid=0.0
79+
def approx2(signal, x_interpolated, y_interpolated,
80+
method=INTERP.LINEAR, off_grid=0.0, x_input = None, y_input = None
6981
):
7082
"""
7183
Interpolate along a two dimension.Interpolation is performed along axes 0 and 1
@@ -74,42 +86,60 @@ def approx2(x_interpolated, x_input, y_interpolated, y_input, signal_input,
7486
Parameters
7587
----------
7688
89+
signal: af.Array
90+
Input signal array (signal = f(x, y))
91+
7792
x_interpolated : af.Array
7893
The x-coordinates of the interpolation points. The interpolation
7994
function is queried at these set of points.
8095
81-
x_input : af.Array
82-
The x-coordinates of the input data points. The convention followed is that
83-
the x-coordinates vary along axis 0
8496
8597
y_interpolated : af.Array
8698
The y-coordinates of the interpolation points. The interpolation
8799
function is queried at these set of points.
88100
89-
y_input : af.Array
90-
The y-coordinates of the input data points. The convention followed is that
91-
the y-coordinates vary along axis 1
92-
93-
signal_input: af.Array
94-
Input signal array (signal = f(x, y))
95-
96101
method: optional: af.INTERP. default: af.INTERP.LINEAR.
97102
Interpolation method.
98103
99104
off_grid: optional: scalar. default: 0.0.
100105
The value used for positions outside the range.
101106
107+
x_input : af.Array
108+
The x-coordinates of the input data points. The convention followed is that
109+
the x-coordinates vary along axis 0
110+
111+
y_input : af.Array
112+
The y-coordinates of the input data points. The convention followed is that
113+
the y-coordinates vary along axis 1
114+
102115
Returns
103116
-------
104117
105118
output: af.Array
106119
Values calculated at interpolation points.
107120
121+
Note
122+
-----
123+
This holds applicable when x_input/y_input isn't provided:
124+
125+
The initial measurements are assumed to have taken place at equal steps between [(0,0) - [M - 1, N - 1]]
126+
where M is the length of the first dimension of `signal`,
127+
and N is the length of the second dimension of `signal`.
108128
"""
129+
109130
output = Array()
110-
pos0 = _scale_pos_axis0(x_interpolated, x_input)
111-
pos1 = _scale_pos_axis1(y_interpolated, y_input)
112-
safe_call(backend.get().af_approx2(c_pointer(output.arr), signal_input.arr,
131+
132+
if(x_input is not None):
133+
pos0 = _scale_pos_axis0(x_interpolated, x_input)
134+
else:
135+
pos0 = x_interpolated
136+
137+
if(y_input is not None):
138+
pos1 = _scale_pos_axis1(y_interpolated, y_input)
139+
else:
140+
pos1 = y_interpolated
141+
142+
safe_call(backend.get().af_approx2(c_pointer(output.arr), signal.arr,
113143
pos0.arr, pos1.arr, method.value, c_float_t(off_grid)))
114144
return output
115145

arrayfire/tests/simple/signal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ def simple_signal(verbose=False):
1818
signal = af.randu(10)
1919
x_new = af.randu(10)
2020
x_orig = af.randu(10)
21-
display_func(af.approx1(x_new, x_orig, signal))
21+
display_func(af.approx1(signal, x_new, x_input = x_orig))
2222

2323
signal = af.randu(3, 3)
2424
x_new = af.randu(3, 3)
2525
x_orig = af.randu(3, 3)
2626
y_new = af.randu(3, 3)
2727
y_orig = af.randu(3, 3)
2828

29-
display_func(af.approx2(x_new, x_orig, y_new, y_orig, signal))
29+
display_func(af.approx2(signal, x_new, y_new, x_input = x_orig, y_input = y_orig))
3030

3131
a = af.randu(8, 1)
3232
display_func(a)

0 commit comments

Comments
 (0)