Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7d4e2e

Browse files
authored
Rewrites len(..) == 0 into not .. (#51)
* Rewrites len(..) == 0 into not ..* fix bug
1 parent885dd6a commitd7d4e2e

File tree

18 files changed

+41
-46
lines changed

18 files changed

+41
-46
lines changed

‎_unittests/ut_light_api/test_light_api.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def list_ops_missing(self, n_inputs):
138138
methods.append("")
139139
new_missing.append(m)
140140
text="\n".join(methods)
141-
iflen(new_missing)>0:
141+
ifnew_missing:
142142
raiseAssertionError(
143143
f"n_inputs={n_inputs}: missing method for operators "
144144
f"{new_missing}\n{text}"

‎_unittests/ut_validation/test_f8.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_search_float32_into_fe5m2(self):
344344
add=value
345345
else:
346346
add=v-value
347-
iflen(w)>0:
347+
ifw:
348348
raiseAssertionError(
349349
f"A warning was thrown for v={v}, "
350350
f"value={value}, w={w[0]}."

‎_unittests/ut_xrun_doc/test_documentation_examples.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def import_source(module_file_path, module_name):
2626
classTestDocumentationExamples(ExtTestCase):
2727
defrun_test(self,fold:str,name:str,verbose=0)->int:
2828
ppath=os.environ.get("PYTHONPATH","")
29-
iflen(ppath)==0:
29+
ifnotppath:
3030
os.environ["PYTHONPATH"]=ROOT
3131
elifROOTnotinppath:
3232
sep=";"ifis_windows()else":"
@@ -42,7 +42,7 @@ def run_test(self, fold: str, name: str, verbose=0) -> int:
4242
res=p.communicate()
4343
out,err=res
4444
st=err.decode("ascii",errors="ignore")
45-
iflen(st)>0and"Traceback"inst:
45+
ifstand"Traceback"inst:
4646
if'"dot" not found in path.'inst:
4747
# dot not installed, this part
4848
# is tested in onnx framework

‎onnx_array_api/ext_test_case.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ def assertRaise(self, fct: Callable, exc_type: Exception):
226226
raiseAssertionError("No exception was raised.")
227227

228228
defassertEmpty(self,value:Any):
229-
ifvalueisNone:
230-
return
231-
iflen(value)==0:
229+
ifnotvalue:
232230
return
233231
raiseAssertionError(f"value is not empty:{value!r}.")
234232

@@ -240,7 +238,7 @@ def assertNotEmpty(self, value: Any):
240238
ifvalueisNone:
241239
raiseAssertionError(f"value is empty:{value!r}.")
242240
ifisinstance(value, (list,dict,tuple,set)):
243-
iflen(value)==0:
241+
ifvalue:
244242
raiseAssertionError(f"value is empty:{value!r}.")
245243

246244
defassertStartsWith(self,prefix:str,full:str):

‎onnx_array_api/light_api/emitter.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def render_attribute_value(self, value: Any) -> Tuple[List[str], str]:
8585
ifisinstance(v,str):
8686
return [],f"{v!r}"
8787
ifisinstance(v,np.ndarray):
88-
iflen(v.shape)==0:
88+
ifnotv.shape:
8989
return [],str(v)
9090
iflen(v.shape)==1:
9191
ifvalue[0].typein (

‎onnx_array_api/light_api/translate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def export(self, as_str, single_line: bool = False) -> Union[str, List[str]]:
5151
else:
5252
raiseValueError(f"Unexpected type{type(self.proto_)} for proto.")
5353

54-
iflen(sparse_initializers)!=0:
54+
ifsparse_initializers:
5555
raiseNotImplementedError("Sparse initializer not supported yet.")
5656

5757
rows.extend(

‎onnx_array_api/npx/npx_graph_builder.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def to_onnx(
919919
[(var,i,None)foriinrange(var.n_var_outputs)]
920920
)
921921

922-
iflen(possible_types)>0:
922+
ifpossible_types:
923923
# converts possibles types into a dictionary
924924
map_types= {}
925925
forvar,i,dtinpossible_types:

‎onnx_array_api/npx/npx_helper.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _process_attributes(attributes):
4747
nodes= []
4848
modified=False
4949
fornodeingraph.node:
50-
iflen(set(node.input)&set_rep)==0:
50+
ifnot(set(node.input)&set_rep):
5151
modified=True
5252
new_inputs= [replacements.get(i,i)foriinnode.input]
5353
atts=_process_attributes(node.attribute)ornode.attribute
@@ -66,7 +66,7 @@ def _process_attributes(attributes):
6666
ifnotmodified:
6767
returnNone
6868

69-
iflen(set(i.nameforiingraph.input)&set_rep)==0:
69+
ifnot(set(i.nameforiingraph.input)&set_rep):
7070
returnmake_graph(nodes,graph.name,graph.input,graph.output)
7171

7272
new_inputs= []

‎onnx_array_api/npx/npx_jit_eager.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def to_jit(self, *values, **kwargs):
253253
"""
254254
self.info("+","to_jit",args=values,kwargs=kwargs)
255255
annotations=self.f.__annotations__
256-
iflen(annotations)>0:
256+
ifannotations:
257257
input_to_kwargs= {}
258258
kwargs_to_input= {}
259259
names=list(annotations.keys())
@@ -352,10 +352,10 @@ def to_jit(self, *values, **kwargs):
352352
ifinameinconstraints
353353
]
354354
names= [i.nameforiininputs]
355-
iflen(new_kwargs)>0:
355+
ifnew_kwargs:
356356
# An attribute is not named in the numpy API
357357
# but is the ONNX definition.
358-
iflen(kwargs)==0:
358+
ifnotkwargs:
359359
kwargs=new_kwargs
360360
else:
361361
kwargs=kwargs.copy()
@@ -375,13 +375,13 @@ def to_jit(self, *values, **kwargs):
375375
target_opsets=self.target_opsets,
376376
ir_version=self.ir_version,
377377
)
378-
iflen(values)>0andlen(values[0].shape)==0:
378+
ifvaluesandnotvalues[0].shape:
379379
inps=onx.graph.input[0]
380380
shape= []
381381
fordininps.type.tensor_type.shape.dim:
382382
v=d.dim_valueifd.dim_value>0elsed.dim_param
383383
shape.append(v)
384-
iflen(shape)!=0:
384+
ifshape:
385385
raiseRuntimeError(
386386
f"Shape mismatch, values[0]={values[0]} "
387387
f"and inputs={onx.graph.input}."
@@ -441,7 +441,7 @@ def move_input_to_kwargs(
441441
f"self.input_to_kwargs_ is not initialized for function{self.f} "
442442
f"from module{self.f.__module__!r}."
443443
)
444-
iflen(self.input_to_kwargs_)==0:
444+
ifnotself.input_to_kwargs_:
445445
returnvalues,kwargs
446446
new_values= []
447447
new_kwargs=kwargs.copy()

‎onnx_array_api/npx/npx_numpy_tensors.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def __bool__(self):
220220
)
221221
ifself.shape== (0,):
222222
returnFalse
223-
iflen(self.shape)!=0:
223+
ifself.shape:
224224
warnings.warn(
225225
f"Conversion to bool only works for scalar, not for{self!r}, "
226226
f"bool(...)={bool(self._tensor)}."
@@ -233,7 +233,7 @@ def __bool__(self):
233233

234234
def__int__(self):
235235
"Implicit conversion to int."
236-
iflen(self.shape)!=0:
236+
ifself.shape:
237237
raiseValueError(
238238
f"Conversion to bool only works for scalar, not for{self!r}."
239239
)
@@ -255,7 +255,7 @@ def __int__(self):
255255

256256
def__float__(self):
257257
"Implicit conversion to float."
258-
iflen(self.shape)!=0:
258+
ifself.shape:
259259
raiseValueError(
260260
f"Conversion to bool only works for scalar, not for{self!r}."
261261
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp