13
13
14
14
from .library import *
15
15
from .array import *
16
+ from .bcast import broadcast
16
17
17
- def approx1 (signal , pos0 , method = INTERP .LINEAR , off_grid = 0.0 ):
18
- """
19
- Interpolate along a single dimension.
20
-
21
- Parameters
22
- ----------
23
-
24
- signal: af.Array
25
- A 1 dimensional signal or batch of 1 dimensional signals.
18
+ @broadcast
19
+ def _scale_pos_axis0 (x_curr , x_orig ):
20
+ x0 = x_orig [0 , 0 , 0 , 0 ]
21
+ dx = x_orig [1 , 0 , 0 , 0 ] - x0
22
+ return ((x_curr - x0 ) / dx )
26
23
27
- pos0 : af.Array
28
- Locations of the interpolation points.
24
+ @broadcast
25
+ def _scale_pos_axis1 (y_curr , y_orig ):
26
+ y0 = y_orig [0 , 0 , 0 , 0 ]
27
+ dy = y_orig [0 , 1 , 0 , 0 ] - y0
28
+ return ((y_curr - y0 ) / dy )
29
29
30
- method: optional: af.INTERP. default: af.INTERP.LINEAR.
31
- Interpolation method.
32
-
33
- off_grid: optional: scalar. default: 0.0.
34
- The value used for positions outside the range.
35
-
36
- Returns
37
- -------
38
-
39
- output: af.Array
40
- Values calculated at interpolation points.
41
-
42
- Note
43
- -----
44
-
45
- The initial measurements are assumed to have taken place at equal steps between [0, N - 1],
46
- where N is the length of the first dimension of `signal`.
47
-
48
-
49
- """
50
- output = Array ()
51
- safe_call (backend .get ().af_approx1 (c_pointer (output .arr ), signal .arr , pos0 .arr ,
52
- method .value , c_float_t (off_grid )))
53
- return output
54
-
55
- def approx2 (signal , pos0 , pos1 , method = INTERP .LINEAR , off_grid = 0.0 ):
30
+ def approx1 (x_interpolated , x_input , signal_input , method = INTERP .LINEAR , off_grid = 0.0 ):
56
31
"""
57
- Interpolate along a two dimension.
58
-
59
- Parameters
60
- ----------
61
-
62
- signal: af.Array
63
- A 2 dimensional signal or batch of 2 dimensional signals.
64
-
65
- pos0 : af.Array
66
- Locations of the interpolation points along the first dimension.
67
-
68
- pos1 : af.Array
69
- Locations of the interpolation points along the second dimension.
70
-
71
- method: optional: af.INTERP. default: af.INTERP.LINEAR.
72
- Interpolation method.
73
-
74
- off_grid: optional: scalar. default: 0.0.
75
- The value used for positions outside the range.
76
-
77
- Returns
78
- -------
79
-
80
- output: af.Array
81
- Values calculated at interpolation points.
82
-
83
- Note
84
- -----
85
-
86
- The initial measurements are assumed to have taken place at equal steps between [(0,0) - [M - 1, N - 1]]
87
- where M is the length of the first dimension of `signal`,
88
- and N is the length of the second dimension of `signal`.
89
-
90
-
91
- """
92
- output = Array ()
93
- safe_call (backend .get ().af_approx2 (c_pointer (output .arr ), signal .arr ,
94
- pos0 .arr , pos1 .arr , method .value , c_float_t (off_grid )))
95
- return output
96
-
97
- def interp1d (x_interpolated , x_input , signal_input , method = INTERP .LINEAR , off_grid = 0.0 ):
98
- """
99
- One-dimensional linear interpolation.Interpolation is performed along axis 0
32
+ Interpolate along a single dimension.Interpolation is performed along axis 0
100
33
of the input array.
101
34
102
35
Parameters
@@ -106,35 +39,36 @@ def interp1d(x_interpolated, x_input, signal_input, method=INTERP.LINEAR, off_gr
106
39
The x-coordinates of the interpolation points. The interpolation
107
40
function is queried at these set of points.
108
41
109
- x : af.Array
110
- The x-coordinates of the input data points
42
+ x_input : af.Array
43
+ The x-coordinates of the input data points
111
44
112
45
signal_input: af.Array
113
46
Input signal array (signal = f(x))
114
47
48
+
115
49
method: optional: af.INTERP. default: af.INTERP.LINEAR.
116
50
Interpolation method.
117
51
118
52
off_grid: optional: scalar. default: 0.0.
119
- The value used for positions outside the range.
53
+ The value used for positions outside the range.
120
54
121
55
Returns
122
56
-------
123
57
124
58
output: af.Array
125
59
Values calculated at interpolation points.
126
60
"""
127
- dx = sum ( x_input [ 1 , 0 , 0 , 0 ] - x_input [ 0 , 0 , 0 , 0 ] )
128
- pos0 = ( x_interpolated - sum ( x_input [ 0 , 0 , 0 , 0 ])) / dx
129
-
130
- return approx1 ( signal_input , pos0 , method , off_grid )
131
-
61
+ 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 ,
64
+ method . value , c_float_t ( off_grid )) )
65
+ return output
132
66
133
- def interp2d (x_interpolated , x_input , y_interpolated , y_input ,
134
- signal_input , method = INTERP .LINEAR , off_grid = 0.0
135
- ):
67
+ def approx2 (x_interpolated , x_input , y_interpolated , y_input , signal_input ,
68
+ method = INTERP .LINEAR , off_grid = 0.0
69
+ ):
136
70
"""
137
- Two-dimensional linear interpolation .Interpolation is performed along axes 0 and 1
71
+ Interpolate along a two dimension .Interpolation is performed along axes 0 and 1
138
72
of the input array.
139
73
140
74
Parameters
@@ -144,17 +78,17 @@ def interp2d(x_interpolated, x_input, y_interpolated, y_input,
144
78
The x-coordinates of the interpolation points. The interpolation
145
79
function is queried at these set of points.
146
80
147
- x : af.Array
148
- The x-coordinates of the input data points. The convention followed is that
149
- the x-coordinates vary along axis 0
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
150
84
151
85
y_interpolated : af.Array
152
86
The y-coordinates of the interpolation points. The interpolation
153
87
function is queried at these set of points.
154
88
155
- y : af.Array
156
- The y-coordinates of the input data points. The convention followed is that
157
- the y-coordinates vary along axis 1
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
158
92
159
93
signal_input: af.Array
160
94
Input signal array (signal = f(x, y))
@@ -163,21 +97,21 @@ def interp2d(x_interpolated, x_input, y_interpolated, y_input,
163
97
Interpolation method.
164
98
165
99
off_grid: optional: scalar. default: 0.0.
166
- The value used for positions outside the range.
100
+ The value used for positions outside the range.
167
101
168
102
Returns
169
103
-------
170
104
171
105
output: af.Array
172
106
Values calculated at interpolation points.
173
- """
174
- dx = sum (x_input [1 , 0 , 0 , 0 ] - x_input [0 , 0 , 0 , 0 ])
175
- dy = sum (y_input [0 , 1 , 0 , 0 ] - y_input [0 , 0 , 0 , 0 ])
176
-
177
- pos0 = (x_interpolated - sum (x_input [0 , 0 , 0 , 0 ]))/ dx
178
- pos1 = (y_interpolated - sum (y_input [0 , 0 , 0 , 0 ]))/ dy
179
107
180
- return approx2 (signal_input , pos0 , pos1 , method , off_grid )
108
+ """
109
+ 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 ,
113
+ pos0 .arr , pos1 .arr , method .value , c_float_t (off_grid )))
114
+ return output
181
115
182
116
def fft (signal , dim0 = None , scale = None ):
183
117
"""
0 commit comments