Shark-ML / Shark

The Shark Machine Leaning Library. See more:
http://shark-ml.github.io/Shark/
GNU Lesser General Public License v3.0
493 stars 130 forks source link

Error in tutorial and example #274

Closed jhlq closed 4 years ago

jhlq commented 4 years ago

So I was modifying the code from http://image.diku.dk/shark/sphinx_pages/build/html/rest_sources/tutorials/algorithms/ffnet.html and got the error error: missing template arguments before ‘optimizer’ Adam optimizer;

Recently cloned and built from github so I navigated to the examples folder and copied the file in question to a new location, created a CMakeLists.txt according to http://image.diku.dk/shark/sphinx_pages/build/html/rest_sources/tutorials/first_steps/your_programs.html and tried to run, but... CMakeFiles/ExampleProject.dir/FFNNBasicTutorial.cpp.o: In functionmain': FFNNBasicTutorial.cpp:(.text.startup+0x145): undefined reference to shark::importSparseData(shark::LabeledData<remora::vector<double, remora::cpu_tag>, unsigned int>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int, unsigned long)'

While writing this I noticed the code in the examples file was slightly different: Adam<> optimizer; That resolves the first issue, and the code is correct in http://www.shark-ml.org/sphinx_pages/build/html/rest_sources/tutorials/algorithms/ffnet.html so it seems it was just the image.diku page that is outdated.

The importSparseData function is not really relevant to my project, but thought you might want to know there is a problem.

jhlq commented 4 years ago

Was trying http://www.shark-ml.org/sphinx_pages/build/html/rest_sources/tutorials/first_steps/general_optimization_tasks.html on the work laptop and importCSV complained about input not being same length as labels, but like in the tutorial I was loading separate files for input and labels... When running the code at home it stops at compilation with undefined references to csvStringToData...

Tried the regressionTutorial.cpp file directly from build examples folder and

CMakeFiles/ExampleProject.dir/regressionTutorial.cpp.o: In function `void shark::importCSV<remora::vector<double, remora::cpu_tag> >(shark::Data<remora::vector<double, remora::cpu_tag> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, char, unsigned long, unsigned long) [clone .constprop.997]':
regressionTutorial.cpp:(.text+0x4da): undefined reference to `shark::csvStringToData(shark::Data<remora::vector<double, remora::cpu_tag> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char, char, unsigned long)'
collect2: error: ld returned 1 exit status

Trying the tpp files from source only gives

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
Ulfgard commented 4 years ago

Hi,

you have to link the shark library to the executable.

And you are right, the webpage lists the sorce of the latest release, but i think this is not perfectly aligned with the current master branch! Sorry for that!


