aboutsummaryrefslogtreecommitdiff
path: root/python_originals/xxpp_to_xpxp.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-11-19 13:40:38 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-11-19 13:40:38 -0500
commit984d56b4d94bf298a197f1567834451acf49cab9 (patch)
treefc545b26d7997106a77f0353aa61062f5b77e098 /python_originals/xxpp_to_xpxp.py
parent268050742bfd920490d90152686178ffba1f6a85 (diff)
downloadmatlab_strawberryfields-984d56b4d94bf298a197f1567834451acf49cab9.tar.gz
matlab_strawberryfields-984d56b4d94bf298a197f1567834451acf49cab9.zip
dir renamev0.1
Diffstat (limited to 'python_originals/xxpp_to_xpxp.py')
-rw-r--r--python_originals/xxpp_to_xpxp.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/python_originals/xxpp_to_xpxp.py b/python_originals/xxpp_to_xpxp.py
new file mode 100644
index 0000000..940d8b8
--- /dev/null
+++ b/python_originals/xxpp_to_xpxp.py
@@ -0,0 +1,25 @@
+def 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:
+ (array): permuted matrix or array
+ """
+ shape = S.shape
+ n = shape[0]
+
+ if n % 2 != 0:
+ raise ValueError("The input array is not even-dimensional")
+
+ n = n // 2
+ ind = np.arange(2 * n).reshape(2, -1).T.flatten()
+
+ if len(shape) == 2:
+ if shape[0] != shape[1]:
+ raise ValueError("The input matrix is not square")
+ return S[:, ind][ind]
+
+ return S[ind]
+