Ejemplo n.º 1
0
def run_ssyrk(N, l):

    A = randn(N, N).astype('float32', order='F')
    C = zeros((N, N), dtype='float32', order='F')

    start = time.time()
    for i in range(0, l):
        blas.ssyrk(1.0, A, c=C, overwrite_c=True)
    end = time.time()

    timediff = (end - start)
    mflops = (N * N * N) * l / timediff
    mflops *= 1e-6

    size = "%dx%d" % (N, N)
    print("%14s :\t%20f MFlops\t%20f sec" % (size, mflops, timediff))
Ejemplo n.º 2
0
def _XXT(XT):
    """
	[Added 30/9/2018]
	Computes X @ XT much faster than naive X @ XT.
	Notice X @ XT is symmetric, hence instead of doing the
	full matrix multiplication X @ XT which takes O(pn^2) time,
	compute only the upper triangular which takes slightly
	less time and memory.
	"""
    if XT.dtype == float64:
        return dsyrk(1, XT, trans=1).T
    return ssyrk(1, XT, trans=1).T
Ejemplo n.º 3
0
    def forward(self, X, mode=''):

        if self.l is None: self.__init__(n=self.n, l=X.shape[1])

        Y = np.dot(X, self.W)

        if 'G' in mode:

            self.X = X
            #self.Y = Y

            if self.SII is None:
                self.SII = np.zeros((self.X.shape[1], ) * 2,
                                    dtype='float32',
                                    order='F')
            ssyrk(alpha=1.0,
                  a=self.X,
                  trans=1,
                  beta=1.0,
                  c=self.SII,
                  overwrite_c=1)

        return np.argmax(Y, 1)
Ejemplo n.º 4
0
print("Calculating shape modes...")

Es = scipy.diag(scipy.sqrt(S) * 3.0).dot(E) 

# add Model_Eigenmode
for i,PC in enumerate(Es):
    modelSurfaceDSA.PointData.append( PC.reshape((-1,3)) , "Model_Eigenmode_" + str(i+1).rjust(int(scipy.log10(nrOfSurfaces)+1),"0") )
    if i>25: break

# add mean distance
meanDistance = scipy.sqrt(scipy.square(scipy.array(allPoints) - meanPoints).sum(axis=2)).mean(axis=0)
modelSurfaceDSA.PointData.append( meanDistance , "Mean_DistanceToMean")

# add tensor
apa = scipy.array(allPoints) - meanPoints
covarianceTensors = scipy.array([ blas.ssyrk( alpha = 1.0 / float(nrOfSurfaces-1) , a = apa[:,i,:].T ) for i in range( apa.shape[1] ) ])
modelSurfaceDSA.PointData.append( covarianceTensors , "CovarianceTensor")
#modelSurfaceDSA.PointData.append( covarianceTensors / scipy.array([scipy.linalg.norm(c) for c in covarianceTensors ]) , "CovarianceTensor_normalized")

print("Writing model...")

# save first and second PC
#scipy.savetxt(args.outputFilename.replace(".vtk","_PC1and2.txt") , Btruncated, delimiter="\t")

# save model
writer = vtk.vtkPolyDataWriter()
writer.SetInputData( modelSurface )
writer.SetFileName( args.outputFilename )
# writer.SetFileTypeToBinary()
writer.Update()
Ejemplo n.º 5
0
def ssyrk(a, alpha=1):
    """Returns alpha * a @ a.T for float alpha and float32 C-contiguous matrix a.
    The result is the lower triangular part of a symmetric matrix."""
    return blas.ssyrk(alpha, a.T, trans=1).T