Re: [myhdl-list] Clump'n and Lump'n
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2011-09-12 05:06:41
|
> > Yes, I agree! Using the numerical packages in Python is much easier. > To your point I can open a Python shell and do the following: > >> from numpy import * > >> X = random.rand(3,3) > >> matrix(X) * matrix(X[1,:]).transpose() > >> > matrix([[ 0.53398746], > [ 0.96773496], > [ 1.01327792]]) > > #... expand to myhdl ... > >> sX = Signal(matrix(X)) > >> sY = Signal(matrix(X[1,:].transpose()) > >> sX.next = sX * sY > #... > Doh, awhile ago I posted the above incorrect example. I had done something similar to the above in the past and forgot I added a small wrapper to work with numpy arrays. The above does not function out of the box, when the update function is called it will fail when trying to determine if the current != next for numpy arrays. Below is the wrapper I used. #------------------------------------------------------------------------------- # BlockSignal : #------------------------------------------------------------------------------- class BlockSignal(SignalType): __slots__ = ("parent",) + SignalType.__slots__ def __init__(self, val=None): # @todo check type, always should be an ndarray type! self.parent = None # Call the myhdl.Signal constructor SignalType.__init__(self, val) # For the DSP simulations / executions going to make a copy # of the numpy.ndarray. The update functions will just swap # buffers instead of copying (copy was actually done in the next # assign). self._next = copy(self._val) def _update(self): # @todo check no waiters (self._eventWaiters) should be # no waiters on these signals. Too expensive to check # the arrays for value changes. waiters = self._eventWaiters[:] # Swap the buffers (numpy.ndarray) so that the consumers have # the latest samples and the producers have a new buffer to # fill. tmp = self._val self._val = self._next self._next = self._val return [] def _update_type(self, val): self._val = val self._next = copy(self._val) Regards, Chris Felton |