提交 04b21e34 authored 作者: amrithasuresh's avatar amrithasuresh

reverted np as numpy

上级 cc6a5c7b
...@@ -130,7 +130,7 @@ import logging ...@@ -130,7 +130,7 @@ import logging
import os import os
import time import time
import numpy as np import numpy
import numpy.distutils import numpy.distutils
try: try:
import numpy.distutils.__config__ import numpy.distutils.__config__
...@@ -166,10 +166,10 @@ try: ...@@ -166,10 +166,10 @@ try:
# `scipy.linalg.blas.fblas` with `scipy.linalg.blas`. # `scipy.linalg.blas.fblas` with `scipy.linalg.blas`.
# See http://github.com/scipy/scipy/pull/358 # See http://github.com/scipy/scipy/pull/358
fblas = scipy.linalg.blas fblas = scipy.linalg.blas
_blas_gemv_fns = {np.dtype('float32'): fblas.sgemv, _blas_gemv_fns = {numpy.dtype('float32'): fblas.sgemv,
np.dtype('float64'): fblas.dgemv, numpy.dtype('float64'): fblas.dgemv,
np.dtype('complex64'): fblas.cgemv, numpy.dtype('complex64'): fblas.cgemv,
np.dtype('complex128'): fblas.zgemv} numpy.dtype('complex128'): fblas.zgemv}
except ImportError as e: except ImportError as e:
have_fblas = False have_fblas = False
# This is used in Gemv and ScipyGer. We use CGemv and CGer # This is used in Gemv and ScipyGer. We use CGemv and CGer
...@@ -190,12 +190,12 @@ def check_init_y(): ...@@ -190,12 +190,12 @@ def check_init_y():
if not have_fblas: if not have_fblas:
check_init_y._result = False check_init_y._result = False
y = float('NaN') * np.ones((2,)) y = float('NaN') * numpy.ones((2,))
x = np.ones((2,)) x = numpy.ones((2,))
A = np.ones((2, 2)) A = numpy.ones((2, 2))
gemv = _blas_gemv_fns[y.dtype] gemv = _blas_gemv_fns[y.dtype]
gemv(1.0, A.T, x, 0.0, y, overwrite_y=True, trans=True) gemv(1.0, A.T, x, 0.0, y, overwrite_y=True, trans=True)
check_init_y._result = np.isnan(y).any() check_init_y._result = numpy.isnan(y).any()
return check_init_y._result return check_init_y._result
...@@ -269,7 +269,7 @@ class Gemv(Op): ...@@ -269,7 +269,7 @@ class Gemv(Op):
out_storage[0][0] = gemv(alpha, A.T, x, beta, y, out_storage[0][0] = gemv(alpha, A.T, x, beta, y,
overwrite_y=self.inplace, trans=True) overwrite_y=self.inplace, trans=True)
else: else:
out = np.dot(A, x) out = numpy.dot(A, x)
if alpha != 1: if alpha != 1:
out *= alpha out *= alpha
if beta != 0: if beta != 0:
...@@ -277,7 +277,7 @@ class Gemv(Op): ...@@ -277,7 +277,7 @@ class Gemv(Op):
out += beta * y out += beta * y
else: else:
out += y out += y
out_storage[0][0] = np.asarray(out, dtype=y.dtype) out_storage[0][0] = numpy.asarray(out, dtype=y.dtype)
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
return [input_shapes[0]] return [input_shapes[0]]
...@@ -341,9 +341,9 @@ class Ger(Op): ...@@ -341,9 +341,9 @@ class Ger(Op):
else: else:
A = cA.copy() A = cA.copy()
if calpha != 1: if calpha != 1:
A += calpha * np.outer(cx, cy) A += calpha * numpy.outer(cx, cy)
else: else:
A += np.outer(cx, cy) A += numpy.outer(cx, cy)
cZ[0] = A cZ[0] = A
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
...@@ -902,26 +902,26 @@ class Gemm(GemmRelated): ...@@ -902,26 +902,26 @@ class Gemm(GemmRelated):
if not self.inplace: if not self.inplace:
z = z.copy() # the original z will not be changed z = z.copy() # the original z will not be changed
if z.shape == (): if z.shape == ():
z.itemset(z * a + b * np.dot(x, y)) z.itemset(z * a + b * numpy.dot(x, y))
zout[0] = z zout[0] = z
else: else:
if b == 0.0: if b == 0.0:
if a == 1.0: if a == 1.0:
z[:] = np.dot(x, y) z[:] = numpy.dot(x, y)
elif a == -1.0: elif a == -1.0:
z[:] = -np.dot(x, y) z[:] = -numpy.dot(x, y)
else: else:
z[:] = a * np.dot(x, y) z[:] = a * numpy.dot(x, y)
elif b == 1.0: elif b == 1.0:
if a == 1.0: if a == 1.0:
z += np.dot(x, y) z += numpy.dot(x, y)
elif a == -1.0: elif a == -1.0:
z -= np.dot(x, y) z -= numpy.dot(x, y)
else: else:
z += a * np.dot(x, y) z += a * numpy.dot(x, y)
else: else:
z *= b z *= b
z += a * np.dot(x, y) z += a * numpy.dot(x, y)
zout[0] = z zout[0] = z
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
...@@ -1068,7 +1068,7 @@ def _as_scalar(res, dtype=None): ...@@ -1068,7 +1068,7 @@ def _as_scalar(res, dtype=None):
"""Return None or a TensorVariable whose type is in T.float_scalar_types""" """Return None or a TensorVariable whose type is in T.float_scalar_types"""
if dtype is None: if dtype is None:
dtype = config.floatX dtype = config.floatX
if np.all(res.type.broadcastable): if numpy.all(res.type.broadcastable):
while res.owner and isinstance(res.owner.op, T.DimShuffle): while res.owner and isinstance(res.owner.op, T.DimShuffle):
res = res.owner.inputs[0] res = res.owner.inputs[0]
# may still have some number of True's # may still have some number of True's
...@@ -1218,7 +1218,7 @@ def _gemm_canonicalize(r, scale, rval, maxclients): ...@@ -1218,7 +1218,7 @@ def _gemm_canonicalize(r, scale, rval, maxclients):
vectors = [] vectors = []
matrices = [] matrices = []
for i in r.owner.inputs: for i in r.owner.inputs:
if np.all(i.type.broadcastable): if numpy.all(i.type.broadcastable):
while i.owner and isinstance(i.owner.op, T.DimShuffle): while i.owner and isinstance(i.owner.op, T.DimShuffle):
i = i.owner.inputs[0] i = i.owner.inputs[0]
if i.type.broadcastable: if i.type.broadcastable:
...@@ -1541,7 +1541,7 @@ class Dot22(GemmRelated): ...@@ -1541,7 +1541,7 @@ class Dot22(GemmRelated):
x, y = inp x, y = inp
z, = out z, = out
try: try:
z[0] = np.asarray(np.dot(x, y)) z[0] = numpy.asarray(numpy.dot(x, y))
except ValueError as e: except ValueError as e:
# The error raised by numpy has no shape information, we mean to # The error raised by numpy has no shape information, we mean to
# add that # add that
...@@ -1706,8 +1706,8 @@ def local_dot22_to_ger_or_gemv(node): ...@@ -1706,8 +1706,8 @@ def local_dot22_to_ger_or_gemv(node):
x, y = node.inputs x, y = node.inputs
xb = x.broadcastable xb = x.broadcastable
yb = y.broadcastable yb = y.broadcastable
one = T.as_tensor_variable(np.asarray(1, dtype=x.dtype)) one = T.as_tensor_variable(numpy.asarray(1, dtype=x.dtype))
zero = T.as_tensor_variable(np.asarray(0, dtype=x.dtype)) zero = T.as_tensor_variable(numpy.asarray(0, dtype=x.dtype))
if xb[1] and yb[0]: if xb[1] and yb[0]:
# x and y are both vectors so this might qualifies for a GER # x and y are both vectors so this might qualifies for a GER
xv = x.dimshuffle(0) xv = x.dimshuffle(0)
...@@ -1812,7 +1812,7 @@ class Dot22Scalar(GemmRelated): ...@@ -1812,7 +1812,7 @@ class Dot22Scalar(GemmRelated):
x, y, scalar = inp x, y, scalar = inp
z, = out z, = out
try: try:
z[0] = np.asarray(scalar * np.dot(x, y)) z[0] = numpy.asarray(scalar * numpy.dot(x, y))
except ValueError as e: except ValueError as e:
# The error raised by numpy has no shape information, we # The error raised by numpy has no shape information, we
# mean to add that # mean to add that
...@@ -2036,9 +2036,9 @@ class BatchedDot(Op): ...@@ -2036,9 +2036,9 @@ class BatchedDot(Op):
shape = self.infer_shape(node, [i.shape for i in inp])[0] shape = self.infer_shape(node, [i.shape for i in inp])[0]
dtype = node.outputs[0].dtype dtype = node.outputs[0].dtype
z0 = z[0] = np.empty(shape, dtype=dtype) z0 = z[0] = numpy.empty(shape, dtype=dtype)
for i in xrange(z0.shape[0]): for i in xrange(z0.shape[0]):
z0[i] = np.dot(x[i], y[i]) z0[i] = numpy.dot(x[i], y[i])
def c_support_code(self): def c_support_code(self):
batch_gemm_defn = """ batch_gemm_defn = """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论