Generate the full string representation of the polynomial, using ``term_method`` to generate each polynomial term.
(self, term_method)
| 346 | return self._generate_string(self._str_term_ascii) |
| 347 | |
| 348 | def _generate_string(self, term_method): |
| 349 | """ |
| 350 | Generate the full string representation of the polynomial, using |
| 351 | ``term_method`` to generate each polynomial term. |
| 352 | """ |
| 353 | # Get configuration for line breaks |
| 354 | linewidth = np.get_printoptions().get('linewidth', 75) |
| 355 | if linewidth < 1: |
| 356 | linewidth = 1 |
| 357 | out = pu.format_float(self.coef[0]) |
| 358 | |
| 359 | off, scale = self.mapparms() |
| 360 | |
| 361 | scaled_symbol, needs_parens = self._format_term(pu.format_float, |
| 362 | off, scale) |
| 363 | if needs_parens: |
| 364 | scaled_symbol = '(' + scaled_symbol + ')' |
| 365 | |
| 366 | for i, coef in enumerate(self.coef[1:]): |
| 367 | out += " " |
| 368 | power = str(i + 1) |
| 369 | # Polynomial coefficient |
| 370 | # The coefficient array can be an object array with elements that |
| 371 | # will raise a TypeError with >= 0 (e.g. strings or Python |
| 372 | # complex). In this case, represent the coefficient as-is. |
| 373 | try: |
| 374 | if coef >= 0: |
| 375 | next_term = "+ " + pu.format_float(coef, parens=True) |
| 376 | else: |
| 377 | next_term = "- " + pu.format_float(-coef, parens=True) |
| 378 | except TypeError: |
| 379 | next_term = f"+ {coef}" |
| 380 | # Polynomial term |
| 381 | next_term += term_method(power, scaled_symbol) |
| 382 | # Length of the current line with next term added |
| 383 | line_len = len(out.split('\n')[-1]) + len(next_term) |
| 384 | # If not the last term in the polynomial, it will be two |
| 385 | # characters longer due to the +/- with the next term |
| 386 | if i < len(self.coef[1:]) - 1: |
| 387 | line_len += 2 |
| 388 | # Handle linebreaking |
| 389 | if line_len >= linewidth: |
| 390 | next_term = next_term.replace(" ", "\n", 1) |
| 391 | out += next_term |
| 392 | return out |
| 393 | |
| 394 | @classmethod |
| 395 | def _str_term_unicode(cls, i, arg_str): |
no test coverage detected