improbable-eng / phtree-cpp

PH-Tree C++ implementation by Improbable.
Apache License 2.0
22 stars 15 forks source link

query: compilation error with FilterSphere #39

Closed andreadimax closed 1 year ago

andreadimax commented 1 year ago

Compilation error when trying to use FilterSphere in for_each function.

Steps to reproduce:

int main(){

using namespace improbable::phtree;
using namespace std;

auto p = PhTreeD<3, bool>();

p.insert(PhPointD<3>({0,0,0}), true);
p.insert(PhPointD<3>({0,1,0}), true);
p.insert(PhPointD<3>({0,0,1}), true);
p.insert(PhPointD<3>({1,0,0}), true);
p.insert(PhPointD<3>({-1,0,0}), true);
p.insert(PhPointD<3>({0,-1,0}), true);
p.insert(PhPointD<3>({0,0,-1}), true);
p.insert(PhPointD<3>({-1,0,-1}), true);
p.insert(PhPointD<3>({-1,-1,-1}), true);
p.insert(PhPointD<3>({-1,0,-1}), true);
p.insert(PhPointD<3>({1,0,1}), true);
p.insert(PhPointD<3>({1,1,1}), true);

struct Printer {
    void operator()(PhPointD<3> key, bool t) {
        cout << "Point is: " << key << endl;
    }
    size_t n_ = 0;
};

Printer callback;

p.for_each(callback, FilterSphere({0,0,0}, 0.5, p.converter()));

return 0;

}


Command used to compile with gcc:
`g++ -I "path\\to\\phtree\\header_file"  prova_ph.cpp -o ph`

Error given:
In file included from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/common.h:24, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/phtree.h:20, from prova_ph.cpp:2: D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/filter.h: In instantiation of 'improbable::phtree::FilterSphere<CONVERTER, DISTANCE>::FilterSphere(const KeyExternal&, const ScalarExternal&, CONVERTER, DISTANCE) [with CONVERTER = improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>; DISTANCE = improbable::phtree::DistanceEuclidean<3>; improbable::phtree::FilterSphere<CONVERTER, DISTANCE>::KeyExternal = std::array<double, 3>; improbable::phtree::FilterSphere<CONVERTER, DISTANCE>::ScalarExternal = double]': prova_ph.cpp:34:66: required from here D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/filter.h:175:37: error: cannot convert 'improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>::PointInternal' {aka 'std::array<long long int, 3>'} to 'double' in initialization 175 , centerinternal{converter.pre(center)} ~~~^~
improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>::PointInternal {aka std::array<long long int, 3>}

