MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _sub_number

Function _sub_number

tools/sampcd_processor.py:136–159  ·  view source on GitHub ↗
(match_obj, digits)

Source from the content-addressed store, hash-verified

134 _check_output = checker.check_output
135
136 def _sub_number(match_obj, digits):
137 match_str = match_obj.group()
138
139 if 'j' in match_str or 'J' in match_str:
140 try:
141 match_num = complex(match_str)
142 except ValueError:
143 return match_str
144
145 return (
146 str(
147 complex(
148 round(match_num.real, digits),
149 round(match_num.imag, digits),
150 )
151 )
152 .strip('(')
153 .strip(')')
154 )
155 else:
156 try:
157 return str(round(float(match_str), digits))
158 except ValueError:
159 return match_str
160
161 sub_number = functools.partial(_sub_number, digits=digits)
162

Callers

nothing calls this directly

Calls 5

strFunction · 0.85
complexFunction · 0.50
roundFunction · 0.50
floatFunction · 0.50
groupMethod · 0.45

Tested by

no test coverage detected