提交 53069317 authored 作者: James Bergstra's avatar James Bergstra

redefined tensor.basic.outer in terms of dot and dimshuffle.

Rationale: this way it can be optimized with the same machinery that currently targets dot. I will add back a modified version of Outer as sandbox/blas_ger.py. In future, we should have a GER Op in blas.py, with a scipy and/or c implementation that uses BLAS's sger/dger/cger/zger functions.
上级 a4ce65ef
......@@ -5305,36 +5305,11 @@ def tensordot(x, y=None, axes=2):
return tensordot.op[axes](x, y)
#TODO: tensordot should be function as described in rst docs.
class Outer(Op):
""" Compute vector-vector outer product
"""
def make_node(self, *inputs):
inputs = map(as_tensor_variable, inputs)
x, y = inputs
nx = x.type.ndim
ny = y.type.ndim
if nx != 1: raise TypeError('non-vector arg0 to outer()', x)
if ny != 1: raise TypeError('not-vector arg1 to outer()', y)
bz = [x.type.broadcastable[0], y.type.broadcastable[0]]
i_dtypes = [input.type.dtype for input in inputs]
outputs = [tensor(scal.upcast(*i_dtypes), bz)]
return Apply(self, inputs, outputs)
def outer(x, y):
"""Return vector-vector outer product."""
return dot(
x.dimshuffle(0, 'x'),
y.dimshuffle('x', 0))
def perform(self, node, inp, out):
x, y = inp
z, = out
z[0] = numpy.outer(x, y)
def grad(self, inp, grads):
x, y = inp
gz, = grads
return dot(gz, y), dot(x, gz) #no transposing necessary
def __str__(self):
return "outer"
outer = Outer()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论