Skip to content
Snippets Groups Projects
Commit 446933cd authored by Daniel van der Schuur's avatar Daniel van der Schuur
Browse files

-Added generator output limiter (nof_blocks).

parent 9a0b73bb
Branches
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ N_POL = 2 # Number of polarizations ...@@ -42,7 +42,7 @@ N_POL = 2 # Number of polarizations
N_BAND = 16 # Number of bands N_BAND = 16 # Number of bands
# Serial (time) dimensions # Serial (time) dimensions
N_INT_X = 800000 # Number of time samples per corrrelator intergration period N_INT_X = 800000 # Number of time samples per corrrelator intergration period
N_SLOT = 1024 #FIXME we need global indices here, don't we? N_SLOT = 1024 # Number of beamlet slots on single BF FN
W_BEAMLET = 6 # Complex beamlet data width W_BEAMLET = 6 # Complex beamlet data width
nof_intervals = 0 # Unlimited runtime nof_intervals = 0 # Unlimited runtime
...@@ -57,25 +57,18 @@ data_width = N_POL*W_BEAMLET ...@@ -57,25 +57,18 @@ data_width = N_POL*W_BEAMLET
parallel_definition = (('dish', N_DISH), ('polarization', N_POL), ('band', N_BAND)) parallel_definition = (('dish', N_DISH), ('polarization', N_POL), ('band', N_BAND))
serial_definition = (('interval', nof_intervals, T_INT_X),('timesample', N_INT_X), ('slot', N_SLOT)) serial_definition = (('interval', nof_intervals, T_INT_X),('timesample', N_INT_X), ('slot', N_SLOT))
CB444 = StreamArray(parallel_definition, serial_definition, data_width, block_size=1024) CB444 = StreamArray(parallel_definition, serial_definition, data_width, block_size=1024, nof_blocks=1)
# Print dish 0, pol 0, band (front node) 0: # Print dish 0, pol 0, band (front node) 0:
for i in CB444[0][0][0]: for i in CB444[0][0][0]:
print i['dish'] print i['slot']
break
for i in CB444[0][0][1]:
print i['dish']
break
############################################################################### ###############################################################################
# Equation 2: transpose the band and dish (physical) dimensions of CB444: flip dimensions 0 and 2 # Equation 2: transpose the band and dish (physical) dimensions of CB444: flip dimensions 0 and 2
############################################################################### ###############################################################################
CB444_T = CB444.transpose((2,1,0)) #NOTE transpose works. How to print this nicely? CB444_T = CB444.transpose((2,1,0))
for i in CB444_T[0][0][0]: for i in CB444_T[0][0][0]:
print i['dish'] print i['dish']
break
for i in CB444_T[0][0][1]:
print i['dish']
break
...@@ -7,7 +7,7 @@ class Stream: ...@@ -7,7 +7,7 @@ class Stream:
""" """
Single serial stream generator Single serial stream generator
""" """
def __init__(self, parallel_definition, serial_definition, data_width, block_size): def __init__(self, parallel_definition, serial_definition, data_width, block_size, nof_blocks):
# Parallel definition: physical stream tags and indices for this serial stream # Parallel definition: physical stream tags and indices for this serial stream
self.parallel_definition = parallel_definition self.parallel_definition = parallel_definition
...@@ -34,11 +34,18 @@ class Stream: ...@@ -34,11 +34,18 @@ class Stream:
self.serial_data_out.append(dimension-1) self.serial_data_out.append(dimension-1)
# Create an interval out counter. Initialize to -1 as there is no maximum # Create an interval out counter. Initialize to -1 as there is no maximum
self.interval_out = -1 self.interval_out = -1
self.block_size = block_size self.block_size = block_size
self.last_block_lo = 0 self.nof_blocks = nof_blocks
self.last_block_hi = block_size self.out_count = 0
def next(self): def next(self):
# Break out of the generator loop when we've output nof_blocks
if self.nof_blocks>0 and self.out_count==self.nof_blocks:
self.out_count = 0
raise StopIteration
else:
self.out_count+=1
block = [] block = []
for i in range(self.block_size): for i in range(self.block_size):
# Start with the fastest changing dimension (index -1). When we have e.g. 2 dimensions, don't go beyond index -2. # Start with the fastest changing dimension (index -1). When we have e.g. 2 dimensions, don't go beyond index -2.
...@@ -67,12 +74,10 @@ class Stream: ...@@ -67,12 +74,10 @@ class Stream:
class StreamArray(np.ndarray): class StreamArray(np.ndarray):
""" """
NOTE: Use get() functions instead of fixed attributes as indexing a subset of StreamArray should yield e.g. User can limit the generated output using nof_intervals (highest dimension = still large amount of output)
a different data rate than the full array. or nof_blocks (lowest dimension = small amount of output). 0=unlimited.
NOTE: An ESSENTIAL property of subclassing numpy array is that method return values *DEPEND ON THE INDEXED SUBSTREAMS*!
. e.g. pass substream to Component without the difficulties of component_class.py!
""" """
def __new__(cls, parallel_definition, serial_definition, data_width, block_size): def __new__(cls, parallel_definition, serial_definition, data_width, block_size, nof_blocks):
# We need the parallel dimensions here, but we'll pass the parallel tags to the serial Stream instances. # We need the parallel dimensions here, but we'll pass the parallel tags to the serial Stream instances.
parallel_tags = [pair[0] for pair in parallel_definition] parallel_tags = [pair[0] for pair in parallel_definition]
parallel_dimensions = [pair[1] for pair in parallel_definition] parallel_dimensions = [pair[1] for pair in parallel_definition]
...@@ -84,7 +89,7 @@ class StreamArray(np.ndarray): ...@@ -84,7 +89,7 @@ class StreamArray(np.ndarray):
for index in np.ndindex(tuple(parallel_dimensions)): for index in np.ndindex(tuple(parallel_dimensions)):
parallel_definition = zip(parallel_tags, index) parallel_definition = zip(parallel_tags, index)
# Replace the dimension size in the parallel_definition with the actual stream index # Replace the dimension size in the parallel_definition with the actual stream index
streams.append(Stream(parallel_definition, serial_definition, data_width, block_size)) streams.append(Stream(parallel_definition, serial_definition, data_width, block_size, nof_blocks))
input_array = np.array(streams) input_array = np.array(streams)
input_array.resize(parallel_dimensions) input_array.resize(parallel_dimensions)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment