tensorflow/python/ops/parallel_for/pfor.py
File pfor.py
has 3878 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Function __init__
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def __init__(self,
Consider simplifying this complex logical expression. Open
Open
if reduce_output is not None:
new_outputs = reduce_output
# None of the inputs and control inputs were converted.
elif ((not is_inside_loop or
(not is_stateful and not some_input_converted and
Function _process_body
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _process_body(
Function _process_body
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _process_body(self, inputs_stacked, new_indices, cond_stacked,
Avoid deeply nested control flow statements. Open
Open
if converted_cinp != cinp:
some_control_input_converted = True
converted_control_ops.add(converted_cinp)
Function _init_pfor
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _init_pfor(self, parent_pfor, indices, cond_stacked, inputs,
Avoid deeply nested control flow statements. Open
Open
if output.dtype in (dtypes.resource, dtypes.variant):
if output not in self._direct_enters:
self._direct_enters.append(output)
else:
self._enters.append(output)
Avoid deeply nested control flow statements. Open
Open
if not self._fallback_to_while_loop:
message += ("Consider enabling the fallback_to_while_loop "
"option to pfor, which may run slower.")
raise ValueError(message)
Avoid deeply nested control flow statements. Open
Open
for t in cinp.outputs:
added_to_stack |= _add_to_stack(t)
else:
Avoid deeply nested control flow statements. Open
Open
for t in cinp.outputs:
converted_t = self._conversion_map[t]
if self._was_converted(t):
some_control_input_converted = True
converted_control_ops.add(converted_t.t.op)
Avoid deeply nested control flow statements. Open
Open
for old_output, new_output in zip(y_op.outputs, new_op.outputs):
handle_data_util.copy_handle_data(old_output, new_output)
new_outputs.append(wrap(new_output, False))
else:
Avoid deeply nested control flow statements. Open
Open
if loop_len is None:
batch_dim = tensor_shape.TensorShape([None])
else:
batch_dim = tensor_shape.TensorShape(loop_len)
output_shape = batch_dim.concatenate(output_shape)
Function _process_cond_stacked
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _process_cond_stacked(self, conditions, indices, inputs, inputs_stacked,
Function _process_cond_stacked
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _process_cond_stacked(self, conditions, indices, inputs, inputs_stacked,
Avoid deeply nested control flow statements. Open
Open
if (self._fallback_to_while_loop and not has_variant_outputs
and not has_vectorized_variant_inputs):
converter = functools.partial(
_fallback_converter, root_cause=root_cause, warn=self._warn)
else:
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def __init__(
Function _process_cond_unstacked
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _process_cond_unstacked(self, conditions, indices, inputs, output_tas):
Function _process_cond_unstacked
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def _process_cond_unstacked(self, conditions, indices, inputs, output_tas):
Function _stack
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def _stack(t, length):
"""stacks `t` `length` times."""
# Note that this stacking may currently be triggered, for example, when a
# loop invariant tensor with dtype variant is input to a while_loop which then
# produces a loop dependent output. Simply stacking the variants may not be
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _parse_variant_shapes_and_types
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def _parse_variant_shapes_and_types(t):
"""Extracts shape and dtype information from a variant tensor `t`."""
shapes_and_types = _variant_handle_data(t)
if shapes_and_types is None or not shapes_and_types:
raise ValueError("Required handle data not set for {!r}".format(t))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"