def test_slicing_tuple_values(self, sequence_type): def _to_value(cbb): return value_impl.to_value(cbb, None, context_stack_impl.context_stack) t = sequence_type(range(0, 50, 10)) comp, _ = transformations.uniquify_compiled_computation_names( value_impl.ValueImpl.get_comp(_to_value(t))) v = _to_value(comp) self.assertEqual((str(v.type_signature)), '<int32,int32,int32,int32,int32>') self.assertEqual(str(v[:]), str(v)) sliced = v[:2] self.assertEqual((str(sliced.type_signature)), '<int32,int32>') self.assertEqual(str(sliced), '<comp#1(),comp#2()>') sliced = v[-3:] self.assertEqual((str(sliced.type_signature)), '<int32,int32,int32>') self.assertEqual(str(sliced), '<comp#3(),comp#4(),comp#5()>') sliced = v[::2] self.assertEqual((str(sliced.type_signature)), '<int32,int32,int32>') self.assertEqual(str(sliced), '<comp#1(),comp#3(),comp#5()>')
def test_get_curried(self): add_numbers = value_impl.ValueImpl( building_blocks.ComputationBuildingBlock.from_proto( computation_impl.ComputationImpl.get_proto( computations.tf_computation(tf.add, [tf.int32, tf.int32]))), _context_stack) curried = value_utils.get_curried(add_numbers) self.assertEqual(str(curried.type_signature), '(int32 -> (int32 -> int32))') comp, _ = transformations.uniquify_compiled_computation_names( value_impl.ValueImpl.get_comp(curried)) self.assertEqual(comp.compact_representation(), '(arg0 -> (arg1 -> comp#1(<arg0,arg1>)))')
def _compile(self, comp): """Compiles a `computation_base.Computation` to prepare it for execution. Args: comp: An instance of `computation_base.Computation`. Returns: An instance of `building_blocks.ComputationBuildingBlock` that contains the compiled logic of `comp`. """ py_typecheck.check_type(comp, computation_base.Computation) if self._compiler is not None: comp = self._compiler.compile(comp) comp, _ = transformations.uniquify_compiled_computation_names( building_blocks.ComputationBuildingBlock.from_proto( computation_impl.ComputationImpl.get_proto(comp))) return comp