commit 16d0947435afaab8ddaf9d66078e108e0d96e483
parent 0d404b0e2d3d10a2fc552048e797d4a34fd2e422
Author: Miroslav Urbanek <mu@miroslavurbanek.com>
Date: Wed, 28 Jun 2017 08:44:25 +0200
Permute indices in decompositions as requested
Callers expect that array-decomposition and tensor-decomposition
return the first tensor with a specified order of indices. If the
decomposition indices are left indices, but they are not in the
correct order, permute them.
Diffstat:
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/tebdol/array.lisp b/tebdol/array.lisp
@@ -161,7 +161,8 @@
(let ((r (array-rank array)))
;; permute indices if they are not in the correct order
- (unless (eql (indices-position r indices) :left)
+ (unless (and (eql (indices-position r indices) :left)
+ (apply #'< indices))
(let ((nl (loop for i below (length indices) collect i)))
(setf array (array-permute array (make-indices-permutation r indices nl)))
(setf indices nl)))
diff --git a/tebdol/tensor.lisp b/tebdol/tensor.lisp
@@ -574,7 +574,8 @@
(setf indices (list indices)))
;; permute if necessary
(let ((r (tensor-rank tensor)))
- (unless (eql (indices-position r indices) :left)
+ (unless (and (eql (indices-position r indices) :left)
+ (apply #'< indices))
(let ((l (loop for i below (length indices) collect i)))
(setf tensor (tensor-permute tensor (make-indices-permutation r indices l)))
(setf indices l))))