Skip to content
Snippets Groups Projects
Commit cdbd3a85 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Rodriguez -> g: some more speedup


Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@584 4c865b51-4357-4376-afb4-474e03ccb993
parent 40be01eb
No related branches found
No related tags found
No related merge requests found
...@@ -21,37 +21,34 @@ function invg = Rod2g(r) ...@@ -21,37 +21,34 @@ function invg = Rod2g(r)
% AK - 13/11/2008 rewritten with the permutation and identity matrices hard % AK - 13/11/2008 rewritten with the permutation and identity matrices hard
% coded rather than derived each time (2x faster!) % coded rather than derived each time (2x faster!)
% %
% 2012-03-12, Modified by Nicola Vigano', nicola.vigano@esrf.fr % 2012, Modified by Nicola Vigano', nicola.vigano@esrf.fr
% - Made even faster, by saving partial computation: 6x faster than the latest :) % - Made even faster, by saving partial computation: 15x faster than the latest :)
% Initialise the orientation matrix % initialise the permutation tensor (do the 3rd as 1st, to allocate it all)
invg = zeros(3, 3); e(:, :, 3) = [ 0 1 0; ...
% initialise the permutation tensor -1 0 0; ...
% e = calc_perm_tensor(); 0 0 0];
e(:, :, 1) = [ 0 0 0; ... e(:, :, 1) = [ 0 0 0; ...
0 0 1; ... 0 0 1; ...
0 -1 0]; 0 -1 0];
e(:, :, 2) = [ 0 0 -1; ... e(:, :, 2) = [ 0 0 -1; ...
0 0 0; ... 0 0 0; ...
1 0 0]; 1 0 0];
e(:, :, 3) = [ 0 1 0; ...
-1 0 0; ...
0 0 0];
delta = eye(3);
% Saving partial computation % Saving partial computation
rSquareNorm = dot(r, r); rSquareNorm = sum(r .^ 2);
% Initialise the orientation matrix
invg = zeros(3, 3);
% Loop over the elements of the orientation matrix % Loop over the elements of the orientation matrix
for ii = 1:3 for ii = 1:3
for jj = 1:3 for jj = 1:3
invg(ii, jj) = (1 - rSquareNorm) * delta(ii, jj) + 2 * r(ii) * r(jj); invg(ii, jj) = (1 - rSquareNorm) * (ii == jj) + 2 * r(ii) * r(jj);
% Summing over the remaining component % Summing over the remaining component
for k = 1:3 for k = 1:3
invg(ii, jj) = invg(ii, jj) - 2 * e(ii, jj, k) * r(k); invg(ii, jj) = invg(ii, jj) - 2 * r(k) * e(ii, jj, k);
end end
invg(ii, jj) = invg(ii, jj) / (1 + rSquareNorm);
end end
end end
invg = invg / (1 + rSquareNorm);
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment