From 61625a3180ea1a96b20b5976cc70d5d1e7a48ba3 Mon Sep 17 00:00:00 2001 From: Cor3Down Date: Thu, 17 Oct 2019 16:02:31 +0330 Subject: [PATCH 1/4] Replacing mutable default argument in __init__ --- linear_algebra/src/lib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index 5ce0f696ad71..39c7a17bf00d 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -46,11 +46,13 @@ class Vector(object): TODO: compare-operator """ - def __init__(self, components=[]): + def __init__(self, components=None): """ input: components or nothing simple constructor for init the vector """ + if components is None: + components = [] self.__components = list(components) def set(self, components): From 1c8a04b4322a79fef5ba6ed8e48f22dc36d80420 Mon Sep 17 00:00:00 2001 From: Cor3Down Date: Thu, 17 Oct 2019 16:05:58 +0330 Subject: [PATCH 2/4] Fixing typo mistakes in lib.py --- linear_algebra/src/lib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index 39c7a17bf00d..dc954953f474 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -27,7 +27,7 @@ class Vector(object): """ - This class represents a vector of arbitray size. + This class represents a vector of arbitrary size. You need to give the vector components. Overview about the methods: @@ -114,7 +114,7 @@ def __sub__(self, other): """ input: other vector assumes: other vector has the same size - returns a new vector that represents the differenz. + returns a new vector that represents the difference. """ size = len(self) if size == len(other): @@ -138,7 +138,7 @@ def __mul__(self, other): summe += self.__components[i] * other.component(i) return summe else: # error case - raise Exception("invalide operand!") + raise Exception("invalid operand!") def copy(self): """ @@ -225,7 +225,7 @@ class Matrix(object): def __init__(self, matrix, w, h): """ - simple constructor for initialzes + simple constructor for initialize the matrix with components. """ self.__matrix = matrix From f7e0c079a69f48399f09161b956fb482c05f910c Mon Sep 17 00:00:00 2001 From: Cor3Down Date: Thu, 17 Oct 2019 16:08:07 +0330 Subject: [PATCH 3/4] Simplifying chained comparisons --- linear_algebra/src/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index dc954953f474..7d90d7fe74fb 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -251,7 +251,7 @@ def changeComponent(self, x, y, value): """ changes the x-y component of this matrix """ - if x >= 0 and x < self.__height and y >= 0 and y < self.__width: + if 0 <= x < self.__height and 0 <= y < self.__width: self.__matrix[x][y] = value else: raise Exception("changeComponent: indices out of bounds") @@ -260,7 +260,7 @@ def component(self, x, y): """ returns the specified (x,y) component """ - if x >= 0 and x < self.__height and y >= 0 and y < self.__width: + if 0 <= x < self.__height and 0 <= y < self.__width: return self.__matrix[x][y] else: raise Exception("changeComponent: indices out of bounds") From 796f95dc6ab30e19e9fdad5a5e402c8cae0d1e86 Mon Sep 17 00:00:00 2001 From: John Law Date: Fri, 18 Oct 2019 00:42:31 +0800 Subject: [PATCH 4/4] Update lib.py --- linear_algebra/src/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index 7d90d7fe74fb..090427d9a520 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -225,7 +225,7 @@ class Matrix(object): def __init__(self, matrix, w, h): """ - simple constructor for initialize + simple constructor for initializing the matrix with components. """ self.__matrix = matrix