def __init__(self): super().__init__() self.list_member = ['relu'] with bd.magic_builder(): self.module_member = ['relu'] with bd.magic_builder(): self.module_member_2 = ['relu'] self.module_member_3 = ['relu'] self.list_member_2 = ['relu']
def test_context_is_set_correctly(self): class Foo(bd.Module): def __init__(self): super().__init__() self.member = ['relu'] member_is_list = Foo() with bd.magic_builder(): member_is_module = Foo() member_is_list_again = Foo() assert member_is_list.member == ['relu'] assert isinstance(member_is_module.member, nn.ReLU) assert member_is_list_again.member == ['relu']
def test_context_works_in_init(self): class Foo(bd.Module): def __init__(self): super().__init__() self.list_member = ['relu'] with bd.magic_builder(): self.module_member = ['relu'] self.list_member_2 = ['relu'] only_one_is_module = Foo() with bd.magic_builder(): all_are_modules = Foo() assert only_one_is_module.list_member == ['relu'] assert isinstance(only_one_is_module.module_member, nn.ReLU) assert only_one_is_module.list_member_2 == ['relu'] assert isinstance(all_are_modules.list_member, nn.ReLU) assert isinstance(all_are_modules.module_member, nn.ReLU) assert isinstance(all_are_modules.list_member_2, nn.ReLU)
def test_can_set_builder_context(self): with bd.magic_builder(): pass