當前位置: 首頁>>代碼示例>>Python>>正文


Python NervanaGPU.mean方法代碼示例

本文整理匯總了Python中nervanagpu.NervanaGPU.mean方法的典型用法代碼示例。如果您正苦於以下問題:Python NervanaGPU.mean方法的具體用法?Python NervanaGPU.mean怎麽用?Python NervanaGPU.mean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nervanagpu.NervanaGPU的用法示例。


在下文中一共展示了NervanaGPU.mean方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: max

# 需要導入模塊: from nervanagpu import NervanaGPU [as 別名]
# 或者: from nervanagpu.NervanaGPU import mean [as 別名]
            glops = max(glops16, glops32, glops64, glops128)

            if glops16 == glops:
                fastest = 16
            elif glops32 == glops:
                fastest = 32
            elif glops64 == glops:
                fastest = 64
            else:
                fastest = 128

            glopsref = cublas_dot(devA2, devB2, devC2, repeat=repeat)

            partial1 = ng.empty((devC1.shape[0],1), dtype=np.float32)
            partial2 = partial1[0:1,0:1]

            diff = ng.max(abs(devC2 - devC1), partial=partial1, out=partial2).get()[0,0]
            mean = ng.mean(abs(devC2), partial=partial1, out=partial2).get()[0,0]

            flops_diff = glops - glopsref

            note = "**************" if flops_diff <= 0 else ""
            
            print "Faster: %.0f gflops Choice: %d Error: %.3f%%%s" % (flops_diff, fastest, 100 * diff / mean, note)

        print "--------------------------------------------------------------------------------"


cublas.cublasDestroy(handle)
開發者ID:KayneWest,項目名稱:nervanagpu,代碼行數:31,代碼來源:cublas2.py

示例2: GPU

# 需要導入模塊: from nervanagpu import NervanaGPU [as 別名]
# 或者: from nervanagpu.NervanaGPU import mean [as 別名]

#.........這裏部分代碼省略.........

        Arguments:
            x (GPUTensor): Input tensor
            out (GPUTensor): Output tensor

        """
        self.ng.maximum(x, 0., out=out)
        return out

    def rectleaky(self, x, slope, out):
        out[:] = self.ng.maximum(x, x*slope)

    def rectleaky_derivative(self, x, slope, out):
        out[:] = self.ng.greater(x, 0) * (1.0 - slope) + slope

    def sum(self, tsr, axes, out):
        """
        Sum

        Arguments:
            tsr  (GPUTensor): Input tensor
            axes (int): Axis along which the reduction is performed. If axes
                        is None,  the tensor is flattened and reduced over
                        both dimensions.
            out (GPUTensor): Output tensor
        """
        if axes is None:
            sze = tsr.shape[0]*tsr.shape[1]
            self.ng.sum(tsr.reshape(sze, 1), axis=0, out=out)
        else:
            self.ng.sum(tsr, axis=axes, out=out)
        return out

    def mean(self, tsr, axes, out):
        """
        Calculates the arithmetic mean of the elements along the specified
        axes.

        Arguments:
            tsr (GPUTensor): Input tensor
            axes (int): Axis along which the reduction is performed. If axes
                        is None,  the tensor is flattened and reduced over
                        both dimensions.
            out (GPUTensor): Output tensor
        """
        if axes is None:
            sze = tsr.shape[0]*tsr.shape[1]
            self.ng.mean(tsr.reshape(sze, 1), axis=0, out=out)
        else:
            self.ng.mean(tsr, axis=axes, out=out)
        return out

    def min(self, tsr, axes, out):
        """
        Calculates the minimum of the elements along the specified
        axes.

        Arguments:
            tsr (GPUTensor): Input tensor
            axes (int): Axis along which the reduction is performed. If axes
                        is None,  the tensor is flattened and reduced over
                        both dimensions.
            out (GPUTensor): Output tensor
        """
        if axes is None:
            sze = tsr.shape[0]*tsr.shape[1]
開發者ID:YouVentures,項目名稱:neon,代碼行數:70,代碼來源:gpu.py

示例3:

# 需要導入模塊: from nervanagpu import NervanaGPU [as 別名]
# 或者: from nervanagpu.NervanaGPU import mean [as 別名]
    nlI = nlF = nlE = None

    print "\ncudnn vs nervanaLib:"

    parO = ng.empty((N,1), dtype=np.float32)
    parB = ng.empty((N,1), dtype=np.float32)
    parU = ng.empty((K,1), dtype=np.float32)
    maxO = parO[0:1,0:1]
    maxB = parB[0:1,0:1]
    maxU = parU[0:1,0:1]

    maxo  = ng.max(abs(cuO - nlO.T), partial=parO, out=maxO).get()[0,0]
    maxb  = ng.max(abs(cuB - nlB.T), partial=parB, out=maxB).get()[0,0]
    maxu  = ng.max(abs(cuU - nlU.T), partial=parU, out=maxU).get()[0,0]

    meano = ng.mean(abs(cuO), partial=parO, out=maxO).get()[0,0]
    meanb = ng.mean(abs(cuB), partial=parB, out=maxB).get()[0,0]
    meanu = ng.mean(abs(cuU), partial=parU, out=maxU).get()[0,0]

    print "        maxerr   mean   pct"
    print "fprop: %7.5f %6.2f %5.3f" % (maxo, meano, 100*maxo/meano)
    print "bprop: %7.5f %6.2f %5.3f" % (maxb, meanb, 100*maxb/meanb)
    print "updat: %7.5f %6.2f %5.3f" % (maxu, meanu, 100*maxu/meanu)

    # free up memory from this layer before proceeding
    cuB  = cuU  = cuO  = None
    nlB  = nlU  = nlO  = None
    parO = parB = parU = maxO = maxB = maxU = None


libcudnn.cudnnDestroyTensorDescriptor(I_desc)
開發者ID:KayneWest,項目名稱:nervanagpu,代碼行數:33,代碼來源:cudnn.py


注:本文中的nervanagpu.NervanaGPU.mean方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。