MCPcopy Create free account
hub / github.com/numpy/numpy / _zseries_div

Function _zseries_div

numpy/polynomial/chebyshev.py:210–274  ·  view source on GitHub ↗

Divide the first z-series by the second. Divide `z1` by `z2` and return the quotient and remainder as z-series. Warning: this implementation only applies when both z1 and z2 have the same symmetry, which is sufficient for present purposes. Parameters ---------- z1, z2 : 1-D

(z1, z2)

Source from the content-addressed store, hash-verified

208
209
210def _zseries_div(z1, z2):
211 """Divide the first z-series by the second.
212
213 Divide `z1` by `z2` and return the quotient and remainder as z-series.
214 Warning: this implementation only applies when both z1 and z2 have the
215 same symmetry, which is sufficient for present purposes.
216
217 Parameters
218 ----------
219 z1, z2 : 1-D ndarray
220 The arrays must be 1-D and have the same symmetry, but this is not
221 checked.
222
223 Returns
224 -------
225
226 (quotient, remainder) : 1-D ndarrays
227 Quotient and remainder as z-series.
228
229 Notes
230 -----
231 This is not the same as polynomial division on account of the desired form
232 of the remainder. If symmetric/anti-symmetric z-series are denoted by S/A
233 then the following rules apply:
234
235 S/S -> S,S
236 A/A -> S,A
237
238 The restriction to types of the same symmetry could be fixed but seems like
239 unneeded generality. There is no natural form for the remainder in the case
240 where there is no symmetry.
241
242 """
243 z1 = z1.copy()
244 z2 = z2.copy()
245 lc1 = len(z1)
246 lc2 = len(z2)
247 if lc2 == 1:
248 z1 /= z2
249 return z1, z1[:1]*0
250 elif lc1 < lc2:
251 return z1[:1]*0, z1
252 else:
253 dlen = lc1 - lc2
254 scl = z2[0]
255 z2 /= scl
256 quo = np.empty(dlen + 1, dtype=z1.dtype)
257 i = 0
258 j = dlen
259 while i < j:
260 r = z1[i]
261 quo[i] = z1[i]
262 quo[dlen - i] = r
263 tmp = r*z2
264 z1[i:i+lc2] -= tmp
265 z1[j:j+lc2] -= tmp
266 i += 1
267 j -= 1

Callers 2

_zseries_derFunction · 0.85
chebdivFunction · 0.85

Calls 1

copyMethod · 0.45

Tested by

no test coverage detected