diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-11-19 13:00:14 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2024-11-19 13:00:14 -0500 |
commit | 6187aede8dc13a4fc4d5fd5463574955d702d7f4 (patch) | |
tree | 26767b68a7df52a8cef24cb74cc88453d42725c8 /xxpp_to_xpxp.m | |
download | matlab_strawberryfields-6187aede8dc13a4fc4d5fd5463574955d702d7f4.tar.gz matlab_strawberryfields-6187aede8dc13a4fc4d5fd5463574955d702d7f4.zip |
initial release
Diffstat (limited to 'xxpp_to_xpxp.m')
-rw-r--r-- | xxpp_to_xpxp.m | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/xxpp_to_xpxp.m b/xxpp_to_xpxp.m new file mode 100644 index 0000000..d6efbe9 --- /dev/null +++ b/xxpp_to_xpxp.m @@ -0,0 +1,30 @@ +function S_permuted = xxpp_to_xpxp(S) + % Permutes the entries of the input from xxpp ordering to xpxp ordering. + % + % Args: + % S (array): input even dimensional square matrix or array + % + % Returns: + % S_permuted (array): permuted matrix or array + + shape = size(S); + n = shape(1); + + 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 length(shape) == 2 + if shape(1) ~= shape(2) + error('The input matrix is not square'); + end + S_permuted = S(ind, ind); + else + S_permuted = S(ind); + end +end + |