From: Marcus Appelros [notifications@github.com] Sent: Thursday, October 24, 2019 3:47 PM To: Shark-ML/Shark Cc: Subscribed Subject: Re: [Shark-ML/Shark] Error in tutorial and example (#274)

Was trying http://www.shark-ml.org/sphinx_pages/build/html/rest_sources/tutorials/first_steps/general_optimization_tasks.html on the work laptop and importCSV complained about input not being same length as labels, but like in the tutorial I was loading separate files for input and labels... When running the code at home it stops at compilation with undefined references to csvStringToData...

Tried the regressionTutorial.cpp file directly from build examples folder and

CMakeFiles/ExampleProject.dir/regressionTutorial.cpp.o: In function void shark::importCSV<remora::vector<double, remora::cpu_tag> >(shark::Data<remora::vector<double, remora::cpu_tag> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, char, unsigned long, unsigned long) [clone .constprop.997]': regressionTutorial.cpp:(.text+0x4da): undefined reference toshark::csvStringToData(shark::Data<remora::vector<double, remora::cpu_tag> >&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char, char, unsigned long)' collect2: error: ld returned 1 exit status

Trying the tpp files from source only gives

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference tomain'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/Shark-ML/Shark/issues/274?email_source=notifications&email_token=ADSZGBXGK6FVTINFIWU56DTQQGRONA5CNFSM4JEFOCUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECFCYCQ#issuecomment-545926154, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADSZGBR466ENXAUJ45NUJFTQQGRONANCNFSM4JEFOCUA.

jhlq commented 4 years ago

I do link it, if I uncomment the importCSV commands it compiles fine, and I was able to construct a model and evaluate it on random data.

jhlq commented 4 years ago

Running the ExampleProject works:

/ml/ExampleProject$ ./ExampleProject
{
    "version": {
        "major": "4",
        "minor": "0",
        "patch": "0"
    },
    "isOfficialRelease": "false",
    "platform": "linux",
    "compiler": "GNU C++ version 5.4.0 20160609",
    "stdLib": "GNU libstdc++ version 20160609",
    "boostVersion": {
        "major": "1",
        "minor": "58",
        "patch": "0"
    },
    "buildType": "Release",
    "dynamicBuild": "false",
    "hasOpenMp": "true"
}

I think I updated Ubuntu after compiling Shark, could that be a problem?

Ulfgard commented 4 years ago

around 80-90% of shark functionality does not require the library, this includes almost all import/export routines, but also some concrete algorithms. The library to link got built while you built shark and should be located in your_cmake_build_directory/lib/

Best, Oswin


From: Marcus Appelros [notifications@github.com] Sent: Thursday, October 24, 2019 5:55 PM To: Shark-ML/Shark Cc: Oswin Krause; Comment Subject: Re: [Shark-ML/Shark] Error in tutorial and example (#274)

I do link it, if I uncomment the importCSV commands it compiles fine, and I was able to construct a model and evaluate it on random data.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/Shark-ML/Shark/issues/274?email_source=notifications&email_token=ADSZGBT5354433QFXML6JG3QQHAPBA5CNFSM4JEFOCUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECFQ7RY#issuecomment-545984455, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADSZGBW6BXQF3G3DDWQB5V3QQHAPBANCNFSM4JEFOCUA.

jhlq commented 4 years ago

Shouldn't that be taken care of by set(SHARK_LIBRARIES "/usr/lib/x86_64-linux-gnu/libboost_serialization.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/liblapack.so;/usr/lib/libcblas.so;/usr/lib/libatlas.so;shark;") in SharkConfig.cmake?

Updated Ubuntu again to 18 and now it doesn't find several libraries like lapack and cblas, going to try and rebuild. Read several articles that said there can be linking problems after updating GCC.

Ulfgard commented 4 years ago

the best way is to look at examples/ExampleProject and use the CMakeLists.txt as example. I think errors should be reported based on this.


From: Marcus Appelros [notifications@github.com] Sent: Friday, October 25, 2019 10:45 AM To: Shark-ML/Shark Cc: Oswin Krause; Comment Subject: Re: [Shark-ML/Shark] Error in tutorial and example (#274)

Shouldn't that be taken care of by set(SHARK_LIBRARIES "/usr/lib/x86_64-linux-gnu/libboost_serialization.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/liblapack.so;/usr/lib/libcblas.so;/usr/lib/libatlas.so;shark;") in SharkConfig.cmake?

Updated Ubuntu again to 18 and now it doesn't find several libraries like lapack and cblas, going to try and rebuild. Read several articles that said there can be linking problems after updating GCC.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/Shark-ML/Shark/issues/274?email_source=notifications&email_token=ADSZGBWDYH57PDEVVMHVSBTQQKWZTA5CNFSM4JEFOCUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECHU7BY#issuecomment-546262919, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADSZGBWJ4M4L66MYMV67TN3QQKWZTANCNFSM4JEFOCUA.

jhlq commented 4 years ago

After rebuilding Shark everything works!

PS. Found a typo in http://www.shark-ml.org/sphinx_pages/build/html/rest_sources/installation.html "On may systems"