Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Friedrich Romstedt
"I'm a bit unhappy with your code, because it's so hard to read tbh. You don't like objects?" I would phrase this differently now: I think you can improve your code by using objects when they are appropriate. :-) 2010/3/6 Ian Mallett : > Unfortunately, the pure Python implementation is actually a

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Friedrich Romstedt
Sent prematurely, typed tab and then space :-(. Real message work in progress. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Friedrich Romstedt
I'm a bit unhappy with your code, because it's so hard to read tbh. You don't like objects? 2010/3/6 Ian Mallett : > 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

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Ian Mallett
On Sat, Mar 6, 2010 at 12:03 PM, Friedrich Romstedt < friedrichromst...@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 > usi

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Friedrich Romstedt
2010/3/6 Ian Mallett : > On Sat, Mar 6, 2010 at 1:20 AM, Friedrich Romstedt > wrote: >> Hmm.  Let's see ... Can you tell me how I can test the time calls in a >> script take?  I have no idea. > > I've been doing: > t1 = time.time() > #code > t2 = time.time() > print "[code]:",t2-t1 Ok. I just wo

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Ian Mallett
Hi, On Sat, Mar 6, 2010 at 1:20 AM, Friedrich Romstedt < friedrichromst...@gmail.com> wrote: > Hmm. Let's see ... Can you tell me how I can test the time calls in a > script take? I have no idea. > I've been doing: t1 = time.time() #code t2 = time.time() print "[code]:",t2-t1 > > #0.0840001106

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Friedrich Romstedt
2010/3/5 Ian Mallett : > #takes 0.04 seconds > inner = np.inner(ns, v1s - some_point) Ok, I don't know why I was able to overlook this: dotprod = (ns * (v1s - some_point)).sum(axis = 1) The things with the inner product have been deleted. Now I will really *attach* it ... Hope it's faster, Fri

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-06 Thread Friedrich Romstedt
2010/3/5 Ian Mallett : > Cool--this works perfectly now :-) :-) > Unfortunately, it's actually slower :P  Most of the slowest part is in the > removing doubles section. Hmm. Let's see ... Can you tell me how I can test the time calls in a script take? I have no idea. > #takes 0.04 seconds > i

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-05 Thread Ian Mallett
Cool--this works perfectly now :-) Unfortunately, it's actually slower :P Most of the slowest part is in the removing doubles section. Some of the costliest calls: #takes 0.04 seconds inner = np.inner(ns, v1s - some_point) #0.0840001106262 sum_1 = sum.reshape((len(sum), 1)).repeat(len(sum), ax

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-05 Thread Friedrich Romstedt
Do you have doublets in the v_array? In case not, then you owe me a donut. See attachment. Friedrich P.S.: You misunderstood too, the line you wanted to change was in context to detect back-facing triangles, and there one vertex is sufficient. shading.py Description: Binary data _

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-04 Thread Ian Mallett
Firstly, I want to thank you for all the time and attention you've obviously put into this code. On Tue, Mar 2, 2010 at 12:27 AM, Friedrich Romstedt < friedrichromst...@gmail.com> wrote: > The loop I can replace by numpy operations: > > >>> v_array > array([[1, 2, 3], > [4, 5, 6], > [

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-02 Thread Friedrich Romstedt
I'm learning too by answering your questions. 2010/3/2 Ian Mallett : > 1  v_array #array of beautifully transformed vertices from last step > 2  n_array #array of beautifully transformed normals from last step > 3  f_list  #list of vec4s, where every vec4 is three vertex indices and a > 4     

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-01 Thread Ian Mallett
Excellent--this setup works perfectly! In the areas I was concentrating on, the the speed increased an order of magnitude. However, the overall speed seems to have dropped. I believe this may be because the heavy indexing that follows on the result is slower in numpy. Is this a correct analysis?

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-01 Thread Chris Colbert
This is how I always do it: In [1]: import numpy as np In [3]: tmat = np.array([[0., 1., 0., 5.],[0., 0., 1., 3.],[1., 0., 0., 2.]]) In [4]: tmat Out[4]: array([[ 0., 1., 0., 5.], [ 0., 0., 1., 3.], [ 1., 0., 0., 2.]]) In [5]: points = np.random.random((5, 3)) In

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-03-01 Thread Friedrich Romstedt
2010/3/1 Charles R Harris : > On Sun, Feb 28, 2010 at 7:58 PM, Ian Mallett wrote: >> Excellent--and a 3D rotation matrix is 3x3--so the list can remain n*3. >> Now the question is how to apply a rotation matrix to the array of vec3? > > It looks like you want something like > > res = dot(vec, rot)

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread Charles R Harris
On Sun, Feb 28, 2010 at 7:58 PM, Ian Mallett wrote: > On Sun, Feb 28, 2010 at 6:54 PM, Charles R Harris < > charlesr.har...@gmail.com> wrote: > >> Why not just add a vector to get translation? There is no need to go the >> homogeneous form. Or you can just leave the vectors at length 4 and use a

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread Ian Mallett
On Sun, Feb 28, 2010 at 6:54 PM, Charles R Harris wrote: > Why not just add a vector to get translation? There is no need to go the > homogeneous form. Or you can just leave the vectors at length 4 and use a > slice to access the first three components. That way you can leave the ones > in place.

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread Charles R Harris
On Sun, Feb 28, 2010 at 7:35 PM, Ian Mallett wrote: > On Sun, Feb 28, 2010 at 6:31 PM, Charles R Harris < > charlesr.har...@gmail.com> wrote: > >> As I understand it, you want *different* matrices applied to each vector? > > Nope--I need the same matrix applied to each vector. > > Because 3D tran

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread Ian Mallett
On Sun, Feb 28, 2010 at 6:31 PM, Charles R Harris wrote: > As I understand it, you want *different* matrices applied to each vector? Nope--I need the same matrix applied to each vector. Because 3D translation matrices must, if I understand correctly be 4x4, the vectors must first be changed to

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread Charles R Harris
On Sun, Feb 28, 2010 at 5:53 PM, Ian Mallett wrote: > Hi, > > I have a list of vec3 lists (e.g. [[1,2,3],[4,5,6],[7,8,9],...]). To every > single one of the vec3 sublists, I am currently applying transformations. I > need to optimize this with numpy. > > To get proper results, as far as I can te

Re: [Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread josef . pktd
On Sun, Feb 28, 2010 at 7:53 PM, Ian Mallett wrote: > Hi, > > I have a list of vec3 lists (e.g. [[1,2,3],[4,5,6],[7,8,9],...]). To every > single one of the vec3 sublists, I am currently applying transformations.  I > need to optimize this with numpy. > > To get proper results, as far as I can tel

[Numpy-discussion] Iterative Matrix Multiplication

2010-02-28 Thread Ian Mallett
Hi, I have a list of vec3 lists (e.g. [[1,2,3],[4,5,6],[7,8,9],...]). To every single one of the vec3 sublists, I am currently applying transformations. I need to optimize this with numpy. To get proper results, as far as I can tell, the vec3 lists must be expressed as vec4s: [[1,2,3],[4,5,6],[7