Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis12-cl/src/include/Diderot/cl-inline-matrix.h
ViewVC logotype

Diff of /branches/vis12-cl/src/include/Diderot/cl-inline-matrix.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3163, Sat Mar 28 11:21:09 2015 UTC revision 3164, Sun Mar 29 08:53:37 2015 UTC
# Line 18  Line 18 
18  /********** 2x2 matrix functions **********/  /********** 2x2 matrix functions **********/
19    
20    
21  inline void zero2x2f (Diderot_Mat2x2_t dst)  inline void zero2x2 (Diderot_Mat2x2_t dst)
22  {  {
23      dst[0] = (float2)(0.0, 0.0);      dst[0] = (Diderot_vec2_t)(0.0, 0.0);
24      dst[1] = (float2)(0.0, 0.0);      dst[1] = (Diderot_vec2_t)(0.0, 0.0);
25  }  }
26    
27  inline void identity2x2f (Diderot_Mat2x2_t dst)  inline void identity2x2 (Diderot_Mat2x2_t dst)
28  {  {
29      dst[0] = (float2)(1.0, 0.0);      dst[0] = (Diderot_vec2_t)(1.0, 0.0);
30      dst[1] = (float2)(0.0, 1.0);      dst[1] = (Diderot_vec2_t)(0.0, 1.0);
31  }  }
32    
33  inline void copy2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)  inline void copy2x2 (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)
34  {  {
35      dst[0] = src[0];      dst[0] = src[0];
36      dst[1] = src[1];      dst[1] = src[1];
37  }  }
38    
39  inline void scale2x2f (Diderot_Mat2x2_t dst, float s, Diderot_Mat2x2_t src)  inline void scale2x2 (Diderot_Mat2x2_t dst, float s, Diderot_Mat2x2_t src)
40  {  {
41      float2 scale = (float2)(s, s);      Diderot_vec2_t scale = (Diderot_vec2_t)(s, s);
42      dst[0] = scale * src[0];      dst[0] = scale * src[0];
43      dst[1] = scale * src[1];      dst[1] = scale * src[1];
44  }  }
45    
46  inline void add2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)  inline void add2x2 (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)
47  {  {
48      dst[0] = a[0] + b[0];      dst[0] = a[0] + b[0];
49      dst[1] = a[1] + b[1];      dst[1] = a[1] + b[1];
50  }  }
51    
52  inline void sub2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)  inline void sub2x2 (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)
53  {  {
54      dst[0] = a[0] - b[0];      dst[0] = a[0] - b[0];
55      dst[1] = a[1] - b[1];      dst[1] = a[1] - b[1];
56  }  }
57    
58  inline float2 mulVec3Mat2x2f (float2 v, Diderot_Mat2x2_t m)  inline Diderot_vec2_t mulVec3Mat2x2 (Diderot_vec2_t v, Diderot_Mat2x2_t m)
59  {  {
60      return (float2)(      return (Diderot_vec2_t)(
61          dot(v, (float2)(m[0].s0, m[1].s0)),          dot(v, (Diderot_vec2_t)(m[0].s0, m[1].s0)),
62          dot(v, (float2)(m[0].s1, m[1].s1)));          dot(v, (Diderot_vec2_t)(m[0].s1, m[1].s1)));
63  }  }
64    
65  inline float2 mulMat2x2Vec2f (Diderot_Mat2x2_t m, float2 v)  inline Diderot_vec2_t mulMat2x2Vec2 (Diderot_Mat2x2_t m, Diderot_vec2_t v)
66  {  {
67      return (float2)(dot(m[0], v), dot(m[1], v));      return (Diderot_vec2_t)(dot(m[0], v), dot(m[1], v));
68  }  }
69    
70  inline void mulMat2x2Mat2x2f ( Diderot_Mat2x2_t dst,  Diderot_Mat2x2_t m1,   Diderot_Mat2x2_t m2)  inline void mulMat2x2Mat2x2 (Diderot_Mat2x2_t dst,  Diderot_Mat2x2_t m1,   Diderot_Mat2x2_t m2)
71  {  {
72      dst[0] = (float2)(      dst[0] = (Diderot_vec2_t)(
73          dot(m1[0], (float2)(m2[0].s0, m2[1].s0)),          dot(m1[0], (Diderot_vec2_t)(m2[0].s0, m2[1].s0)),
74          dot(m1[0], (float2)(m2[0].s1, m2[1].s1)));          dot(m1[0], (Diderot_vec2_t)(m2[0].s1, m2[1].s1)));
75      dst[1] = (float2)(      dst[1] = (Diderot_vec2_t)(
76          dot(m1[1], (float2)(m2[0].s0, m2[1].s0)),          dot(m1[1], (Diderot_vec2_t)(m2[0].s0, m2[1].s0)),
77          dot(m1[1], (float2)(m2[0].s1, m2[1].s1)));          dot(m1[1], (Diderot_vec2_t)(m2[0].s1, m2[1].s1)));
78  }  }
79    
80  inline void transpose2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)  inline void transpose2x2 (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)
81  {  {
82      dst[0] = (float2)(src[0].s0, src[1].s0);      dst[0] = (Diderot_vec2_t)(src[0].s0, src[1].s0);
83      dst[1] = (float2)(src[0].s1, src[1].s1);      dst[1] = (Diderot_vec2_t)(src[0].s1, src[1].s1);
84  }  }
85    
86  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
87  inline float norm2x2f (Diderot_Mat2x2_t m)  inline float norm2x2 (Diderot_Mat2x2_t m)
88  {  {
89      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]));      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]));
90  }  }
# Line 92  Line 92 
92    
93  /********** 3x3 matrix functions **********/  /********** 3x3 matrix functions **********/
94    
95  inline void zero3x3f (Diderot_Mat3x3_t dst)  inline void zero3x3 (Diderot_Mat3x3_t dst)
96  {  {
97      dst[0] = VEC3(0.0, 0.0, 0.0);      dst[0] = VEC3(0.0, 0.0, 0.0);
98      dst[1] = VEC3(0.0, 0.0, 0.0);      dst[1] = VEC3(0.0, 0.0, 0.0);
99      dst[2] = VEC3(0.0, 0.0, 0.0);      dst[2] = VEC3(0.0, 0.0, 0.0);
100  }  }
101    
102  inline void identity3x3f (Diderot_Mat3x3_t dst)  inline void identity3x3 (Diderot_Mat3x3_t dst)
103  {  {
104      dst[0] = VEC3(1.0, 0.0, 0.0);      dst[0] = VEC3(1.0, 0.0, 0.0);
105      dst[1] = VEC3(0.0, 1.0, 0.0);      dst[1] = VEC3(0.0, 1.0, 0.0);
106      dst[2] = VEC3(0.0, 0.0, 1.0);      dst[2] = VEC3(0.0, 0.0, 1.0);
107  }  }
108    
109  inline void copy3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)  inline void copy3x3 (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)
110  {  {
111      dst[0] = src[0];      dst[0] = src[0];
112      dst[1] = src[1];      dst[1] = src[1];
113      dst[2] = src[2];      dst[2] = src[2];
114  }  }
115    
116  inline void scale3x3f (Diderot_Mat3x3_t dst, float s, Diderot_Mat3x3_t src)  inline void scale3x3 (Diderot_Mat3x3_t dst, float s, Diderot_Mat3x3_t src)
117  {  {
118      float3 scale = VEC3(s, s, s);      Diderot_vec3_t scale = VEC3(s, s, s);
119      dst[0] = scale * src[0];      dst[0] = scale * src[0];
120      dst[1] = scale * src[1];      dst[1] = scale * src[1];
121      dst[2] = scale * src[2];      dst[2] = scale * src[2];
122  }  }
123    
124  inline void add3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)  inline void add3x3 (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)
125  {  {
126      dst[0] = a[0] + b[0];      dst[0] = a[0] + b[0];
127      dst[1] = a[1] + b[1];      dst[1] = a[1] + b[1];
128      dst[2] = a[2] + b[2];      dst[2] = a[2] + b[2];
129  }  }
130    
131  inline void sub3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)  inline void sub3x3 (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)
132  {  {
133      dst[0] = a[0] - b[0];      dst[0] = a[0] - b[0];
134      dst[1] = a[1] - b[1];      dst[1] = a[1] - b[1];
135      dst[2] = a[2] - b[2];      dst[2] = a[2] - b[2];
136  }  }
137    
138  inline float3 mulVec3Mat3x3f (float3 v, Diderot_Mat3x3_t m)  inline Diderot_vec3_t mulVec3Mat3x3 (Diderot_vec3_t v, Diderot_Mat3x3_t m)
139  {  {
140      return VEC3(      return VEC3(
141          dot(v, VEC3(m[0].s0, m[1].s0, m[2].s0)),          dot(v, VEC3(m[0].s0, m[1].s0, m[2].s0)),
# Line 143  Line 143 
143          dot(v, VEC3(m[0].s2, m[1].s2, m[2].s2)));          dot(v, VEC3(m[0].s2, m[1].s2, m[2].s2)));
144  }  }
145    
146  inline float3 mulMat3x3Vec3f (Diderot_Mat3x3_t m, float3 v)  inline Diderot_vec3_t mulMat3x3Vec3 (Diderot_Mat3x3_t m, Diderot_vec3_t v)
147  {  {
148      return VEC3(dot(m[0], v), dot(m[1], v), dot(m[2], v));      return VEC3(dot(m[0], v), dot(m[1], v), dot(m[2], v));
149  }  }
150    
151  inline void mulMat3x3Mat3x3f ( Diderot_Mat3x3_t dst,  Diderot_Mat3x3_t m1,  Diderot_Mat3x3_t m2)  inline void mulMat3x3Mat3x3 (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t m1, Diderot_Mat3x3_t m2)
152  {  {
153      dst[0] = VEC3(      dst[0] = VEC3(
154          dot(m1[0], VEC3(m2[0].s0, m2[1].s0, m2[2].s0)),          dot(m1[0], VEC3(m2[0].s0, m2[1].s0, m2[2].s0)),
# Line 163  Line 163 
163          dot(m1[2], VEC3(m2[0].s1, m2[1].s1, m2[2].s1)),          dot(m1[2], VEC3(m2[0].s1, m2[1].s1, m2[2].s1)),
164          dot(m1[2], VEC3(m2[0].s2, m2[1].s2, m2[2].s2)));          dot(m1[2], VEC3(m2[0].s2, m2[1].s2, m2[2].s2)));
165  }  }
166  inline void transpose3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)  inline void transpose3x3 (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)
167  {  {
168      dst[0] = VEC3(src[0].s0, src[1].s0, src[2].s0);      dst[0] = VEC3(src[0].s0, src[1].s0, src[2].s0);
169      dst[1] = VEC3(src[0].s1, src[1].s1, src[2].s1);      dst[1] = VEC3(src[0].s1, src[1].s1, src[2].s1);
# Line 171  Line 171 
171  }  }
172    
173  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
174  inline float norm3x3f (Diderot_Mat3x3_t m)  inline float norm3x3 (Diderot_Mat3x3_t m)
175  {  {
176      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]));      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]));
177  }  }
# Line 179  Line 179 
179    
180  /********** 4x4 matrix functions **********/  /********** 4x4 matrix functions **********/
181    
182  inline void copy4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)  inline void copy4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
183  {  {
184      dst[0] = src[0];      dst[0] = src[0];
185      dst[1] = src[1];      dst[1] = src[1];
# Line 187  Line 187 
187      dst[3] = src[3];      dst[3] = src[3];
188  }  }
189    
190  inline void transpose4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)  inline void transpose4x4 (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
191  {  {
192      dst[0] = (float4)(src[0].s0, src[1].s0, src[2].s0, src[3].s0);      dst[0] = (Diderot_vec4_t)(src[0].s0, src[1].s0, src[2].s0, src[3].s0);
193      dst[1] = (float4)(src[0].s1, src[1].s1, src[2].s1, src[3].s1);      dst[1] = (Diderot_vec4_t)(src[0].s1, src[1].s1, src[2].s1, src[3].s1);
194      dst[2] = (float4)(src[0].s2, src[1].s2, src[2].s2, src[3].s2);      dst[2] = (Diderot_vec4_t)(src[0].s2, src[1].s2, src[2].s2, src[3].s2);
195      dst[3] = (float4)(src[0].s3, src[1].s3, src[2].s3, src[3].s3);      dst[3] = (Diderot_vec4_t)(src[0].s3, src[1].s3, src[2].s3, src[3].s3);
196  }  }
197    
198  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
199  inline float norm4x4f (Diderot_Mat4x4_t m)  inline float norm4x4 (Diderot_Mat4x4_t m)
200  {  {
201      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]) + dot(m[3],m[3]));      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]) + dot(m[3],m[3]));
202  }  }

Legend:
Removed from v.3163  
changed lines
  Added in v.3164

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0