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

added old convenience constructors vertical_stack and horizontal_stack, now using concatenate

上级 7b9c8bf9
...@@ -1640,6 +1640,27 @@ def get_vector_length(v): ...@@ -1640,6 +1640,27 @@ def get_vector_length(v):
return v.owner.inputs[0].type.ndim return v.owner.inputs[0].type.ndim
raise ValueError("length not known") raise ValueError("length not known")
@constructor
def horizontal_stack(*args):
"""
Horizontally stack two L{Tensor}s.
Stack two L{Tensor}s along the second axis (column wise). These
L{Tensor}s must have the same shape along all dimensions but the
second.
@note: Unlike VerticalStack, we assume that the L{Tensor}s have
two dimensions.
"""
assert x.type.ndim == 2
assert y.type.ndim == 2
return concatenate([x,y], axis=1)
@constructor
def vertical_stack(*args):
assert x.type.ndim == 2
assert y.type.ndim == 2
return concatenate(args, axis=0)
if 0: #vertical and horizontal stacking are deprecated. Better to use stack() and join(). if 0: #vertical and horizontal stacking are deprecated. Better to use stack() and join().
class VerticalStack(Op): class VerticalStack(Op):
""" """
...@@ -1681,19 +1702,6 @@ if 0: #vertical and horizontal stacking are deprecated. Better to use stack() a ...@@ -1681,19 +1702,6 @@ if 0: #vertical and horizontal stacking are deprecated. Better to use stack() a
return gz[:xs[0]], gz[xs[0]:] return gz[:xs[0]], gz[xs[0]:]
vertical_stack = VerticalStack() vertical_stack = VerticalStack()
def horizontal_stack(x, y):
"""
Horizontally stack two L{Tensor}s.
Stack two L{Tensor}s along the second axis (column wise). These
L{Tensor}s must have the same shape along all dimensions but the
second.
@note: Unlike VerticalStack, we assume that the L{Tensor}s have
two dimensions.
"""
assert x.type.ndim == 2
assert y.type.ndim == 2
return transpose(vertical_stack(x.T, y.T))
class MakeVector(Op): class MakeVector(Op):
"""WRITEME""" """WRITEME"""
def __init__(self, stype): def __init__(self, stype):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论