Esempio n. 1
0
    def test_two_sub_components(self):
        stack = Stack(Dummy1To1(scope="A", constant_value=3.0),
                      Dummy1To1(scope="B", constant_value=1.0),
                      api_methods={"run"})
        test = ComponentTest(component=stack,
                             input_spaces=dict(inputs=[float]))

        test.test(("run", 4.6),
                  expected_outputs=np.array(8.6, dtype=np.float32))
Esempio n. 2
0
    def test_two_sub_components_1to2_2to1(self):
        stack = Stack(Dummy1To2(scope="A", constant_value=1.5),
                      Dummy2To1(scope="B"),
                      api_methods={"run"})
        test = ComponentTest(component=stack,
                             input_spaces=dict(inputs=FloatBox()))

        # Expect: (in + 1.5, in * 1.5) -> (1.5, 0.0) -> (1.5 + 0.0) = 1.5
        test.test(("run", 0.0),
                  expected_outputs=np.array(1.5, dtype=np.float32))
Esempio n. 3
0
    def test_two_sub_components_2to1_1to2(self):
        # Try different ctor with list as first item.
        stack = Stack(
            [Dummy2To1(scope="A"),
             Dummy1To2(scope="B", constant_value=2.3)],
            api_methods={"run"})
        test = ComponentTest(component=stack,
                             input_spaces=dict(inputs=[FloatBox(), float]))

        # Expect: (in1 + in2) -> 0.1 -> (0.1 + 2.3, 0.1 * 2.3)
        test.test(("run", [0.0, 0.1]), expected_outputs=(2.4, 0.23))
Esempio n. 4
0
    def test_two_sub_components_and_time_rank_folding(self):
        stack = Stack(Dummy1To1(scope="A", constant_value=3.0),
                      Dummy1To1(scope="B", constant_value=1.0),
                      api_methods=[dict(api="run", fold_time_rank=True)])
        test = ComponentTest(
            component=stack,
            input_spaces=dict(
                inputs=[FloatBox(add_time_rank=True, add_batch_rank=True)]))

        test.test(("run", np.array([[4.6, 5.2], [1.0, 2.0]])),
                  expected_outputs=np.array([8.6, 9.2, 5.0, 6.0],
                                            dtype=np.float32))
Esempio n. 5
0
 def test_non_matching_sub_components_in_stack(self):
     stack = Stack(Dummy2To1(scope="A"),
                   Dummy2To1(scope="B"),
                   api_methods={"run"})
     try:
         ComponentTest(component=stack,
                       input_spaces=dict(inputs=[float, float]))
     except RLGraphAPICallParamError:
         print("expected this error.")
         return
     else:
         # Something went wrong.
         assert False, "Expected Error on non-matching sub-Components in Stack, but none was thrown!"
Esempio n. 6
0
    def test_two_sub_components_and_time_rank_unfolding(self):
        stack = Stack(Dummy1To1(scope="A", constant_value=3.0),
                      Dummy1To1(scope="B", constant_value=1.0),
                      api_methods=[dict(api="run", unfold_time_rank=True)])
        input_space = FloatBox(add_batch_rank=True)
        test = ComponentTest(
            component=stack,
            input_spaces=dict(
                inputs=[input_space, input_space.with_time_rank()]))

        input_ = input_space.sample(size=4)
        input_before_folding = input_.reshape((2, 2))

        test.test(
            ("run", [np.array([4.6, 5.2, 1.0, 2.0]), input_before_folding]),
            expected_outputs=np.array([[8.6, 9.2], [5.0, 6.0]],
                                      dtype=np.float32))
Esempio n. 7
0
    def test_two_sub_components_1to2_2to1_time_rank_folding_and_unfolding(
            self):
        stack = Stack(
            [Dummy1To2(scope="A", constant_value=1.5),
             Dummy2To1(scope="B")],
            api_methods=[
                dict(api="run", fold_time_rank=True, unfold_time_rank=True)
            ])
        input_space = FloatBox(add_batch_rank=True,
                               add_time_rank=True,
                               time_major=True)
        test = ComponentTest(component=stack,
                             input_spaces=dict(inputs=[input_space]))

        input_ = input_space.sample(size=(2, 3))
        expected_outputs = input_ + 1.5 + (input_ * 1.5)

        test.test(("run", input_), expected_outputs=expected_outputs)
Esempio n. 8
0
    def test_one_sub_component(self):
        stack = Stack(Dummy1To1(constant_value=3.0), api_methods={"run"})
        test = ComponentTest(component=stack, input_spaces=dict(inputs=float))

        test.test(("run", 4.6), expected_outputs=7.6)