MCPcopy Index your code
hub / github.com/bayesian-optimization/BayesianOptimization / _format_number

Method _format_number

bayes_opt/logger.py:66–104  ·  view source on GitHub ↗

Format a number. Parameters ---------- x : number Value to format. Returns ------- A stringified, formatted version of `x`.

(self, x: float)

Source from the content-addressed store, hash-verified

64 return self._is_constrained
65
66 def _format_number(self, x: float) -> str:
67 """Format a number.
68
69 Parameters
70 ----------
71 x : number
72 Value to format.
73
74 Returns
75 -------
76 A stringified, formatted version of `x`.
77 """
78 s = f"{x:.5e}" if abs(x) >= 10000000.0 else str(x)
79
80 if len(s) > self._default_cell_size:
81 # Convert to str representation of scientific notation
82 result = ""
83 width = self._default_cell_size
84 # Keep negative sign, exponent, and as many decimal places as possible
85 if x < 0:
86 result += "-"
87 width -= 1
88 s = s[1:]
89 if "e" in s:
90 e_pos = s.find("e")
91 end = s[e_pos:]
92 width -= len(end)
93 if "." in s:
94 dot_pos = s.find(".") + 1
95 result += s[:dot_pos]
96 width -= dot_pos
97 if width > 0:
98 result += s[dot_pos : dot_pos + width]
99 if "e" in s:
100 result += end
101 result = result.ljust(self._default_cell_size)
102 else:
103 result = s.ljust(self._default_cell_size)
104 return result
105
106 def _format_bool(self, x: bool) -> str:
107 """Format a boolean.

Callers 2

test_format_numberFunction · 0.95
_print_stepMethod · 0.95

Calls

no outgoing calls

Tested by 1

test_format_numberFunction · 0.76