예제 #1
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def method_reshape(self, s_tuple):
     if not isinstance(s_tuple, SomeTuple):
         raise AnnotatorError("reshape expects tuple arg")
     for s_item in s_tuple.items:
         if not isinstance(s_item, SomeInteger):
             raise AnnotatorError("bad shape arg")
     ndim = len(s_tuple.items)
     return SomeArray(self.typecode, ndim)
예제 #2
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def getitem((s_array, s_index)):
     ndim = pair(s_array, s_index).get_leftover_dim()
     if len(s_index.items) > s_array.ndim:
         raise AnnotatorError("invalid index")
     if s_array.ndim == 0 and len(s_index.items):
         raise AnnotatorError(
             "indexing rank zero array with nonempty tuple")
     if ndim > 0:
         return SomeArray(s_array.typecode, ndim)
     return s_array.get_item_type()
예제 #3
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def inplace_add((s_arr, s_other)):
     if isinstance(s_other, SomeArray):
         # This can only work if s_other is broadcastable to s_arr
         if s_other.ndim > s_arr.ndim:
             raise AnnotatorError("invalid return array shape")
     elif isinstance(s_other, SomeList):
         item2 = s_other.listdef.listitem.s_value
         if not isinstance(item2, SomeFloat):
             raise AnnotatorError("cannot operate with list of %s" % item2)
     elif not isinstance(s_other, SomeFloat):
         raise AnnotatorError("cannot operate with %s" % s_other)
     return s_arr
예제 #4
0
파일: aarray.py 프로젝트: xx312022850/pypy
    def compute_result_annotation(self, s_arg, s_dtype=None):
        if isinstance(s_arg, SomeTuple):
            s_tuple = s_arg
            for s_item in s_tuple.items:
                if not isinstance(s_item, SomeInteger):
                    raise AnnotatorError("shape arg not understood")
            ndim = len(s_tuple.items)
        elif isinstance(s_arg, SomeInteger):
            ndim = 1
        else:
            raise AnnotatorError("shape arg not understood: %s" % s_arg)

        typecode = 'd'
        if isinstance(s_dtype, SomeChar) and s_dtype.is_constant():
            typecode = s_dtype.const
            s_dtype = None
        return SomeArray(typecode, ndim)
예제 #5
0
class __extend__(pairtype(SomePBC, SomeObject)):
    def getitem((pbc, o)):
        if not pbc.isNone():
            raise AnnotatorError("getitem on %r" % pbc)
        return s_ImpossibleValue

    def setitem((pbc, o), s_value):
        if not pbc.isNone():
            raise AnnotatorError("setitem on %r" % pbc)
예제 #6
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def get_leftover_dim((s_array, s_index)):
     ndim = s_array.ndim
     for s_item in s_index.items:
         if isinstance(s_item, SomeInteger):
             ndim -= 1
         elif isinstance(s_item, SomeSlice):
             pass
         else:
             raise AnnotatorError("cannot index with %s" % s_item)
     return ndim
예제 #7
0
파일: aarray.py 프로젝트: xx312022850/pypy
class __extend__(pairtype(SomeArray, SomeTuple)):
    def get_leftover_dim((s_array, s_index)):
        ndim = s_array.ndim
        for s_item in s_index.items:
            if isinstance(s_item, SomeInteger):
                ndim -= 1
            elif isinstance(s_item, SomeSlice):
                pass
            else:
                raise AnnotatorError("cannot index with %s" % s_item)
        return ndim

    def setitem((s_array, s_index), s_value):
        ndim = pair(s_array, s_index).get_leftover_dim()
        if len(s_index.items) > s_array.ndim:
            raise AnnotatorError("invalid index")
        if isinstance(s_value, SomeArray):
            if s_value.ndim > ndim:
                raise AnnotatorError("shape mismatch")
예제 #8
0
파일: aarray.py 프로젝트: xx312022850/pypy
def unify_scalar_tp(item1, item2):
    typecode = None
    if float in (item1.knowntype, item2.knowntype):
        typecode = 'd'
    else:
        item_knowntype = rarithmetic.compute_restype(item1.knowntype,
                                                     item2.knowntype)
        for typecode, s_item in SomeArray.typecode_to_item.items():
            if s_item.knowntype == item_knowntype:
                break
    if typecode is None:
        raise AnnotatorError()
    return typecode
