Ignore:
Timestamp:
04/30/10 02:53:15 (2 years ago)
Author:
Luper Rouch <luper.rouch@…>
Children:
acf43d008d077e46c8915fc1a184b56ffea0dac1
Parents:
8d7196fb48bcec3bf822911c6aaff79b2b90cda4
git-committer:
Luper Rouch <luper.rouch@…> (04/30/10 02:53:15)
Message:

pyflu:

  • refactored fifo.FifoBuffer?, now working more like numpy arrays
  • jsonalize:
    • added load() and save() methods to JSONAlizable
    • alternate constructor can be specified in register()
  • qt:
    • TreeModel? now uses JSON to serialize python objects in drag and drop operations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyflu/pyflu/fifo.py

    r125db56 r70bb1cc  
    77    """ 
    88 
    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 
    1513        if filled: 
    16             self._ind = self._array_size 
     14            self._ind = self.shape[0] 
    1715        else: 
    1816            self._ind = 0 
    1917        self._cached = False 
    2018 
    21     def add(self, *args): 
     19    def add(self, value): 
    2220        """ 
    23         Add a vector to the queue. 
     21        Add a value to the buffer. 
    2422        """ 
    25         ind = self._ind % self._array_size 
    26         self._values[ind:ind + self._dimensions] = args 
    27         self._ind += self._dimensions 
     23        ind = self._ind % self.shape[0] 
     24        self._values[ind] = value 
     25        self._ind += 1 
    2826        self._cached = False 
    2927 
     
    3230        Returns a numpy array containing the last stored values. 
    3331        """ 
    34         if self._ind < self._array_size: 
     32        if self._ind < self.shape[0]: 
    3533            return self._values[:self._ind] 
    3634        if not self._cached: 
    37             ind = self._ind % self._array_size 
    38             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] 
    4038            self._cached = True 
    4139        return self._cache 
    4240 
    4341    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.