Skip to content

Commit 394b4bd

Browse files
committed
removed curl from header file
1 parent 4c988bb commit 394b4bd

File tree

2 files changed

+28
-51
lines changed

2 files changed

+28
-51
lines changed

src/shogun/io/OpenMLFlow.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <shogun/lib/type_case.h>
99
#include <shogun/util/factory.h>
1010

11+
#include <curl/curl.h>
1112
#include <rapidjson/document.h>
1213

1314
using namespace shogun;
@@ -25,16 +26,14 @@ using namespace rapidjson;
2526
*/
2627
size_t writer(char* data, size_t size, size_t nmemb, std::string* buffer_in)
2728
{
28-
// adapted from https://stackoverflow.com/a/5780603
29-
// Is there anything in the buffer?
30-
if (buffer_in->empty())
29+
// check that the buffer string points to something
30+
if (buffer_in != nullptr)
3131
{
3232
// Append the data to the buffer
3333
buffer_in->append(data, size * nmemb);
3434

3535
return size * nmemb;
3636
}
37-
3837
return 0;
3938
}
4039

@@ -55,7 +54,7 @@ const char* OpenMLReader::flow_file = "/flow/{}";
5554
/* TASK API */
5655
const char* OpenMLReader::task_file = "/task/{}";
5756
/* SPLIT API */
58-
const char* OpenMLReader::get_split = "/split/{}";
57+
const char* OpenMLReader::get_split = "/get/{}";
5958

6059
const std::unordered_map<std::string, std::string>
6160
OpenMLReader::m_format_options = {{"xml", xml_server},
@@ -72,10 +71,6 @@ const std::unordered_map<std::string, std::string>
7271
{"flow_file", flow_file},
7372
{"task_file", task_file}};
7473

75-
OpenMLReader::OpenMLReader(const std::string& api_key) : m_api_key(api_key)
76-
{
77-
}
78-
7974
void OpenMLReader::openml_curl_request_helper(const std::string& url)
8075
{
8176
CURL* curl_handle = nullptr;
@@ -95,20 +90,12 @@ void OpenMLReader::openml_curl_request_helper(const std::string& url)
9590

9691
CURLcode res = curl_easy_perform(curl_handle);
9792

98-
openml_curl_error_helper(curl_handle, res);
93+
if (res != CURLE_OK)
94+
SG_SERROR("Connection error: %s.\n", curl_easy_strerror(res))
9995

10096
curl_easy_cleanup(curl_handle);
10197
}
10298

103-
void OpenMLReader::openml_curl_error_helper(CURL* curl_handle, CURLcode code)
104-
{
105-
if (code != CURLE_OK)
106-
{
107-
// TODO: call curl_easy_cleanup(curl_handle) ?
108-
SG_SERROR("Connection error: %s.\n", curl_easy_strerror(code))
109-
}
110-
}
111-
11299
/**
113100
* Checks the returned response from OpenML in JSON format
114101
* @param doc the parsed OpenML JSON format response
@@ -298,7 +285,7 @@ void OpenMLFlow::upload_flow(const std::shared_ptr<OpenMLFlow>& flow)
298285
SG_SNOTIMPLEMENTED;
299286
}
300287

301-
void OpenMLFlow::dump()
288+
void OpenMLFlow::dump() const
302289
{
303290
SG_SNOTIMPLEMENTED;
304291
}
@@ -543,13 +530,13 @@ OpenMLTask::get_task_from_string(const std::string& task_type)
543530
SG_SERROR("OpenMLTask does not support \"%s\"", task_type.c_str())
544531
}
545532

546-
SGMatrix<int32_t> OpenMLTask::get_train_indices()
533+
SGMatrix<int32_t> OpenMLTask::get_train_indices() const
547534
{
548535
SG_SNOTIMPLEMENTED
549536
return SGMatrix<int32_t>();
550537
}
551538

552-
SGMatrix<int32_t> OpenMLTask::get_test_indices()
539+
SGMatrix<int32_t> OpenMLTask::get_test_indices() const
553540
{
554541
SG_SNOTIMPLEMENTED
555542
return SGMatrix<int32_t>();
@@ -685,18 +672,18 @@ class StringToShogun : public AnyVisitor
685672
* In OpenML "null" is an empty parameter value field.
686673
* @return whether the field is "null"
687674
*/
688-
SG_FORCED_INLINE bool is_null()
675+
SG_FORCED_INLINE bool is_null() const noexcept
689676
{
690677
bool result = strcmp(m_string_val.c_str(), "null") == 0;
691678
return result;
692679
}
693680

694-
SG_FORCED_INLINE void set_parameter_name(const std::string& name)
681+
SG_FORCED_INLINE void set_parameter_name(const std::string& name) noexcept
695682
{
696683
m_parameter = name;
697684
}
698685

