Skip to content

Commit

Permalink
build simple bsi_functions successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
Lypho2012 committed Apr 9, 2024
1 parent b99623d commit d7cdcbd
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
Empty file removed bsi_functions.cpp
Empty file.
4 changes: 4 additions & 0 deletions bsi_functions_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import OpenSfM
a1 = [1, 2, 3]
a2 = [1,2,3]
print(OpenSfM.dot(a1,a2))
1 change: 0 additions & 1 deletion opensfm/actions/extract_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

def run_dataset(data: DataSetBase) -> None:
"""Extract metadata from images' EXIF tag."""
input("Press Enter to continue ")
exif_overrides = {}
if data.exif_overrides_exists():
exif_overrides = data.load_exif_overrides()
Expand Down
3 changes: 3 additions & 0 deletions opensfm/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ add_subdirectory(third_party/vlfeat)

include_directories(third_party/vlfeat)

####### Bsi Functions #######
pybind11_add_module(pybsi bsi_functions.cpp)

####### Debugging #######
if (CMAKE_BUILD_TYPE MATCHES DEBUG)
add_executable(debug_c_extension
Expand Down
49 changes: 49 additions & 0 deletions opensfm/src/bsi_functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include </home/czhang/OpenSfM/bsiCPP/bsi/BsiAttribute.hpp> // TODO: change to relative path
#include </home/czhang/OpenSfM/bsiCPP/bsi/BsiSigned.hpp>
#include </home/czhang/OpenSfM/bsiCPP/bsi/BsiUnsigned.hpp>
namespace py = pybind11;
/*template <typename T>
class Bsi {
public:
std::vector<int> shape;
Bsi() {}
Bsi(py::list<int> array) {
shape = {py::len(array)};
BsiSigned<uint64_t> bsi;
BsiAttribute<uint64_t>* bsiattribute = bsi.buildBsiAttributeFromVector(py::cast<std::vector<int>>array);
}
T arr;
}*/
/*std::vector<long> listToVec(py::list a) {
std::vector<long> res;
for (py::handle item: a) {
try {
res.push_back(item.cast<long>());
} catch (std::exception e) {throw std::runtime_error("could not cast to type long");}
}
return res;
}
long dot(py::list a, py::list b) {
BsiSigned<uint64_t> bsi;
BsiAttribute<uint64_t> *bsi_a = bsi.buildBsiAttributeFromVectorSigned(listToVec(a),0.5);
BsiAttribute<uint64_t> *bsi_b = bsi.buildBsiAttributeFromVectorSigned(listToVec(a),0.5);
//BsiAttribute<uint64_t> *bsi_a = bsi.buildBsiAttributeFromVectorSigned(py::cast<std::vector<long>> (a),0.5);
//BsiAttribute<uint64_t> *bsi_b = bsi.buildBsiAttributeFromVectorSigned(py::cast<std::vector<long>> (a),0.5);
return bsi_a->dot(bsi_b);
}
PYBIND11_MODULE(pybsi,m) {
//py::class_<Bsi<BsiAttribute<u_int64_t>>>(m,"bsi")
// .def(py::init<>());
m.def("dot", &dot);
}*/
int add(int i, int j) {
return i + j;
}

PYBIND11_MODULE(pybsi, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring

m.def("add", &add, "A function that adds two numbers");
}

0 comments on commit d7cdcbd

Please sign in to comment.