コード例 #1
0
ファイル: semispace.py プロジェクト: filmackay/flypy
    def collect(self, size, top_of_stack):
        """
        Collect garbage by copying all live data to tospace, starting with
        `roots`. If there is no or little garbage and we're running out of heap
        space, grow the heap. `size` indicates the size of the requested memory.

        This method may raise MemoryError.

        For every root, we determine the trace function and call it on the root.
        The trace function traces the object itself (since only it knows its
        size), and traces its children:

            def __flypy_trace__(self, gc):
                obj = gc.trace((int8 *) self, sizeof(self))
                obj.field1 = obj.field1.trace(gc)
                ...
                obj.fieldN = obj.fieldN.trace(gc)
                return obj
        """
        # Copy all live data
        for item in roots.find_roots(top_of_stack):
            obj = head(item)
            trace = head(tail(item))
            trace(obj)

        # Swap spaces and adjust heap if necessary
        self.fromspace, self.tospace = self.tospace, self.fromspace
        if self.resize_heap(size):
            self.init_forwarding_table()
        else:
            self.forwarding_table.clear()
コード例 #2
0
def add(a, b):
    arrays = broadcast(a, b)
    a = head(arrays)
    b = head(tail(arrays))
    out = np.empty_like(a, unify(a.dtype, b.dtype))
    _add(a, b, out)
    return out
コード例 #3
0
def slice_dim(dim, p, indices, dtype):
    # TODO: wraparound
    s = head(indices)

    data = p
    extent = dim.extent
    stride = dim.stride

    t = normalize(s, extent)
    start = t[0]
    stop = t[1]
    step = t[2]  # TODO: tuple unpacking
    extent = len(xrange(start, stop, step))

    # Process start
    if s.start is not None:
        data += start * stride

    # Process step
    if s.step is not None:
        stride *= step

    array = dim.base.index(data, tail(indices), dtype)
    # TODO: Without 'step', ContigDim should remain a ContigDim
    dims = Dimension(array.dims, extent, stride)
    return NDArray(array.data, dims, dtype)
コード例 #4
0
ファイル: vectorize.py プロジェクト: pausz/flypy
def add(a, b):
    arrays = broadcast(a, b)
    a = head(arrays)
    b = head(tail(arrays))
    out = np.empty_like(a, unify(a.dtype, b.dtype))
    _add(a, b, out)
    return out
コード例 #5
0
ファイル: semispace.py プロジェクト: pombreda/flypy
    def collect(self, size, top_of_stack):
        """
        Collect garbage by copying all live data to tospace, starting with
        `roots`. If there is no or little garbage and we're running out of heap
        space, grow the heap. `size` indicates the size of the requested memory.

        This method may raise MemoryError.

        For every root, we determine the trace function and call it on the root.
        The trace function traces the object itself (since only it knows its
        size), and traces its children:

            def __flypy_trace__(self, gc):
                obj = gc.trace((int8 *) self, sizeof(self))
                obj.field1 = obj.field1.trace(gc)
                ...
                obj.fieldN = obj.fieldN.trace(gc)
                return obj
        """
        # Copy all live data
        for item in roots.find_roots(top_of_stack):
            obj = head(item)
            trace = head(tail(item))
            trace(obj)

        # Swap spaces and adjust heap if necessary
        self.fromspace, self.tospace = self.tospace, self.fromspace
        if self.resize_heap(size):
            self.init_forwarding_table()
        else:
            self.forwarding_table.clear()
コード例 #6
0
ファイル: ndarrayobject.py プロジェクト: filmackay/flypy
def slice_dim(dim, p, indices, dtype):
    # TODO: wraparound
    s = head(indices)

    data = p
    extent = dim.extent
    stride = dim.stride

    t = normalize(s, extent)
    start = t[0] ; stop = t[1] ; step = t[2] # TODO: tuple unpacking
    extent = len(range(start, stop, step))

    # Process start
    if s.start is not None:
        data += start * stride

    # Process step
    if s.step is not None:
        stride *= step

    array = dim.base.index(data, tail(indices), dtype)
    # TODO: Without 'step', ContigDim should remain a ContigDim
    dims = Dimension(array.dims, extent, stride)
    return NDArray(array.data, dims, dtype)
コード例 #7
0
ファイル: nplib.py プロジェクト: filmackay/flypy
def c_layout_from_shape(shape, dtype):
    """Construct dimensions for an array of shape `shape` with a C layout"""
    dim = c_layout_from_shape(tail(shape), dtype)
    extent = head(shape)
    stride = dim.stride * dim.extent
    return Dimension(dim, extent, stride)
コード例 #8
0
 def index(self, p, indices, dtype):
     idx = head(indices)
     #if idx < 0 or idx > self.extent:
     #    print("Index out of bounds!")
     #    return self.base.index(p, tail(indices))
     return self.base.index(p + idx * self.stride, tail(indices), dtype)
コード例 #9
0
ファイル: ndarrayobject.py プロジェクト: filmackay/flypy
 def index(self, p, indices, dtype):
     idx = head(indices)
     #if idx < 0 or idx > self.extent:
     #    print("Index out of bounds!")
     #    return self.base.index(p, tail(indices))
     return self.base.index(p + idx * self.stride, tail(indices), dtype)
コード例 #10
0
ファイル: nplib.py プロジェクト: pombreda/flypy
def c_layout_from_shape(shape, dtype):
    """Construct dimensions for an array of shape `shape` with a C layout"""
    dim = c_layout_from_shape(tail(shape), dtype)
    extent = head(shape)
    stride = dim.stride * dim.extent
    return Dimension(dim, extent, stride)