Skip to content

Fixing Some Minor Issues #1386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions linear_algebra/src/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.__components = list(components or [])

def set(self, components):
Expand Down Expand Up @@ -112,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):
Expand All @@ -136,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):
"""
Expand Down Expand Up @@ -223,7 +225,7 @@ class Matrix(object):

def __init__(self, matrix, w, h):
"""
simple constructor for initialzes
simple constructor for initializing
the matrix with components.
"""
self.__matrix = matrix
Expand All @@ -249,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")
Expand All @@ -258,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")
Expand Down