Skip to content

Commit 66ae9a0

Browse files
committed
fixes to compilation and output
1 parent 7ab382a commit 66ae9a0

File tree

7 files changed

+56
-12
lines changed

7 files changed

+56
-12
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ project(libprlearn VERSION 1.0.0 LANGUAGES CXX)
66
if(NOT CMAKE_BUILD_TYPE)
77
set(CMAKE_BUILD_TYPE Release)
88
endif(NOT CMAKE_BUILD_TYPE)
9-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wpedantic")
10-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -Wall -Wpedantic")
9+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wpedantic -static-libgcc -static-libstdc++")
10+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -Wall -Wpedantic -static-libgcc -static-libstdc++")
11+
12+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1113
set(CMAKE_CXX_STANDARD 17)
1214

15+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
16+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
17+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
18+
1319
#actual library
1420
add_subdirectory(src)

src/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ set(CMAKE_CXX_STANDARD 17)
44
set(CMAKE_INCLUDE_CURRENT_DIR ON)
55

66

7-
add_library(prlearn ${HEADER_FILES} MLearning.cpp SimpleMLearning.cpp RefinementTree.cpp structs.cpp)
7+
add_library(prlearn SHARED ${HEADER_FILES} MLearning.cpp SimpleMLearning.cpp RefinementTree.cpp structs.cpp)
8+
add_library(prlearnStatic STATIC ${HEADER_FILES} MLearning.cpp SimpleMLearning.cpp RefinementTree.cpp structs.cpp)
9+
810
target_include_directories (prlearn PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
11+
target_include_directories (prlearnStatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
12+
set_target_properties(prlearnStatic PROPERTIES OUTPUT_NAME prlearn)
13+
914

1015
install(TARGETS prlearn
1116
LIBRARY DESTINATION lib

src/MLearning.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <memory>
3030
#include <algorithm>
3131
#include <iostream>
32+
#include <iomanip>
3233

3334
namespace prlearn {
3435

@@ -176,6 +177,7 @@ namespace prlearn {
176177
}
177178

178179
void MLearning::print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& edge_map, const std::vector<MLearning>& clouds) const {
180+
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
179181
for (size_t i = 0; i < tabs; ++i) s << "\t";
180182
s << "{";
181183
bool first = true;
@@ -210,7 +212,16 @@ namespace prlearn {
210212
s << "}";
211213
} else {
212214
for (size_t i = 0; i < tabs; ++i) s << "\t";
213-
s << _q.avg();
215+
if(_q.cnt() > 0)
216+
{
217+
auto v = _q.avg();
218+
if(!std::isinf(v) && !std::isnan(v))
219+
s << v;
220+
else
221+
s << "\"inf\"";
222+
}
223+
else
224+
s << "\"inf\"";
214225
}
215226
}
216227

src/MLearning.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <map>
3333
#include <limits>
3434

35-
namespace prlearn {
35+
namespace prlearn {
3636

3737
class MLearning {
3838
public:

src/RefinementTree.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525

2626
#include "RefinementTree.h"
2727
#include <limits>
28+
#include <iomanip>
29+
2830
namespace prlearn {
2931

3032
RefinementTree::RefinementTree() {
3133
}
3234

3335
void RefinementTree::print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& edge_map) const {
36+
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
3437
for (size_t i = 0; i < tabs; ++i) s << "\t";
3538
s << "{";
3639
bool first = true;
@@ -121,7 +124,11 @@ namespace prlearn {
121124
for (size_t i = 0; i < tabs; ++i) s << "\t";
122125
s << "}";
123126
} else {
124-
s << _predictor._q.avg();
127+
auto v = _predictor._q.avg();
128+
if(!std::isinf(v) && !std::isnan(v))
129+
s << _predictor._q.avg();
130+
else
131+
s << "\"inf\"";
125132
}
126133
}
127134

src/SimpleMLearning.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
#include "SimpleMLearning.h"
27+
#include <iomanip>
2728

2829
namespace prlearn {
2930
SimpleMLearning::~SimpleMLearning() {
@@ -58,6 +59,7 @@ namespace prlearn {
5859
}
5960

6061
void SimpleMLearning::print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& label_map, const std::vector<SimpleMLearning>& other) const {
62+
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
6163
for (size_t i = 0; i < tabs; ++i) s << "\t";
6264
s << "{\"id\":" << (this - other.data()) << ",";
6365
bool first = true;
@@ -69,7 +71,13 @@ namespace prlearn {
6971
for (size_t i = 0; i < tabs + 1; ++i) s << "\t";
7072
s << "\"";
7173
s << label_map[el._label];
72-
s << "\":{\"val\":" << el._q.avg() << ",\"succs\":[";
74+
s << "\":{\"val\":";
75+
auto v = el._q.avg();
76+
if(!std::isinf(v) && !std::isnan(v))
77+
s << v;
78+
else
79+
s << "\"inf\"";
80+
s << ",\"succs\":[";
7381
bool f = true;
7482
for(auto& e : el._succssors)
7583
{

src/SimpleRegressor.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
#ifndef SIMPLEREGRESSOR_H
2626
#define SIMPLEREGRESSOR_H
2727

28+
#include "propts.h"
29+
#include "structs.h"
30+
2831
#include <limits>
2932
#include <vector>
3033
#include <map>
31-
32-
#include "propts.h"
33-
#include "structs.h"
34+
#include <iomanip>
3435

3536
namespace prlearn {
3637

@@ -73,10 +74,11 @@ namespace prlearn {
7374
res->_value.cnt() = std::min<size_t>(res->_cnt, options._q_learn_rate);
7475
res->_cnt += 1;
7576
res->_value += nval;
76-
assert(res->_value._avg >= 0);
77+
assert(res->_value.avg() >= 0);
7778
}
7879

7980
void print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& label_map) const {
81+
s << std::setprecision (std::numeric_limits<double>::digits10 + 1);
8082
for (size_t i = 0; i < tabs; ++i) s << "\t";
8183
s << "{";
8284
bool first = true;
@@ -85,7 +87,12 @@ namespace prlearn {
8587
first = false;
8688
s << "\n";
8789
for (size_t t = 0; t < tabs; ++t) s << "\t";
88-
s << "\"" << label_map[w._label] << "\" : " << w._value.avg();
90+
s << "\"" << label_map[w._label] << "\" : ";
91+
auto v = w._value.avg();
92+
if(!std::isinf(v) && !std::isnan(v))
93+
s << v;
94+
else
95+
s << "\"inf\"";
8996
}
9097
s << "\n";
9198
for (size_t i = 0; i < tabs; ++i) s << "\t";

0 commit comments

Comments
 (0)