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