Ejemplo n.º 1
0
def marked_pgxtype_to_ndpointer(ns, name, pgxtype, attrs):
    if 'arr' not in attrs or attrs.pop('arr') != 'true':
        raise NotApplicable
    try:
        ctype = pgxtype_to_ctype(ns, name, pgxtype, attrs)
    except NotApplicable:
        raise CTypeException("Cannot create ndpointer class for type '{0}'."
                             .format(pgxtype.decl_string))
    if not isinstance(ctype, type(ctypes._Pointer)) or ctype._type_ not in invtypemap:
        raise CTypeException("Cannot create ndpointer class for type '{0}'."
                             .format(pgxtype.decl_string))
    flags = ["C"]
    dtype = get_ntype(ctype._type_)
    nullable = attrs.pop('nullable', '0')
    if nullable in ['false', '0']:
        nullable = False
    else:
        nullable = True
    ndim = attrs.pop('ndim', None)
    shape = attrs.pop('shape', None)
    if shape:
        dims = shape.split('x')
        if ndim is not None and ndim != len(dims):
            raise ValueError("Conflict on type '{2}': ndpointer cannot have ndim={0} and shape={1}".format(ndim, shape, pgxtype.decl_string))
        ndim = len(dims)
        try:
            dims = map(int, dims)
            shape = tuple(dims)
        except ValueError:
            shape = None
            # self.shape_constraints[name] = dims
    if attrs:
        raise AttributeError("Unrecognized GCCXML attributes on arg '{0} {1}': ".format(pgxtype.decl_string, name)+' '.join(attrs.keys()))
    return ndpointer(dtype=dtype, flags=flags, allow_null=nullable, shape=shape, ndim=ndim)
Ejemplo n.º 2
0
def pgxtype_to_ndpointer(ns, name, pgxtype, attrs):
    t = pgxtype_to_ctype(ns, name, pgxtype, attrs)
    if isinstance(t, type(ctypes.POINTER(ctypes.c_int))):
        if t._type_ in invtypemap:
            return ndpointer(dtype=get_ntype(t._type_),
                             allow_null=True,
                             flags=['C'])
    raise NotApplicable
Ejemplo n.º 3
0
def marked_pgxtype_to_ndpointer(ns, name, pgxtype, attrs):
    if 'arr' not in attrs or attrs.pop('arr') != 'true':
        raise NotApplicable
    try:
        ctype = pgxtype_to_ctype(ns, name, pgxtype, attrs)
    except NotApplicable:
        raise CTypeException(
            "Cannot create ndpointer class for type '{0}'.".format(
                pgxtype.decl_string))
    if not isinstance(ctype, type(
            ctypes._Pointer)) or ctype._type_ not in invtypemap:
        raise CTypeException(
            "Cannot create ndpointer class for type '{0}'.".format(
                pgxtype.decl_string))
    flags = ["C"]
    dtype = get_ntype(ctype._type_)
    nullable = attrs.pop('nullable', '0')
    if nullable in ['false', '0']:
        nullable = False
    else:
        nullable = True
    ndim = attrs.pop('ndim', None)
    shape = attrs.pop('shape', None)
    if shape:
        dims = shape.split('x')
        if ndim is not None and ndim != len(dims):
            raise ValueError(
                "Conflict on type '{2}': ndpointer cannot have ndim={0} and shape={1}"
                .format(ndim, shape, pgxtype.decl_string))
        ndim = len(dims)
        try:
            dims = map(int, dims)
            shape = tuple(dims)
        except ValueError:
            shape = None
            # self.shape_constraints[name] = dims
    if attrs:
        raise AttributeError(
            "Unrecognized GCCXML attributes on arg '{0} {1}': ".format(
                pgxtype.decl_string, name) + ' '.join(attrs.keys()))
    return ndpointer(dtype=dtype,
                     flags=flags,
                     allow_null=nullable,
                     shape=shape,
                     ndim=ndim)
Ejemplo n.º 4
0
def pgxtype_to_ndpointer(ns, name, pgxtype, attrs):
    t = pgxtype_to_ctype(ns, name, pgxtype, attrs)
    if isinstance(t, type(ctypes.POINTER(ctypes.c_int))):
        if t._type_ in invtypemap:
            return ndpointer(dtype=get_ntype(t._type_), allow_null=True, flags=['C'])
    raise NotApplicable