Mercurial > touhou
comparison pytouhou/utils/matrix.pyx @ 613:560b45a7d014
Don’t uselessly malloc() a matrix for multiply, the stack is here for that!
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 28 Mar 2015 19:58:50 +0100 |
parents | e15672733c93 |
children | e5361b74b9ad |
comparison
equal
deleted
inserted
replaced
612:73f134f84c7f | 613:560b45a7d014 |
---|---|
34 return new_matrix(&identity) | 34 return new_matrix(&identity) |
35 | 35 |
36 | 36 |
37 cdef void mul(Matrix *mat1, Matrix *mat2) nogil: | 37 cdef void mul(Matrix *mat1, Matrix *mat2) nogil: |
38 cdef float *d3 | 38 cdef float *d3 |
39 cdef Matrix out | |
39 | 40 |
40 out = <Matrix*> malloc(sizeof(Matrix)) | |
41 d1 = <float*>mat1 | 41 d1 = <float*>mat1 |
42 d2 = <float*>mat2 | 42 d2 = <float*>mat2 |
43 d3 = <float*>out | 43 d3 = <float*>&out |
44 for i in range(4): | 44 for i in range(4): |
45 for j in range(4): | 45 for j in range(4): |
46 d3[4*i+j] = 0 | 46 d3[4*i+j] = 0 |
47 for k in range(4): | 47 for k in range(4): |
48 d3[4*i+j] += d1[4*i+k] * d2[4*k+j] | 48 d3[4*i+j] += d1[4*i+k] * d2[4*k+j] |
49 memcpy(mat1, out, sizeof(Matrix)) | 49 memcpy(mat1, &out, sizeof(Matrix)) |
50 free(out) | |
51 | 50 |
52 | 51 |
53 cdef void flip(Matrix *mat) nogil: | 52 cdef void flip(Matrix *mat) nogil: |
54 data = <float*>mat | 53 data = <float*>mat |
55 for i in range(4): | 54 for i in range(4): |