@@ -627,26 +627,31 @@ def permutation(self, X, Y, seed=None):
627627 # generate permuted indices (unless already provided)
628628 self .permsamp = self .inputs .get ('permsamples' )
629629 if self .permsamp is None :
630+ use_permind = self .inputs .get ('permindices' )
630631 self .permsamp = gen_permsamp (self .inputs .groups ,
631632 self .inputs .n_cond ,
632633 self .inputs .n_perm ,
633634 seed = seed ,
634635 verbose = self .inputs .verbose )
636+ else :
637+ use_permind = self .inputs .get ('permindices' )
638+ self .permsamp = self .permsamp if use_permind else \
639+ np .transpose (self .permsamp , (1 , 2 , 0 ))
635640
636641 # get permuted values (parallelizing as requested)
637642 gen = utils .trange (self .inputs .n_perm , verbose = self .inputs .verbose ,
638643 desc = 'Running permutations' )
639644 with utils .get_par_func (self .inputs .n_proc ,
640645 self .__class__ ._single_perm ) as (par , func ):
641- out = par (func (self , X = X , Y = Y , inds = self .permsamp [: , i ],
642- groups = self . dummy , original = self .res [ 'y_weights' ],
643- seed = i )
646+ out = par (func (self , X = X , Y = Y , samples = self .permsamp [... , i ],
647+ use_permind = use_permind , groups = self .dummy ,
648+ original = self . res [ 'y_weights' ], seed = i )
644649 for i in gen )
645650 d_perm , ucorrs , vcorrs = [np .stack (o , axis = - 1 ) for o in zip (* out )]
646651
647652 return d_perm , ucorrs , vcorrs
648653
649- def _single_perm (self , X , Y , inds , groups = None , original = None , seed = None ):
654+ def _single_perm (self , X , Y , samples , use_permind = True , groups = None , original = None , seed = None ):
650655 """
651656 Permutes `X` (w/o replacement) and recomputes SVD
652657
@@ -656,8 +661,10 @@ def _single_perm(self, X, Y, inds, groups=None, original=None, seed=None):
656661 Input data matrix, where `S` is observations and `B` is features
657662 Y : (S, T) array_like
658663 Input data matrix, where `S` is observations and `T` is features
659- inds : (S,) array_like
660- Permutation resampling array
664+ samples : (S,) or (S, T) array_like
665+ Permutation resampling array or pre-permuted Y matrix
666+ use_permind : bool
667+ Whether `samples` is a resampling array or pre-permuted array
661668 original : (J, L) array_like
662669 Right singular vector from original decomposition of `X` and `Y`.
663670 Used to perform Procrustes rotation on permuted singular values,
@@ -679,7 +686,10 @@ def _single_perm(self, X, Y, inds, groups=None, original=None, seed=None):
679686 """
680687
681688 # calculate SVD of permuted matrices
682- Xp , Yp = self .make_permutation (X , Y , inds )
689+ if use_permind :
690+ Xp , Yp = self .make_permutation (X , Y , samples )
691+ else :
692+ Xp , Yp = X , samples
683693 U , d , V = self .svd (Xp , Yp , groups = groups , seed = seed )
684694
685695 # optionally get rotated/rescaled singular values
0 commit comments