Reader that produces increasing integers.
| 295 | |
| 296 | |
| 297 | class CounterReader(Reader): |
| 298 | """ Reader that produces increasing integers. """ |
| 299 | def __init__(self): |
| 300 | Reader.__init__(self, schema=Struct(('iter', np.int64))) |
| 301 | self.counter = None |
| 302 | self.should_stop = None |
| 303 | |
| 304 | def setup_ex(self, global_init_net, global_finish_net): |
| 305 | if self.counter is None: |
| 306 | self.counter = global_init_net.CreateCounter([], init_count=0) |
| 307 | self.should_stop = global_init_net.ConstantFill( |
| 308 | [], shape=[], dtype=core.DataType.BOOL, value=False) |
| 309 | |
| 310 | def read_ex(self, local_init_net, local_finish_net): |
| 311 | count_net = core.Net('limited_reader_counter') |
| 312 | value = count_net.CountUp([self.counter], 1) |
| 313 | return [count_net], self.should_stop, [value] |
| 314 | |
| 315 | |
| 316 | class ReaderWithLimitBase(Reader): |
no outgoing calls
no test coverage detected
searching dependent graphs…