예제 #1
0
파일: main.py 프로젝트: tomsmeding/ADBench
def main(argv):
    try:
        if (len(argv) < 9):
            eprint("usage: PythonRunner test_type module_path input_filepath " +\
                "output_dir minimum_measurable_time nruns_F nruns_J time_limit [-rep]\n")
            return 1

        test_type = argv[1]
        module_path = os.path.normpath(argv[2])
        input_filepath = os.path.normpath(argv[3])
        output_prefix = os.path.normpath(argv[4])
        minimum_measurable_time = float(argv[5])
        nruns_F = int(argv[6])
        nruns_J = int(argv[7])
        time_limit = float(argv[8])

        # read only 1 point and replicate it?
        replicate_point = (len(argv) > 9 and str(argv[9]) == "-rep")

        # If the given prefix is a directory then add a separator to its end
        # thus we can just use concatenation further
        if os.path.isdir(output_prefix):
            output_prefix += os.path.sep

        if test_type == "GMM":
            # read gmm input
            _input = input_utils.read_gmm_instance(input_filepath, replicate_point)
        elif test_type == "BA":
            # read ba input
            _input = input_utils.read_ba_instance(input_filepath)
        elif test_type == "HAND":
            model_dir = os.path.join(filepath_to_dirname(input_filepath), "model")
            # read hand input
            _input = input_utils.read_hand_instance(model_dir, input_filepath, False)
        elif test_type == "HAND-COMPLICATED":
            model_dir = os.path.join(filepath_to_dirname(input_filepath), "model")
            # read hand complicated input
            _input = input_utils.read_hand_instance(model_dir, input_filepath, True)
        elif test_type == "LSTM":
            _input = input_utils.read_lstm_instance(input_filepath)
        else:
            raise RuntimeError("Python runner doesn't support tests of " + test_type + " type")

        run_benchmark(
            module_path,
            input_filepath,
            _input,
            output_prefix,
            minimum_measurable_time,
            nruns_F,
            nruns_J,
            time_limit
        )

    except RuntimeError as ex:
        eprint("Runtime exception caught: ", ex)
    except Exception as ex:
        eprint("An exception caught: ", ex)

    return 0
예제 #2
0
파일: ba_tests.py 프로젝트: iliaeg/ADBench
    def test_jacobian_runs_multiple_times(self):
        '''Checks if jacobian can be calculated multiple times.'''

        input = read_ba_instance(TEST_INPUT_FILE_NAME)
        self.test.prepare(input)

        func = self.test.calculate_jacobian
        self.assertTrue(utils.can_objective_run_multiple_times(func))
예제 #3
0
파일: ba_tests.py 프로젝트: iliaeg/ADBench
    def objective_calculation_correctness(self, times):
        '''Checks objective calculation correctness running calculation
        several times.'''

        input = read_ba_instance(TEST_INPUT_FILE_NAME)
        self.test.prepare(input)
        self.test.calculate_objective(times)
        output = self.test.output()

        expected_weight_err = np.full(10, 8.26092651515999976e-01)
        expected_reproj_err = np.array(
            [-2.69048849235189402e-01, 2.59944792677901881e-01] * 10)

        self.assertFloatArrayEqual(expected_reproj_err, output.reproj_err,
                                   self.params["tolerance"])

        self.assertFloatArrayEqual(expected_weight_err, output.w_err,
                                   self.params["tolerance"])
예제 #4
0
파일: ba_tests.py 프로젝트: iliaeg/ADBench
    def jacobian_calculation_correctness(self, times):
        '''Checks jacobian calculation correctness running calculation
        several times.'''

        input = read_ba_instance(TEST_INPUT_FILE_NAME)
        self.test.prepare(input)
        self.test.calculate_jacobian(times)
        output = self.test.output()

        # check jacobian shape
        self.assertEqual(30, output.J.nrows)
        self.assertEqual(62, output.J.ncols)
        self.assertEqual(31, len(output.J.rows))
        self.assertEqual(310, len(output.J.cols))
        self.assertEqual(310, len(output.J.vals))

        # check jacobian values
        expected_J_values = [
            2.28877202208246757e+02, 6.34574811495545418e+02,
            -7.82222866259340549e+02, 2.42892615607159668e+00,
            -1.17828079628011313e+01, 2.54169312487743460e+00,
            -1.03657084958518086e+00, 4.17022e-01, 0.0,
            -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, 2.28877202208246757e+02,
            6.34574811495545418e+02, -7.82222866259340549e+02,
            2.42892615607159668e+00, -1.17828079628011313e+01,
            2.54169312487743460e+00, -1.03657084958518086e+00, 4.17022e-01,
            0.0, -3.50739521096005205e+02, -9.12107773668008576e+02,
            -2.42892615607159668e+00, 1.17828079628011313e+01,
            -2.54169312487743460e+00, -6.45167039712987389e-01,
            -1.20542435994996879e+02, -3.85673240766460424e+02,
            9.75476291403326456e+01, -1.78372108529576567e+00,
            4.15466799433126077e+00, 2.04025718029898906e+00,
            3.49176397433145880e-01, 0.0, 4.17022e-01, 1.18149147704414503e+02,
            3.07250108960343255e+02, 1.78372108529576567e+00,
            -4.15466799433126077e+00, -2.04025718029898906e+00,
            6.23335921553064054e-01, -8.34044e-01, -8.34044e-01, -8.34044e-01,
            -8.34044e-01, -8.34044e-01, -8.34044e-01, -8.34044e-01,
            -8.34044e-01, -8.34044e-01, -8.34044e-01
        ]

        self.assertFloatArrayEqual(expected_J_values, output.J.vals,
                                   self.params["tolerance"])