summaryrefslogtreecommitdiff
path: root/xpxp_to_xxpp.m
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-11-19 13:00:14 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-11-19 13:00:14 -0500
commit6187aede8dc13a4fc4d5fd5463574955d702d7f4 (patch)
tree26767b68a7df52a8cef24cb74cc88453d42725c8 /xpxp_to_xxpp.m
downloadmatlab_strawberryfields-6187aede8dc13a4fc4d5fd5463574955d702d7f4.tar.gz
matlab_strawberryfields-6187aede8dc13a4fc4d5fd5463574955d702d7f4.zip
initial release
Diffstat (limited to 'xpxp_to_xxpp.m')
-rw-r--r--xpxp_to_xxpp.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/xpxp_to_xxpp.m b/xpxp_to_xxpp.m
new file mode 100644
index 0000000..fc732e2
--- /dev/null
+++ b/xpxp_to_xxpp.m
@@ -0,0 +1,32 @@
+function S_permuted = xpxp_to_xxpp(S)
+ % Permutes the entries of the input from xpxp ordering to xxpp ordering.
+ %
+ % Args:
+ % S (array): input even dimensional square matrix or a row vector
+ %
+ % Returns:
+ % S_permuted (array): permuted matrix or vector
+
+ shape = size(S);
+ if length(shape) > 2
+ error('The input matrix is not 2 dimensional');
+ end
+
+ n = shape(2);
+
+ if mod(n, 2) ~= 0
+ error('The input array is not even-dimensional');
+ end
+
+ n = n / 2;
+ ind = reshape(1:2*n, 2, [])';
+ ind = ind(:)';
+
+
+ if shape(1) == shape(2)
+ S_permuted = S(ind, ind);
+ else
+ S_permuted = S(ind);
+ end
+end
+