コード例 #1
0
ファイル: basic.py プロジェクト: Roger-Chuh/depth_video
class Extend(Op):
    # See doc in instance of this Op after the class definition.
    def __init__(self, inplace=False):
        self.inplace = inplace
        if self.inplace:
            self.destroy_map = {0: [0]}
            # TODO: make destroy_handler support having views and
            # destroyed version of multiple inputs.
            # self.view_map = {0: [1]}
        else:
            # TODO: make destroy_handler support multiple view
            # self.view_map = {0: [0, 1]}
            self.view_map = {0: [0]}

    def __eq__(self, other):
        return type(self) == type(other) and self.inplace == other.inplace

    def __hash__(self):
        return hash(type(self)) ^ hash(self.inplace)

    def make_node(self, x, toAppend):
        assert isinstance(x.type, TypedListType)
        assert x.type == toAppend.type
        return Apply(self, [x, toAppend], [x.type()])

    def perform(self, node, (x, toAppend), (out, )):
        if not self.inplace:
            out[0] = list(x)
        else:
            out[0] = x
        # need to copy toAppend due to destroy_handler limitation
        if toAppend:
            o = out[0]
            for i in toAppend:
                o.append(_lessbroken_deepcopy(i))
コード例 #2
0
 def perform(self, node, inputs, outputs):
     (x, index, toInsert) = inputs
     (out, ) = outputs
     if not self.inplace:
         out[0] = list(x)
     else:
         out[0] = x
     # need to copy toAppend due to destroy_handler limitation
     toInsert = _lessbroken_deepcopy(toInsert)
     out[0].insert(index, toInsert)
コード例 #3
0
ファイル: basic.py プロジェクト: aalmah/Theano
 def perform(self, node, inputs, outputs):
     (x, index, toInsert) = inputs
     (out,) = outputs
     if not self.inplace:
         out[0] = list(x)
     else:
         out[0] = x
     # need to copy toAppend due to destroy_handler limitation
     toInsert = _lessbroken_deepcopy(toInsert)
     out[0].insert(index, toInsert)
コード例 #4
0
 def perform(self, node, inputs, outputs):
     (x, toAppend) = inputs
     (out, ) = outputs
     if not self.inplace:
         out[0] = list(x)
     else:
         out[0] = x
     # need to copy toAppend due to destroy_handler limitation
     if toAppend:
         o = out[0]
         for i in toAppend:
             o.append(_lessbroken_deepcopy(i))
コード例 #5
0
ファイル: basic.py プロジェクト: aalmah/Theano
 def perform(self, node, inputs, outputs):
     (x, toAppend) = inputs
     (out,) = outputs
     if not self.inplace:
         out[0] = list(x)
     else:
         out[0] = x
     # need to copy toAppend due to destroy_handler limitation
     if toAppend:
         o = out[0]
         for i in toAppend:
             o.append(_lessbroken_deepcopy(i))
コード例 #6
0
ファイル: basic.py プロジェクト: Roger-Chuh/depth_video
class Insert(Op):
    # See doc in instance of this Op after the class definition.
    def __init__(self, inplace=False):
        self.inplace = inplace
        if self.inplace:
            self.destroy_map = {0: [0]}
            # TODO: make destroy_handler support having views and
            # destroyed version of multiple inputs.
            # self.view_map = {0: [2]}
        else:
            # TODO: make destroy_handler support multiple view
            # self.view_map = {0: [0, 2]}
            self.view_map = {0: [0]}

    def __eq__(self, other):
        return type(self) == type(other) and self.inplace == other.inplace

    def __hash__(self):
        return hash(type(self)) ^ hash(self.inplace)

    def make_node(self, x, index, toInsert):
        assert isinstance(x.type, TypedListType)
        assert x.ttype == toInsert.type
        if not isinstance(index, Variable):
            index = T.constant(index, ndim=0, dtype='int64')
        else:
            assert index.dtype == 'int64'
            assert isinstance(index, T.TensorVariable) and index.ndim == 0
        return Apply(self, [x, index, toInsert], [x.type()])

    def perform(self, node, (x, index, toInsert), (out, )):
        if not self.inplace:
            out[0] = list(x)
        else:
            out[0] = x
        # need to copy toAppend due to destroy_handler limitation
        toInsert = _lessbroken_deepcopy(toInsert)
        out[0].insert(index, toInsert)
コード例 #7
0
 def perform(self, node, inputs, outputs):
     (out, ) = outputs
     # We need to make sure that we don't get a view on our inputs
     out[0] = [_lessbroken_deepcopy(inp) for inp in inputs]
コード例 #8
0
ファイル: basic.py プロジェクト: 12190143/Theano
 def perform(self, node, inputs, outputs):
     (out,) = outputs
     # We need to make sure that we don't get a view on our inputs
     out[0] = [_lessbroken_deepcopy(inp) for inp in inputs]