Ejemplo n.º 1
0
    def __getitem__(self, item):
        """
        Support array type creation by slicing, e.g. double[:, :] specifies
        a 2D strided array of doubles. The syntax is the same as for
        Cython memoryviews.
        """
        assert isinstance(item, (tuple, slice))

        def verify_slice(s):
            if s.start or s.stop or s.step not in (None, 1):
                raise minierror.InvalidTypeSpecification(
                    "Only a step of 1 may be provided to indicate C or "
                    "Fortran contiguity")

        if isinstance(item, tuple):
            step_idx = None
            for idx, s in enumerate(item):
                verify_slice(s)
                if s.step and (step_idx or idx not in (0, len(item) - 1)):
                    raise minierror.InvalidTypeSpecification(
                        "Step may only be provided once, and only in the "
                        "first or last dimension.")

                if s.step == 1:
                    step_idx = idx

            return ArrayType(self,
                             len(item),
                             is_c_contig=step_idx == len(item) - 1,
                             is_f_contig=step_idx == 0)
        else:
            verify_slice(item)
            return ArrayType(self, 1, is_c_contig=bool(item.step))
Ejemplo n.º 2
0
    def __init__(self,
                 fields=None,
                 name=None,
                 readonly=False,
                 packed=False,
                 **kwargs):
        super(struct, self).__init__()
        if fields and kwargs:
            raise minierror.InvalidTypeSpecification(
                "The struct must be either ordered or unordered")

        if kwargs:
            fields = sort_types(kwargs)

        self.fields = fields
        self.rank = sum(_sort_key(field) for field in fields)
        self.name = name
        self.readonly = readonly
        self.fielddict = dict(fields)
        self.packed = packed
Ejemplo n.º 3
0
 def verify_slice(s):
     if s.start or s.stop or s.step not in (None, 1):
         raise minierror.InvalidTypeSpecification(
             "Only a step of 1 may be provided to indicate C or "
             "Fortran contiguity")