[Numpy-discussion] Iterative Matrix Multiplication
Ian Mallett
geometrian at gmail.com
Sat Mar 6 15:08:23 EST 2010
On Sat, Mar 6, 2010 at 12:03 PM, Friedrich Romstedt <
friedrichromstedt at gmail.com> wrote:
> At the moment, I can do nothing about that. Seems that we have
> reached the limit. Anyhow, is it now faster than your Python list
> implementation, and if yes, how much? How large was your gain by
> using numpy means at all? I'm just curious.
>
Unfortunately, the pure Python implementation is actually an order of
magnitude faster. The fastest solution right now is to use numpy for the
transformations, then convert it back into a list (.tolist()) and use Python
for the rest.
Here's the actual Python code.
def glLibInternal_edges(object,lightpos):
edge_set = set([])
edges = {}
for sublist in xrange(object.number_of_lists): #There's only one sublist
here
face_data = object.light_volume_face_data[sublist]
for indices in face_data: #v1,v2,v3,n
normal = object.transformed_normals[sublist][indices[3]]
v1,v2,v3 = [ object.transformed_vertices[sublist][indices[i]]
for i in xrange(3) ]
if
abs_angle_between_rad(normal,vec_subt(v1,lightpos))<pi_over_two:
for p1,p2 in [[indices[0],indices[1]],
[indices[1],indices[2]],
[indices[2],indices[0]]]:
edge = [p1,p2]
index = 0
edge2 = list(edge)
edge2.sort()
edge2 = tuple(edge2)
if edge2 in edges: edges[edge2][1] += 1
else: edges[edge2] = [edge,1]
edges2 = []
for edge_data in edges.values():
if edge_data[1] == 1:
p1 = object.transformed_vertices[sublist][edge_data[0][0]]
p2 = object.transformed_vertices[sublist][edge_data[0][1]]
edges2.append([p1,p2])
return edges2
Friedrich
>
Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100306/c8546cad/attachment.html>
More information about the NumPy-Discussion
mailing list