MCPcopy Create free account
hub / github.com/NVIDIA/DALI / ExternalInputIterator

Class ExternalInputIterator

dali/test/python/operator_1/test_arithmetic_ops.py:349–409  ·  view source on GitHub ↗

Generates inputs of required shapes and types The number of inputs is based on the length of tuple `types`, if types is a single element it is considered we should generate 1 output. If the kind contains 'scalar', than the result is batch of scalar tensors. the "shape" of `kinds

Source from the content-addressed store, hash-verified

347
348
349class ExternalInputIterator(object):
350 """
351 Generates inputs of required shapes and types
352 The number of inputs is based on the length of tuple `types`, if types is a single element
353 it is considered we should generate 1 output.
354 If the kind contains 'scalar', than the result is batch of scalar tensors.
355 the "shape" of `kinds` arguments should match the `types` argument - single elements or tuples
356 of the same arity.
357 """
358
359 def __init__(
360 self, batch_size, shape_gen, types, kinds, disallow_zeros=None, limited_range=None
361 ):
362 try:
363 self.length = len(types)
364 except TypeError:
365 types = (types,)
366 kinds = (kinds,)
367 self.length = 1
368 if not disallow_zeros:
369 disallow_zeros = (False,) * self.length
370 if limited_range is None:
371 limited_range = (None,) * self.length
372 self.batch_size = batch_size
373 self.types = types
374 self.gens = []
375 self.shapes = []
376 for i in range(self.length):
377 self.gens += [self.get_generator(self.types[i], disallow_zeros[i], limited_range[i])]
378 if "scalar" not in kinds[i]:
379 self.shapes += [shape_gen(i)]
380 elif "scalar_legacy" in kinds[i]:
381 self.shapes += [[(1,)] * batch_size]
382 else:
383 self.shapes += [[]] # empty shape, special 0D scalar
384
385 def __iter__(self):
386 return self
387
388 def __next__(self):
389 out = ()
390 for i in range(self.length):
391 batch = []
392 # Handle 0D scalars
393 if self.shapes[i] == []:
394 batch = self.gens[i](self.batch_size)
395 else:
396 for sample in range(self.batch_size):
397 batch.append(self.gens[i](self.shapes[i][sample]))
398 out = out + (batch,)
399 return out
400
401 def get_generator(self, type, no_zeros, limited_range):
402 if type == np.bool_:
403 return lambda shape: bool_generator(shape, no_zeros)
404 elif type in [np.float16, np.float32, np.float64]:
405 return lambda shape: float_generator(shape, type, no_zeros, limited_range)
406 else:

Callers 9

check_unary_opFunction · 0.70
check_math_function_opFunction · 0.70
check_arithm_opFunction · 0.70
check_ternary_opFunction · 0.70
check_comparsion_opFunction · 0.70
check_arithm_divFunction · 0.70
check_arithm_modFunction · 0.70
check_raisesFunction · 0.70

Calls

no outgoing calls

Tested by 9

check_unary_opFunction · 0.56
check_math_function_opFunction · 0.56
check_arithm_opFunction · 0.56
check_ternary_opFunction · 0.56
check_comparsion_opFunction · 0.56
check_arithm_divFunction · 0.56
check_arithm_modFunction · 0.56
check_raisesFunction · 0.56