Beispiel #1
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)
Beispiel #2
0
    def __setitem__(self, key, value):
        value = fromDS(value)
        if isinstance(value, ndarray):
            value = value._jdataset()
        else:
            value = _cvt2j(value)

        isslice, key = _toslice(self.ndim, key)

        try:
            if not isslice:
                if isinstance(key, _booleands):
                    return self.__dataset.setByBoolean(value, key)
                if isinstance(key, _integerds):
                    return self.__dataset.setBy1DIndex(value, key)
                if _contains_ints_bools_newaxis(key):
                    return self.__dataset.setByIndexes(value, key)
                return self.__dataset.set(value, key)
    
            _setslice(self.__dataset, value, key)
            return self
        except _jarrayindex_exception:
            raise IndexError
Beispiel #3
0
 def fill(self, value):
     self.__dataset.fill(_cvt2j(value))
     return self