D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/filter.h: In instantiation of 'bool improbable::phtree::FilterSphere<CONVERTER, DISTANCE>::IsNodeValid(const KeyInternal&, int) const [with CONVERTER = improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>; DISTANCE = improbable::phtree::DistanceEuclidean<3>; improbable::phtree::FilterSphere<CONVERTER, DISTANCE>::KeyInternal = std::array<long long int, 3>]': D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/v16/for_each.h:56:40: required from 'void improbable::phtree::v16::ForEach<T, CONVERT, CALLBACK_FN, FILTER>::TraverseNode(const KeyInternal&, const NodeT&) [with T = bool; CONVERT = improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>; CALLBACK_FN = main()::Printer; FILTER = improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >; improbable::phtree::v16::ForEach<T, CONVERT, CALLBACK_FN, FILTER>::KeyInternal = std::array<long long int, 3>; improbable::phtree::v16::ForEach<T, CONVERT, CALLBACK_FN, FILTER>::NodeT = improbable::phtree::v16::Node<3, bool, long long int>]' D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/v16/for_each.h:44:9: required from 'void improbable::phtree::v16::ForEach<T, CONVERT, CALLBACK_FN, FILTER>::run(const EntryT&) [with T = bool; CONVERT = improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>; CALLBACK_FN = main()::Printer; FILTER = improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >; improbable::phtree::v16::ForEach<T, CONVERT, CALLBACK_FN, FILTER>::EntryT = improbable::phtree::v16::Entry<3, bool, long long int>]' D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/v16/phtree_v16.h:279:83: required from 'void improbable::phtree::v16::PhTreeV16<DIM, T, CONVERT>::for_each(CALLBACK_FN&, FILTER) const [with CALLBACK_FN = main()::Printer; FILTER = improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >; long long unsigned int DIM = 3; T = bool; CONVERT = improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>]' D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/phtree.h:163:23: required from 'void improbable::phtree::PhTree<DIM, T, CONVERTER>::for_each(CALLBACK_FN&, FILTER) const [with CALLBACK_FN = main()::Printer; FILTER = improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >; long long unsigned int DIM = 3; T = bool; CONVERTER = improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>]' prova_ph.cpp:34:15: required from here D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/filter.h:207:46: error: no matching function for call to 'clamp(const value_type&, improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >::ScalarInternal&, improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >::ScalarInternal&)' 207 | closest_in_bounds[i] = std::clamp(centerinternal[i], lo, hi); | ~~^~~~~~~~~ In file included from D:/Programmi/JetBrains/CLion 2022.1.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/algorithm:62, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/base_types.h:20, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/common.h:20, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/phtree.h:20, from prova_ph.cpp:2: D:/Programmi/JetBrains/CLion 2022.1.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/stl_algo.h:3656:5: note: candidate: 'template constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&)' 3656 | clamp(const _Tp& val, const _Tp& __lo, const _Tp& hi) | ^~~~~ D:/Programmi/JetBrains/CLion 2022.1.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/stl_algo.h:3656:5: note: template argument deduction/substitution failed: In file included from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/common.h:24, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/phtree.h:20, from prova_ph.cpp:2: D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/filter.h:207:46: note: deduced conflicting types for parameter 'const _Tp' ('double' and 'improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >::ScalarInternal' {aka 'long long int'}) 207 | closest_in_bounds[i] = std::clamp(centerinternal[i], lo, hi); | ~~^~~~~~~~~ In file included from D:/Programmi/JetBrains/CLion 2022.1.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/algorithm:62, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/phtree.h:20, from prova_ph.cpp:2: D:/Programmi/JetBrains/CLion 2022.1.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/stl_algo.h:3674:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&, _Compare)' 3674 | clamp(const _Tp& val, const _Tp& __lo, const _Tp& hi, _Compare __comp) | ^~~~~ D:/Programmi/JetBrains/CLion 2022.1.3/bin/mingw/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/bits/stl_algo.h:3674:5: note: template argument deduction/substitution failed: In file included from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/common.h:24, from D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/phtree.h:20, from prova_ph.cpp:2: D:\Documenti\Progetto tesi\include/phtree-cpp/phtree/common/filter.h:207:46: note: deduced conflicting types for parameter 'const _Tp' ('double' and 'improbable::phtree::FilterSphere<improbable::phtree::SimplePointConverter<3, double, long long int, improbable::phtree::ScalarConverterIEEE>, improbable::phtree::DistanceEuclidean<3> >::ScalarInternal' {aka 'long long int'}) 207 | closest_in_bounds[i] = std::clamp(centerinternal[i], lo, hi)



**Environment**:
- OS (e.g. from /etc/os-release): Windows 11
- GCC version: 11.2.0
- Others:
tzaeschke commented 1 year ago

Hi, thanks for reporting! As far as I understand, this repo is not maintained at the moment. I maintained this while I was working at Improbable, I now maintain my own fork here: https://github.com/tzaeschke/phtree-cpp

I tried reproducing it with the latest version of my fork and I cannot reproduce it (Ubuntu 22.04, GCC 11.3.0). My fork underwent some major refactoring, so this problem may have been fixed on the way. Note that the paths have changed, everything was moved to a subfolder include.

Could you try the version from my repo? If the issue persists, could you raise an issue over there?

andreadimax commented 1 year ago

Forked your newer repo and it works! Thank you!