예제 #9
0
파일: aarray.py 프로젝트: xx312022850/pypy
    def compute_result_annotation(self, s_list, s_dtype=None):
        if isinstance(s_list, SomeList):
            # First guess type from input list
            listitem = s_list.listdef.listitem
            key = type(listitem.s_value), listitem.s_value.knowntype
            typecode = numpy_typedict.get(key, None)
            ndim = 1
        elif isinstance(s_list, SomeArray):
            typecode = s_list.typecode
            ndim = s_list.ndim
        else:
            raise AnnotatorError("cannot build array from %s" % s_list)

        # now see if the dtype arg over-rides the typecode
        if isinstance(s_dtype, SomeChar) and s_dtype.is_constant():
            typecode = s_dtype.const
            s_dtype = None
        if s_dtype is not None:
            raise AnnotatorError("dtype is not a valid type specification")
        if typecode is None or typecode not in valid_typecodes:
            raise AnnotatorError("List item type not supported")

        return SomeArray(typecode, ndim)
예제 #10
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def add((s_arr, s_other)):
     item1 = s_arr.get_item_type()
     ndim = s_arr.ndim
     if isinstance(s_other, SomeArray):
         item2 = s_other.get_item_type()
         ndim = max(ndim, s_other.ndim)
     elif isinstance(s_other, SomeList):
         item2 = s_other.listdef.listitem.s_value
     elif isinstance(s_other, SomeFloat):
         item2 = s_other
     else:
         raise AnnotatorError("cannot operate with %s" % s_other)
     typecode = unify_scalar_tp(item1, item2)
     return SomeArray(typecode, ndim)
예제 #11
0
    def ondegenerated(self, what, s_value, where=None, called_from_graph=None):
        if self.policy.allow_someobjects:
            return
        # is the function itself tagged with allow_someobjects?
        position_key = where or getattr(self.bookkeeper, 'position_key', None)
        if position_key is not None:
            graph, block, i = position_key
            try:
                if graph.func.allow_someobjects:
                    return
            except AttributeError:
                pass

        msgstr = format_someobject_error(self, position_key, what, s_value,
                                         called_from_graph,
                                         self.bindings.get(what, "(none)"))

        raise AnnotatorError(msgstr)
예제 #12
0
    def complete(self):
        """Process pending blocks until none is left."""
        while True:
            while self.pendingblocks:
                block, graph = self.pendingblocks.popitem()
                if annmodel.DEBUG:
                    self.flowin_block = block  # we need to keep track of block
                self.processblock(graph, block)
            self.policy.no_more_blocks_to_annotate(self)
            if not self.pendingblocks:
                break  # finished
        # make sure that the return variables of all graphs is annotated
        if self.added_blocks is not None:
            newgraphs = [self.annotated[block] for block in self.added_blocks]
            newgraphs = dict.fromkeys(newgraphs)
            got_blocked_blocks = False in newgraphs
        else:
            newgraphs = self.translator.graphs  #all of them
            got_blocked_blocks = False in self.annotated.values()
        if got_blocked_blocks:
            for graph in self.blocked_graphs.values():
                self.blocked_graphs[graph] = True

            blocked_blocks = [
                block for block, done in self.annotated.items()
                if done is False
            ]
            assert len(blocked_blocks) == len(self.blocked_blocks)

            text = format_blocked_annotation_error(self, self.blocked_blocks)
            #raise SystemExit()
            raise AnnotatorError(text)
        for graph in newgraphs:
            v = graph.getreturnvar()
            if v not in self.bindings:
                self.setbinding(v, annmodel.s_ImpossibleValue)
        # policy-dependent computation
        self.bookkeeper.compute_at_fixpoint()
예제 #13
0
 def setattr(pbc, s_attr, s_value):
     if not pbc.isNone():
         raise AnnotatorError("setattr on %r" % pbc)
예제 #14
0
 def add((o, pbc)):
     if not pbc.isNone():
         raise AnnotatorError('add on %r' % pbc)
     return s_ImpossibleValue
예제 #15
0
 def getitem((pbc, o)):
     if not pbc.isNone():
         raise AnnotatorError("getitem on %r" % pbc)
     return s_ImpossibleValue
예제 #16
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def inplace_add((s_flt, s_arr)):
     # This involves promoting the type of the lhs
     raise AnnotatorError()
예제 #17
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def __init__(self, typecode, ndim=1):
     if not typecode in self.typecode_to_item:
         raise AnnotatorError("bad typecode: %r" % typecode)
     self.dtype = self.typecode = typecode
     self.ndim = ndim
예제 #18
0
파일: aarray.py 프로젝트: xx312022850/pypy
 def method_astype(self, s_dtype):
     if isinstance(s_dtype, SomeChar) and s_dtype.is_constant():
         typecode = s_dtype.const
         return SomeArray(typecode, self.ndim)
     raise AnnotatorError()