def __init__(self, child: FrameGenerator, dilator: Easing, dilator_kwargs: typing.Optional[dict] = None): tus.check(child=(child, FrameGenerator), dilator_kwargs=(dilator_kwargs, (dict, type(None)))) tus.check_callable(dilator=dilator) self.child = child self.dilator = dilator self.dilator_kwargs = (dilator_kwargs if dilator_kwargs is not None else dict())
def __init__(self, child: Scene, dilator: Easing, dilator_kwargs: dict = None): tus.check(child=(child, Scene), dilator_kwargs=(dilator_kwargs, (dict, type(None)))) tus.check_callable(dilator=dilator) self.dilator = dilator self.dilator_kwargs = (dict() if dilator_kwargs is None else dilator_kwargs) self.child = child
def dilate(self, dilator: Easing, dilator_kwargs: typing.Optional[dict] = None) -> 'FluentScene': """Transforms time according to the given easing. Args: dilator (Easing): The rule for manipulating time dilator_kwargs (dict, optional): Arguments to the dilator. """ tus.check(dilator_kwargs=(dilator_kwargs, (dict, type(None)))) tus.check_callable(dilator=dilator) return self.apply(TimeDilateScene, dilator, dilator_kwargs)
def dilate(self, dilator: Easing, dilator_kwargs: typing.Optional[dict] = None) -> 'FluentFG': """Rescales time for the current frame generator to be rescaled by the given dilator. Args: dilator (Easing): the rule for changing time dilator_kwargs (typing.Optional[dict]): if specified, the keyword arguments to the dilator """ tus.check(dilator_kwargs=(dilator_kwargs, (dict, type(None)))) tus.check_callable(dilator=dilator) return self.apply(TimeDilateFrameGenerator, dilator, dilator_kwargs)
def apply(self, transform: typing.Callable, *args, **kwargs) -> 'FluentFG': """Applies the given transformation to the currently build frame generator, using the given arguments Args: transform (typing.Callable): Must accept FrameGenerator, *args, **kwargs and return a FrameGenerator """ tus.check_callable(transform=transform) if self.followed_by: self.base = self.build() self.followed_by = [] self.base = transform(self.base, *args, **kwargs) tus.check(transform_result=(self.base, FrameGenerator)) return self
def forward_with(fc_layers, norms, learning, inp, acts_cb): """Applies the forward pass to the given input data using the given fully connected layers and norms. If learning is set, it is invoked prior to the norms. Args: fc_layers (list[nn.Linear]): the three linear layers in the order they are invoked norms (list[nn.BatchNorm1d]): Or equivalent callables. learning (list[LearningAbsoluteNormLayer], optional): learning absolute norms or None inp (torch.tensor[batch_size, encode_dim]): the encoded game state acts_cb (callable, optional): passed FFHiddenActivations 4 times at times 0-3 respectively """ tus.check_tensors(inp=(inp, (('batch', None), ('input_dim', ENCODE_DIM)), torch.float32)) if acts_cb: tus.check_callable(acts_cb=acts_cb) acts_cb(FFHiddenActivations(layer=0, hidden_acts=inp)) if learning: learning[0](inp) res = norms[0](inp) res = fc_layers[0](res) res = torch.tanh(res) if learning: learning[1](res) res = norms[1](res) if acts_cb: acts_cb(FFHiddenActivations(layer=1, hidden_acts=res)) res = fc_layers[1](res) res = torch.tanh(res) if learning: learning[2](res) res = norms[2](res) if acts_cb: acts_cb(FFHiddenActivations(layer=2, hidden_acts=res)) res = fc_layers[2](res) res = torch.tanh(res) if acts_cb: acts_cb(FFHiddenActivations(layer=3, hidden_acts=res)) return res
def __init__(self, child, transform): tus.check(child=(child, Token)) tus.check_callable(transform=transform) self.child = child self.transform = transform
def test_checkcallable_lambda_pass(self): tus.check_callable(a=lambda x: True)
def test_checkcallable_function_pass(self): def foo(): pass tus.check_callable(a=foo)
def tests_checkcallable_int_fail(self): with self.assertRaises(ValueError): tus.check_callable(a=5)
def test_checkcallable_class_pass(self): tus.check_callable(a=TestCheckCallableMethod)
def test_checkcallable_noarg_pass(self): tus.check_callable()
def __init__(self, stop_failer: typing.Callable, max_out_len: int): tus.check(max_out_len=(max_out_len, int)) tus.check_callable(stop_failer=stop_failer) self.max_out_len = max_out_len self.stop_failer = stop_failer