예제 #1
0
def _jinput(arg): # strip for java input
    if type(arg) is _types.DictType:
        d = dict()
        for k,v in arg.items():
            d[_jinput(k)] = _jinput(v)
        return d
    elif type(arg) is _types.ListType:
        return [ _jinput(a) for a in arg ]
    elif type(arg) is _types.TupleType:
        return tuple([ _jinput(a) for a in arg ])
    elif isinstance(arg, _jlist):
        return [ _jinput(a) for a in arg ]
    elif type(arg) is _arraytype:
        return [ _jinput(a) for a in arg if a is not None]
    elif isinstance(arg, ndarray):
        return arg._jdataset()
    elif isinstance(arg, complex):
        return _jcomplex(arg.real, arg.imag)

    return arg
예제 #2
0
def asDataset(data, dtype=None, force=False):
    '''
    Used for arithmetic ops to coerce a sequence to a dataset otherwise leave as single item
    '''
    if isinstance(data, ndarray):
        if dtype is None or dtype == data.dtype:
            return data
        return ndarray(buffer=data, dtype=dtype, copy=False)

    if isinstance(data, _ds):
        return ndarray(buffer=data, dtype=dtype, copy=False)

    try:
        iter(data)
    except:
        if not force:
            if isinstance(data, complex):
                return _jcomplex(data.real, data.imag)
            return data

    return ndarray(buffer=data, dtype=dtype, copy=False)
예제 #3
0
def asDataset(data, dtype=None, force=False):
    """
    Used for arithmetic ops to coerce a sequence to a dataset otherwise leave as single item
    """
#    if isinstance(data, _dataset):
#        return Sciwrap(_dataset.convertToDoubleDataset())
    if isinstance(data, ndarray):
        return data

    if isinstance(data, _abstractds):
        return ndarray(buffer=data, dtype=dtype, copy=False)

    try:
        iter(data)
    except:
        if not force:
            if isinstance(data, complex):
                return _jcomplex(data.real, data.imag)
            return data

    return ndarray(buffer=data, dtype=dtype, copy=False)
예제 #4
0
def asDataset(data, dtype=None, force=False):
    '''
    Used for arithmetic ops to coerce a sequence to a dataset otherwise leave as single item
    '''
    if isinstance(data, ndarray):
        if dtype is None or dtype == data.dtype:
            return data
        return ndarray(buffer=data, dtype=dtype, copy=False)

    if isinstance(data, _ds):
        return ndarray(buffer=data, dtype=dtype, copy=False)

    try:
        iter(data)
    except:
        if not force:
            if isinstance(data, complex):
                return _jcomplex(data.real, data.imag)
            return data

    return ndarray(buffer=data, dtype=dtype, copy=False)
예제 #5
0
def __cvt_jobj(obj, dtype=None, copy=True, force=False):
    '''Convert object to java object'''
    if isinstance(obj, ndarray):
        obj = obj._jdataset()

    if isinstance(obj, _ds):
        if copy:
            if dtype is None or _translatenativetype(dtype).value == obj.dtype:
                return obj.clone()
            else:
                return obj.cast(_translatenativetype(dtype).value)
        else:
            if dtype is None:
                return obj
            return obj.cast(_translatenativetype(dtype).value)

    if not isinstance(obj, list):
        if isinstance(obj, _matrix): # cope with JAMA matrices
            if dtype is None:
                dtype = float64
            obj = obj.getArray()
    elif len(obj) == 0 and dtype is None:
        dtype = float64

    obj = _cvt2j(obj)
    try:
        iter(obj)
    except:
        if not force:
            if isinstance(obj, complex):
                return _jcomplex(obj.real, obj.imag)
            return obj

    if dtype is None:
        dtype = _getdtypefromobj(obj)
    else:
        dtype = _translatenativetype(dtype)

    return _df.createFromObject(obj, dtype.value)
예제 #6
0
def __cvt_jobj(obj, dtype=None, copy=True, force=False):
    '''Convert object to java object'''
    if isinstance(obj, ndarray):
        obj = obj._jdataset()

    dtype = _translatenativetype(dtype)
    if isinstance(obj, _ds):
        if copy:
            if dtype is None or dtype.value == obj.getDType():
                return obj.clone()
            else:
                return obj.cast(dtype.value)
        else:
            if dtype is None:
                return obj
            return obj.cast(dtype.value)

    if not isinstance(obj, list):
        if isinstance(obj, _matrix): # cope with JAMA matrices
            if dtype is None:
                dtype = float64
            obj = obj.getArray()
    elif len(obj) == 0 and dtype is None:
        dtype = float64

    obj = _cvt2j(obj)
    try:
        iter(obj)
    except:
        if not force:
            if isinstance(obj, complex):
                return _jcomplex(obj.real, obj.imag)
            return obj

    if dtype is None:
        dtype = _getdtypefromobj(obj)

    return _create(dtype.value, obj)