示例#1
0
    def __setitem__(self, indices, value):
        #print type(indices)
        if isinstance(indices, MIArray):
            if isinstance(value, MIArray):
                value = value.asarray()
            ArrayMath.setValue(self.array, indices.array, value)
            return None

        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds

        if self.ndim == 0:
            self.array.setObject(0, value)
            return None

        if len(indices) != self.ndim:
            print 'indices must be ' + str(self.ndim) + ' dimensions!'
            return None

        ranges = []
        flips = []
        for i in range(0, self.ndim):
            if isinstance(indices[i], int):
                sidx = indices[i]
                if sidx < 0:
                    sidx = self.getshape()[i] + sidx
                eidx = sidx
                step = 1
            else:
                sidx = 0 if indices[i].start is None else indices[i].start
                if sidx < 0:
                    sidx = self.getshape()[i] + sidx
                eidx = self.getshape(
                )[i] - 1 if indices[i].stop is None else indices[i].stop
                if eidx < 0:
                    eidx = self.getshape()[i] + eidx
                step = 1 if indices[i].step is None else indices[i].step
            if step < 0:
                step = abs(step)
                flips.append(i)
            rr = Range(sidx, eidx, step)
            ranges.append(rr)

        if isinstance(value, MIArray):
            value = value.asarray()
        r = ArrayMath.setSection(self.array, ranges, value)
        self.array = r
示例#2
0
    def __setitem__(self, indices, value):
        #print type(indices)
        if isinstance(indices, (MIArray, DimArray)):
            ArrayMath.setValue(self.asarray(), indices.asarray(), value)
            return None

        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds

        if self.rank == 0:
            self.array.array.setObject(0, value)
            return None

        if len(indices) != self.rank:
            print 'indices must be ' + str(self.rank) + ' dimensions!'
            return None

        ranges = []
        flips = []
        for i in range(0, self.rank):
            if isinstance(indices[i], int):
                sidx = indices[i]
                eidx = indices[i]
                step = 1
            else:
                sidx = 0 if indices[i].start is None else indices[i].start
                eidx = self.shape[i] - 1 if indices[
                    i].stop is None else indices[i].stop
                step = 1 if indices[i].step is None else indices[i].step
            if step < 0:
                step = abs(step)
                flips.append(i)
            rr = Range(sidx, eidx, step)
            ranges.append(rr)

        if isinstance(value, (MIArray, DimArray)):
            value = value.asarray()
        r = ArrayMath.setSection(self.array.array, ranges, value)
        self.array.array = r
示例#3
0
    def __setitem__(self, indices, value):
        #print type(indices) 
        if isinstance(indices, (MIArray, DimArray)):
            ArrayMath.setValue(self.asarray(), indices.asarray(), value)
            return None
        
        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds
        
        if self.rank == 0:
            self.array.array.setObject(0, value)
            return None
        
        if len(indices) != self.rank:
            print 'indices must be ' + str(self.rank) + ' dimensions!'
            return None

        ranges = []
        flips = []        
        for i in range(0, self.rank):   
            if isinstance(indices[i], int):
                sidx = indices[i]
                eidx = indices[i]
                step = 1
            else:
                sidx = 0 if indices[i].start is None else indices[i].start
                eidx = self.shape[i]-1 if indices[i].stop is None else indices[i].stop
                step = 1 if indices[i].step is None else indices[i].step
            if step < 0:
                step = abs(step)
                flips.append(i)
            rr = Range(sidx, eidx, step)
            ranges.append(rr)
    
        if isinstance(value, (MIArray, DimArray)):
            value = value.asarray()
        r = ArrayMath.setSection(self.array.array, ranges, value)
        self.array.array = r
示例#4
0
    def __setitem__(self, indices, value):
        #print type(indices)
        if isinstance(indices, MIArray):
            if isinstance(value, MIArray):
                value = value.asarray()
            ArrayMath.setValue(self.array, indices.array, value)
            return None

        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds

        if self.ndim == 0:
            self.array.setObject(0, value)
            return None

        if len(indices) != self.ndim:
            print 'indices must be ' + str(self.ndim) + ' dimensions!'
            return None

        ranges = []
        flips = []
        onlyrange = True
        alllist = True
        for i in range(0, self.ndim):
            k = indices[i]
            if isinstance(k, int):
                sidx = k
                if sidx < 0:
                    sidx = self._shape[i] + sidx
                eidx = sidx
                step = 1
                alllist = False
            elif isinstance(k, (list, tuple, MIArray)):
                if isinstance(k, MIArray):
                    k = k.aslist()
                onlyrange = False
                ranges.append(k)
                continue
            else:
                sidx = 0 if k.start is None else k.start
                if sidx < 0:
                    sidx = self._shape[i] + sidx
                eidx = self._shape[i] if k.stop is None else k.stop
                if eidx < 0:
                    eidx = self._shape[i] + eidx
                eidx -= 1
                step = 1 if k.step is None else k.step
                alllist = False
            if step < 0:
                step = abs(step)
                flips.append(i)
            rr = Range(sidx, eidx, step)
            ranges.append(rr)

        if isinstance(value, (list, tuple)):
            value = ArrayUtil.array(value)
        if isinstance(value, MIArray):
            value = value.asarray()
        if onlyrange:
            r = ArrayMath.setSection(self.array, ranges, value)
        else:
            if alllist:
                r = ArrayMath.setSection_List(self.array, ranges, value)
            else:
                r = ArrayMath.setSection_Mix(self.array, ranges, value)
        self.array = r
示例#5
0
    def __setitem__(self, indices, value):
        #print type(indices) 
        if isinstance(indices, MIArray):
            if isinstance(value, MIArray):
                value = value.asarray()
            ArrayMath.setValue(self.array, indices.array, value)
            return None
        
        if not isinstance(indices, tuple):
            inds = []
            inds.append(indices)
            indices = inds
        
        if self.ndim == 0:
            self.array.setObject(0, value)
            return None
        
        if len(indices) != self.ndim:
            print 'indices must be ' + str(self.ndim) + ' dimensions!'
            raise IndexError()

        ranges = []
        flips = []
        onlyrange = True
        alllist = True
        for i in range(0, self.ndim):   
            k = indices[i]
            if isinstance(k, int):
                sidx = k                
                if sidx < 0:
                    sidx = self._shape[i] + sidx                
                eidx = sidx
                step = 1
                alllist = False
            elif isinstance(k, (list, tuple, MIArray)):
                if isinstance(k, MIArray):
                    k = k.aslist()
                onlyrange = False
                ranges.append(k)
                continue
            else:
                sidx = 0 if k.start is None else k.start
                if sidx < 0:
                    sidx = self._shape[i] + sidx
                eidx = self._shape[i] if k.stop is None else k.stop
                if eidx < 0:
                    eidx = self._shape[i] + eidx
                eidx -= 1
                step = 1 if k.step is None else k.step
                alllist = False
            if step < 0:
                step = abs(step)
                flips.append(i)
            rr = Range(sidx, eidx, step)
            ranges.append(rr)

        if isinstance(value, (list,tuple)):
            value = ArrayUtil.array(value)
        if isinstance(value, MIArray):
            value = value.asarray()
        if onlyrange:
            r = ArrayMath.setSection(self.array, ranges, value)
        else:
            if alllist:
                r = ArrayMath.setSection_List(self.array, ranges, value)
            else:
                r = ArrayMath.setSection_Mix(self.array, ranges, value)
        self.array = r