add generated dir as argument

This commit is contained in:
Willem Melching 2020-05-14 13:26:33 -07:00
parent f9d3744670
commit d3a79c6a42
3 changed files with 17 additions and 12 deletions

View File

@ -8,6 +8,9 @@ ekf_sym = "#rednose/helpers/ekf_sym.py"
to_build = {
'live': ('examples/live_kf.py', 'examples/generated'),
'pos_computer_4': ('rednose/helpers/lst_sq_computer.py', 'examples/generated'),
'pos_computer_5': ('rednose/helpers/lst_sq_computer.py', 'examples/generated'),
'feature_handler_5': ('rednose/helpers/feature_handler.py', 'examples/generated'),
}
@ -23,7 +26,6 @@ for target, (command, generated_folder) in found.items():
env.Command(target_files,
[templates, command_file, sympy_helpers, ekf_sym],
command_file.get_abspath()+" "+target
)
command_file.get_abspath() + " " + target + " " + Dir(generated_folder).get_abspath())
env.SharedLibrary(f'{generated_folder}/' + target, target_files[0])

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os
import sys
import numpy as np
@ -37,7 +38,7 @@ class FeatureHandler():
name = 'feature_handler'
@staticmethod
def generate_code(K=5):
def generate_code(generated_dir, K=5):
# Wrap c code for slow matching
c_header = "\nvoid merge_features(double *tracks, double *features, long long *empty_idxs);"
@ -47,9 +48,9 @@ class FeatureHandler():
c_code += "\n" + open(os.path.join(TEMPLATE_DIR, "feature_handler.c")).read()
filename = f"{FeatureHandler.name}_{K}"
write_code(filename, c_code, c_header)
write_code(generated_dir, filename, c_code, c_header)
def __init__(self, K=5):
def __init__(self, generated_dir, K=5):
self.MAX_TRACKS = 6000
self.K = K
@ -64,7 +65,7 @@ class FeatureHandler():
self.tracks[:] = np.nan
name = f"{FeatureHandler.name}_{K}"
ffi, lib = load_code(name)
ffi, lib = load_code(generated_dir, name)
def merge_features_c(tracks, features, empty_idxs):
lib.merge_features(ffi.cast("double *", tracks.ctypes.data),
@ -163,4 +164,5 @@ def generate_orient_error_jac(K):
if __name__ == "__main__":
# TODO: get K from argparse
FeatureHandler.generate_code()
generated_dir = sys.argv[2]
FeatureHandler.generate_code(generated_dir)

View File

@ -47,7 +47,7 @@ class LstSqComputer():
name = 'pos_computer'
@staticmethod
def generate_code(K=4):
def generate_code(generated_dir, K=4):
sympy_functions = generate_residual(K)
header, code = sympy_into_c(sympy_functions)
@ -59,15 +59,15 @@ class LstSqComputer():
"""
filename = f"{LstSqComputer.name}_{K}"
write_code(filename, code, header)
write_code(generated_dir, filename, code, header)
def __init__(self, K=4, MIN_DEPTH=2, MAX_DEPTH=500):
def __init__(self, generated_dir, K=4, MIN_DEPTH=2, MAX_DEPTH=500):
self.to_c = orient.rot_matrix(-np.pi / 2, -np.pi / 2, 0)
self.MAX_DEPTH = MAX_DEPTH
self.MIN_DEPTH = MIN_DEPTH
name = f"{LstSqComputer.name}_{K}"
ffi, lib = load_code(name)
ffi, lib = load_code(generated_dir, name)
# wrap c functions
def residual_jac(x, poses, img_positions):
@ -170,4 +170,5 @@ def project(poses, ecef_pos):
if __name__ == "__main__":
K = int(sys.argv[1].split("_")[-1])
LstSqComputer.generate_code(K=K)
generated_dir = sys.argv[2]
LstSqComputer.generate_code(generated_dir, K=K)