def orthogonal_procrustes(A, B, check_finite=True):
 if check_finite:
  A = np.asarray_chkfinite(A)
  B = np.asarray_chkfinite(B)
 else:
  A = np.asanyarray(A)
  B = np.asanyarray(B)
 if (A.ndim != 2):
  raise ValueError(('expected ndim to be 2, but observed %s' % A.ndim))
 if (A.shape != B.shape):
  raise ValueError(('the shapes of A and B differ (%s vs %s)' % (A.shape, B.shape)))
 (u, w, vt) = svd(B.T.dot(A).T)
 R = u.dot(vt)
 scale = w.sum()
 return (R, scale)

def orthogonal_procrustes ( A , B , check_finite = True ) : if check_finite : A = np . asarray_chkfinite ( A ) B = np . asarray_chkfinite ( B ) else : A = np . asanyarray ( A ) B = np . asanyarray ( B ) if ( A . ndim != 2 ) : raise ValueError ( ( 'expected ndim to be 2, but observed %s' % A . ndim ) ) if ( A . shape != B . shape ) : raise ValueError ( ( 'the shapes of A and B differ (%s vs %s)' % ( A . shape , B . shape ) ) ) ( u , w , vt ) = svd ( B . T . dot ( A ) . T ) R = u . dot ( vt ) scale = w . sum ( ) return ( R , scale )
compute the matrix solution of the orthogonal procrustes problem .