Changeset 70bb1cc8f9a8886fea37e017478f3a85c0b6e233 for pyflu/pyflu/fifo.py
- Timestamp:
- 04/30/10 02:53:15 (2 years ago)
- Children:
- acf43d008d077e46c8915fc1a184b56ffea0dac1
- Parents:
- 8d7196fb48bcec3bf822911c6aaff79b2b90cda4
- git-committer:
- Luper Rouch <luper.rouch@…> (04/30/10 02:53:15)
- File:
-
- 1 edited
-
pyflu/pyflu/fifo.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyflu/pyflu/fifo.py
r125db56 r70bb1cc 7 7 """ 8 8 9 def __init__(self, size, dimensions=1, dtype=np.float32, filled=False): 10 self._cache = np.zeros(size * dimensions, dtype) 11 self._values = np.zeros(size * dimensions, dtype) 12 self._size = size 13 self._dimensions = dimensions 14 self._array_size = size * dimensions 9 def __init__(self, shape, dtype=np.float32, filled=False): 10 self._cache = np.zeros(shape, dtype) 11 self._values = np.zeros(shape, dtype) 12 self.shape = shape 15 13 if filled: 16 self._ind = self. _array_size14 self._ind = self.shape[0] 17 15 else: 18 16 self._ind = 0 19 17 self._cached = False 20 18 21 def add(self, *args):19 def add(self, value): 22 20 """ 23 Add a v ector to the queue.21 Add a value to the buffer. 24 22 """ 25 ind = self._ind % self. _array_size26 self._values[ind :ind + self._dimensions] = args27 self._ind += self._dimensions23 ind = self._ind % self.shape[0] 24 self._values[ind] = value 25 self._ind += 1 28 26 self._cached = False 29 27 … … 32 30 Returns a numpy array containing the last stored values. 33 31 """ 34 if self._ind < self. _array_size:32 if self._ind < self.shape[0]: 35 33 return self._values[:self._ind] 36 34 if not self._cached: 37 ind = self._ind % self. _array_size38 self._cache[:self. _array_size- ind] = self._values[ind:]39 self._cache[self. _array_size- ind:] = self._values[:ind]35 ind = self._ind % self.shape[0] 36 self._cache[:self.shape[0] - ind] = self._values[ind:] 37 self._cache[self.shape[0] - ind:] = self._values[:ind] 40 38 self._cached = True 41 39 return self._cache 42 40 43 41 def __len__(self): 44 if self._ind < self._array_size: 45 return self._ind / self._dimensions 46 return self._size 42 return min(self._ind, self.shape[0])
Note: See TracChangeset
for help on using the changeset viewer.
