Fix Codacy Warnings (#477)
--------- Co-authored-by: Dario Coscia <dariocos99@gmail.com>
This commit is contained in:
committed by
Nicola Demo
parent
e3790e049a
commit
4177bfbb50
@@ -1,26 +1,40 @@
|
||||
"""Utils module."""
|
||||
|
||||
import types
|
||||
from functools import reduce
|
||||
import torch
|
||||
|
||||
from functools import reduce
|
||||
from .label_tensor import LabelTensor
|
||||
|
||||
|
||||
# Codacy error unused parameters
|
||||
def custom_warning_format(
|
||||
message, category, filename, lineno, file=None, line=None
|
||||
):
|
||||
"""
|
||||
Depewarning custom format.
|
||||
|
||||
:param str message: The warning message.
|
||||
:param class category: The warning category.
|
||||
:param str filename: The filename where the warning was raised.
|
||||
:param int lineno: The line number where the warning was raised.
|
||||
:param str file: The file object where the warning was raised.
|
||||
:param inr line: The line where the warning was raised.
|
||||
:return: The formatted warning message.
|
||||
:rtype: str
|
||||
"""
|
||||
return f"{filename}: {category.__name__}: {message}\n"
|
||||
|
||||
|
||||
def check_consistency(object, object_instance, subclass=False):
|
||||
def check_consistency(object_, object_instance, subclass=False):
|
||||
"""Helper function to check object inheritance consistency.
|
||||
Given a specific ``'object'`` we check if the object is
|
||||
instance of a specific ``'object_instance'``, or in case
|
||||
``'subclass=True'`` we check if the object is subclass
|
||||
if the ``'object_instance'``.
|
||||
|
||||
:param (iterable or class object) object: The object to check the inheritance
|
||||
:param (iterable or class object) object: The object to check the
|
||||
inheritance
|
||||
:param Object object_instance: The parent class from where the object
|
||||
is expected to inherit
|
||||
:param str object_name: The name of the object
|
||||
@@ -28,17 +42,19 @@ def check_consistency(object, object_instance, subclass=False):
|
||||
:raises ValueError: If the object does not inherit from the
|
||||
specified class
|
||||
"""
|
||||
if not isinstance(object, (list, set, tuple)):
|
||||
object = [object]
|
||||
if not isinstance(object_, (list, set, tuple)):
|
||||
object_ = [object_]
|
||||
|
||||
for obj in object:
|
||||
for obj in object_:
|
||||
try:
|
||||
if not subclass:
|
||||
assert isinstance(obj, object_instance)
|
||||
else:
|
||||
assert issubclass(obj, object_instance)
|
||||
except AssertionError:
|
||||
raise ValueError(f"{type(obj).__name__} must be {object_instance}.")
|
||||
except AssertionError as e:
|
||||
raise ValueError(
|
||||
f"{type(obj).__name__} must be {object_instance}."
|
||||
) from e
|
||||
|
||||
|
||||
def labelize_forward(forward, input_variables, output_variables):
|
||||
@@ -67,12 +83,14 @@ def labelize_forward(forward, input_variables, output_variables):
|
||||
|
||||
|
||||
def merge_tensors(tensors): # name to be changed
|
||||
"""TODO"""
|
||||
if tensors:
|
||||
return reduce(merge_two_tensors, tensors[1:], tensors[0])
|
||||
raise ValueError("Expected at least one tensor")
|
||||
|
||||
|
||||
def merge_two_tensors(tensor1, tensor2):
|
||||
"""TODO"""
|
||||
n1 = tensor1.shape[0]
|
||||
n2 = tensor2.shape[0]
|
||||
|
||||
@@ -125,7 +143,7 @@ def is_function(f):
|
||||
:return: `True` if `f` is a function, `False` otherwise.
|
||||
:rtype: bool
|
||||
"""
|
||||
return type(f) == types.FunctionType or type(f) == types.LambdaType
|
||||
return isinstance(f, (types.FunctionType, types.LambdaType))
|
||||
|
||||
|
||||
def chebyshev_roots(n):
|
||||
|
||||
Reference in New Issue
Block a user