Portál AbcLinuxu, 28. října 2025 02:18
Zdravim,
upravuji kod pro modelovani neuronovych siti jako v neokortexu a snazim se pridat podporu pro Clang.
Potreboval bych poradit s porovnanim templatu a namespace v C++.
Kod, o kterem mluvim je k nahlednuti zde: https://github.com/breznak/nupic/tree/compilation .
Zde je vystup pri prekladu s chybou:
In file included from
/home/marek/devel/nupic/nta/algorithms/SparsePooler.cpp:28:
In file included from
/home/marek/devel/nupic/nta/algorithms/SparsePooler.hpp:40:
/home/marek/devel/nupic/nta/math/stl_io.hpp:514:20: error: call to function
'operator<<' that is neither visible in the template definition nor found
by argument-dependent
lookup
out_stream << v[i] << ' ';
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:532:11: note: in instantiation
of member function 'nta::vector_saver<std::vector<std::pair<unsigned int,
unsigned int>,
std::allocator<std::pair<unsigned int, unsigned int> > >,
false>::save' requested here
saver.save(n, out_stream, v);
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:542:5: note: in instantiation
of function template specialization
'nta::vector_save<std::vector<std::pair<unsigned int, unsigned
int>, std::allocator<std::pair<unsigned int, unsigned int> > > >'
requested here
vector_save(v.size(), out_stream, v);
^
/home/marek/devel/nupic/nta/algorithms/SparsePooler.cpp:79:39: note: in
instantiation of function template specialization
'nta::operator<<<std::vector<std::pair<unsigned int,
unsigned int>, std::allocator<std::pair<unsigned int, unsigned int> >
> >' requested here
outStream << segmentSize() << " " << masks_ << " ";
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:540:24: note: 'operator<<'
should be declared prior to the call site
inline std::ostream& operator<<(std::ostream& out_stream, const
std::vector<T>& v)
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:430:19: error: call to function
'operator>>' that is neither visible in the template definition nor found
by argument-dependent
lookup
in_stream >> v[i];
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:443:12: note: in instantiation
of member function 'nta::vector_loader<std::vector<std::pair<unsigned int,
unsigned int>,
std::allocator<std::pair<unsigned int, unsigned int> > >,
false>::load' requested here
loader.load(n, in_stream, v);
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:558:5: note: in instantiation
of function template specialization
'nta::vector_load<std::vector<std::pair<unsigned int, unsigned
int>, std::allocator<std::pair<unsigned int, unsigned int> > > >'
requested here
vector_load(n, in_stream, v);
^
/home/marek/devel/nupic/nta/algorithms/SparsePooler.cpp:85:49: note: in
instantiation of function template specialization
'nta::operator>><std::vector<std::pair<unsigned int,
unsigned int>, std::allocator<std::pair<unsigned int, unsigned int> >
> >' requested here
inStream >> segment_size_ >> general_vector >> masks_;
^
/home/marek/devel/nupic/nta/math/stl_io.hpp:553:3: note: 'operator>>'
should be declared prior to the call site
operator>>(std::istream& in_stream, std::vector<T>& v)
^
3 warnings and 2 errors generated.
make[2]: *** [libalgorithms_a-SparsePooler.o] Error 1
make[2]: Leaving directory `/tmp/ntabuild/nta/algorithms'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/tmp/ntabuild/nta'
make: *** [install-recursive] Error 1
V podstate navod na reseni je podle meho tady http://clang.llvm.org/compatibility.html#dep_lookup , ale nevim, jak ho pouzit pro tento pripad :)
Zatim jsem se ptal na ML (anglicky) http://lists.numenta.org/pipermail/nupic_lists.numenta.org/2013-June/000398.html , ale bez odpovedi..
Budu moc rad, pokud mi nejaky zkusenejsi C++ programator poradi!
Diky, Marek
int Multiply(int x, int y) {
return x * y;
}
template <typename T> T Squared(T x) {
return Multiply(x, x);
}
int main() {
return Squared(5);
}
Dufam, ze Vam to pomoze.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.