Ejemplo n.º 1
0
	def __mul__(self, other):
		if type(other) is vector:
			len_eq = len(self) == len(other)
			if not len_eq:
				raise ValueError('Vectors are not the same lenght')
			for i in my_xrange(self.__len__()):
				self.nodes[i] *= other[i]
			return self.nodes
		else:
			for i in my_xrange(self.__len__()):
				self.nodes[i] *= other
			return self.nodes
Ejemplo n.º 2
0
	def __sub__(self, other):
		len_eq = len(self) == len(other)
		if not len_eq:
			raise ValueError('Vectors are not the same lenght')
		for i in my_xrange(self.__len__()):
			self.nodes[i] -= other[i]
		return self.nodes
Ejemplo n.º 3
0
		len_eq = len(self) == len(other)
		if not len_eq:
			raise ValueError('Vectors are not the same lenght')
		for i in my_xrange(self.__len__()):
			self.nodes[i] -= other[i]
		return self.nodes

	def __mul__(self, other):
		if type(other) is vector:
			len_eq = len(self) == len(other)
			if not len_eq:
				raise ValueError('Vectors are not the same lenght')
			for i in my_xrange(self.__len__()):
				self.nodes[i] *= other[i]
			return self.nodes
		else:
			for i in my_xrange(self.__len__()):
				self.nodes[i] *= other
			return self.nodes

	def __rmul__(self, other):
		return self * other

	def __call__(self):
		yield self.nodes


f = vector(list(my_xrange(2, 15, 3)))
g = vector(list(my_xrange(3, 16, 3)))
print(g - f)
Ejemplo n.º 4
0
	def test_myrange(self):
		self.assertEquals([x for x in my_xrange(10)], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
		self.assertEquals([x for x in my_xrange(10, 17)], [10, 11, 12, 13, 14, 15, 16])
		self.assertEquals([x for x in my_xrange(1, 100, 15)], [1, 16, 31, 46, 61, 76, 91])
		self.assertEquals([x for x in my_xrange(10, 1, -1)], [10, 9, 8, 7, 6, 5, 4, 3, 2])
		self.assertEquals([x for x in my_xrange(1, 10, -1)], [])