699-
SG_FORCED_INLINE void set_string_value(const std::string& value)
686+
SG_FORCED_INLINE void set_string_value(const std::string& value) noexcept
700687
{
701688
m_string_val = value;
702689
}
@@ -774,7 +761,7 @@ std::shared_ptr<CSGObject> ShogunOpenML::flow_to_model(
774761
auto obj = instantiate_model_from_factory(module_name, algo_name);
775762
auto obj_param = obj->get_params();
776763

777-
std::unique_ptr<StringToShogun> visitor(new StringToShogun(obj));
764+
auto visitor = std::make_unique<StringToShogun>();
778765

779766
if (initialize_with_defaults)
780767
{
@@ -859,7 +846,7 @@ CLabels* ShogunOpenML::run_model_on_fold(
859846
return machine->apply(X_test);
860847
}
861848
else
862-
SG_SERROR("The provided model is not trainable!\n")
849+
SG_SERROR("The provided model is not a trainable machine!\n")
863850
}
864851
break;
865852
case OpenMLTask::TaskType::LEARNING_CURVE:

src/shogun/io/OpenMLFlow.h

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <shogun/base/SGObject.h>
1515
#include <shogun/io/SGIO.h>
1616

17-
#include <curl/curl.h>
18-
1917
#include <memory>
2018
#include <numeric>
2119
#include <string>
@@ -32,7 +30,7 @@ namespace shogun
3230
{
3331

3432
public:
35-
explicit OpenMLReader(const std::string& api_key);
33+
explicit OpenMLReader(const std::string& api_key): m_api_key(api_key) {}
3634

3735
/**
3836
* Returns a string returned by the server given a request.
@@ -51,6 +49,7 @@ namespace shogun
5149
get(const std::string& request, const std::string& format, Args... args)
5250
{
5351
std::string request_path;
52+
// clear the buffer before request
5453
m_curl_response_buffer.clear();
5554
auto find_format = m_format_options.find(format);
5655
if (find_format == m_format_options.end())
@@ -124,14 +123,6 @@ namespace shogun
124123
*/
125124
void openml_curl_request_helper(const std::string& url);
126125

127-
/**
128-
* Handles all possible codes
129-
*
130-
* @param curl_handle curl handle used in the request
131-
* @param code the code returned by the query
132-
*/
133-
void openml_curl_error_helper(CURL* curl_handle, CURLcode code);
134-
135126
/** the user API key, not required for all requests */
136127
std::string m_api_key;
137128

@@ -214,7 +205,7 @@ namespace shogun
214205
const std::string& model, components_type components,
215206
parameters_type parameters)
216207
: m_name(name), m_description(description), m_class_name(model),
217-
m_parameters(parameters), m_components(components)
208+
m_parameters(std::move(parameters)), m_components(std::move(components))
218209
{
219210
}
220211

@@ -247,7 +238,7 @@ namespace shogun
247238
/**
248239
* Dumps the OpenMLFlow to disk.
249240
*/
250-
void dump();
241+
void dump() const;
251242

252243
/**
253244
* Gets a subflow, i.e. a kernel in a machine
@@ -266,17 +257,17 @@ namespace shogun
266257
}
267258

268259
#ifndef SWIG
269-
SG_FORCED_INLINE parameters_type get_parameters()
260+
SG_FORCED_INLINE parameters_type get_parameters() const noexcept
270261
{
271262
return m_parameters;
272263
}
273264

274-
SG_FORCED_INLINE components_type get_components()
265+
SG_FORCED_INLINE components_type get_components() const noexcept
275266
{
276267
return m_components;
277268
}
278269

279-
SG_FORCED_INLINE std::string get_class_name()
270+
SG_FORCED_INLINE std::string get_class_name() const noexcept
280271
{
281272
return m_class_name;
282273
}
@@ -320,7 +311,6 @@ namespace shogun
320311
param_descriptors,
321312
std::vector<std::unordered_map<std::string, std::string>>
322313
param_qualities)
323-
324314
: m_name(name), m_description(description),
325315
m_data_format(data_format), m_dataset_id(dataset_id),
326316
m_version(version), m_creator(creator),
@@ -441,8 +431,8 @@ namespace shogun
441431
std::shared_ptr<OpenMLData> data)
442432
: m_task_id(task_id), m_task_name(task_name),
443433
m_task_type(task_type), m_task_type_id(task_type_id),
444-
m_evaluation_measures(evaluation_measures), m_split(split),
445-
m_data(data)
434+
m_evaluation_measures(std::move(evaluation_measures)), m_split(std::move(split)),
435+
m_data(std::move(data))
446436
{
447437
}
448438

@@ -459,9 +449,9 @@ namespace shogun
459449
return m_split;
460450
}
461451

462-
SGMatrix<int32_t> get_train_indices();
452+
SGMatrix<int32_t> get_train_indices() const;
463453

464-
SGMatrix<int32_t> get_test_indices();
454+
SGMatrix<int32_t> get_test_indices() const;
465455

466456
#ifndef SWIG
467457
SG_FORCED_INLINE TaskType get_task_type() const noexcept
@@ -553,9 +543,9 @@ namespace shogun
553543
m_fold_evaluations(std::move(fold_evaluations)),
554544
m_sample_evaluations(std::move(sample_evaluations)),
555545
m_data_content(data_content),
556-
m_output_files(std::move(output_files)), m_task(task),
557-
m_flow(flow), m_run_id(run_id), m_model(model), m_tags(tags),
558-
m_predictions_url(predictions_url)
546+
m_output_files(std::move(output_files)), m_task(std::move(task)),
547+
m_flow(std::move(flow)), m_run_id(run_id), m_model(std::move(model)), m_tags(std::move(tags)),
548+
m_predictions_url(std::move(predictions_url))
559549
{
560550
}
561551

0 commit comments

Comments
 (0)