From 2dd3e030776182011aff56a344bfa311e420e964 Mon Sep 17 00:00:00 2001 From: Byron Xu Date: Thu, 30 Jun 2022 08:32:17 -0500 Subject: [PATCH] feat: Port over updated clang-format script from the reinforcement_learning repo (#3992) * Updated clang-format.sh script and run formatting. Changed header include order for vw_string_view_fmt.h to fix compile error. * Undo clang-format on CSharp binding files due to compile errors Co-authored-by: Jack Gerrits --- .clang-format | 4 + .github/workflows/lint.yml | 2 +- bindings/c/src/placeholder.cc | 1 + bindings/c/test/placeholder_test.cc | 4 +- java/src/main/c++/jni_base_learner.h | 6 +- java/src/main/c++/jni_spark_cluster.cc | 18 +- java/src/main/c++/jni_spark_vw.h | 12 +- java/src/main/c++/jni_spark_vw_generated.h | 88 +++---- java/src/main/c++/util.cc | 3 +- java/src/main/c++/util.h | 9 +- java/src/main/c++/vowpalWabbit_VW.cc | 2 +- java/src/main/c++/vowpalWabbit_VW.h | 23 +- ...wpalWabbit_learner_VWActionProbsLearner.cc | 6 +- ...owpalWabbit_learner_VWActionProbsLearner.h | 38 +-- ...palWabbit_learner_VWActionScoresLearner.cc | 6 +- ...wpalWabbit_learner_VWActionScoresLearner.h | 38 +-- .../c++/vowpalWabbit_learner_VWCCBLearner.cc | 6 +- .../c++/vowpalWabbit_learner_VWCCBLearner.h | 4 +- .../c++/vowpalWabbit_learner_VWLearners.h | 91 ++++---- ...owpalWabbit_learner_VWMulticlassLearner.cc | 6 +- ...vowpalWabbit_learner_VWMulticlassLearner.h | 38 +-- ...wpalWabbit_learner_VWMultilabelsLearner.cc | 8 +- ...owpalWabbit_learner_VWMultilabelsLearner.h | 38 +-- .../c++/vowpalWabbit_learner_VWProbLearner.cc | 6 +- .../c++/vowpalWabbit_learner_VWProbLearner.h | 37 ++- .../vowpalWabbit_learner_VWScalarLearner.cc | 6 +- .../vowpalWabbit_learner_VWScalarLearner.h | 38 +-- .../vowpalWabbit_learner_VWScalarsLearner.cc | 8 +- .../vowpalWabbit_learner_VWScalarsLearner.h | 38 +-- library/library_example.cc | 12 +- library/libsearch.h | 55 +++-- library/recommend.cc | 14 +- library/search_generate.cc | 221 ++++++++++-------- library/test_search.cc | 36 +-- test/benchmarks/benchmarks_common.h | 2 +- test/benchmarks/standalone/rcv1_benchmarks.cc | 5 +- test/tools/fuzzing/main.cc | 5 +- test/tools/parser_throughput/main.cc | 10 +- test/unit_test/automl_test.cc | 6 +- test/unit_test/cats_user_provided_pdf.cc | 5 +- test/unit_test/cb_explore_adf_test.cc | 3 +- test/unit_test/custom_reduction_test.cc | 2 +- test/unit_test/dsjson_parser_test.cc | 20 +- test/unit_test/error_test.cc | 3 +- test/unit_test/example_header_test.cc | 9 +- test/unit_test/guard_test.cc | 1 - test/unit_test/minimal_custom_reduction.cc | 2 +- test/unit_test/pmf_to_pdf_test.cc | 8 +- test/unit_test/power_test.cc | 3 +- test/unit_test/slates_test.cc | 10 +- test/unit_test/stable_unique_test.cc | 8 +- test/unit_test/test_common.cc | 8 +- test/unit_test/test_common.h | 16 +- test/unit_test/tokenize_test.cc | 90 ++++--- test/unit_test/tutorial_test.cc | 8 +- utl/clang-format | 34 --- utl/clang-format.sh | 49 ++++ .../core/include/vw/core/cost_sensitive.h | 4 +- .../core/include/vw/core/parse_example_json.h | 8 +- .../vw/core/parse_slates_example_json.h | 4 +- .../core/include/vw/core/vw_string_view_fmt.h | 2 + vowpalwabbit/core/src/decision_scores.cc | 4 +- vowpalwabbit/core/src/multilabel.cc | 3 +- vowpalwabbit/core/src/no_label.cc | 3 +- vowpalwabbit/core/src/parse_args.cc | 5 +- vowpalwabbit/core/src/simple_label.cc | 3 +- vowpalwabbit/core/src/simple_label_parser.cc | 2 +- .../vw/fb_parser/parse_example_flatbuffer.h | 3 +- 68 files changed, 652 insertions(+), 618 deletions(-) delete mode 100755 utl/clang-format create mode 100755 utl/clang-format.sh diff --git a/.clang-format b/.clang-format index 50f633ac629..dae136c02f6 100644 --- a/.clang-format +++ b/.clang-format @@ -15,6 +15,10 @@ IndentPPDirectives: AfterHash PointerAlignment: Left DerivePointerAlignment: false IncludeCategories: + # vw_string_format.h has a template specialization for fmt.h + # and it must be included first to prevent compile errors + - Regex: '"vw\/core\/vw_string_view_fmt\.h"' + Priority: 0 # First block is local directory includes - Regex: '"[[:alnum:]._\/]+"' Priority: 1 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2358fac7442..68599a8033f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -97,7 +97,7 @@ jobs: clang-format --version - name: Check code formatting for codebase shell: bash - run: ./utl/clang-format check + run: ./utl/clang-format.sh check env: GH_WORKFLOW_LOGGING: true - name: Check code formatting for diff diff --git a/bindings/c/src/placeholder.cc b/bindings/c/src/placeholder.cc index 4ee28b40f5f..3b4017de066 100644 --- a/bindings/c/src/placeholder.cc +++ b/bindings/c/src/placeholder.cc @@ -3,4 +3,5 @@ // license as described in the file LICENSE. #include "vw/experimental/placeholder.h" + #include "vw/experimental/workspace.h" diff --git a/bindings/c/test/placeholder_test.cc b/bindings/c/test/placeholder_test.cc index 5c463b09462..5a3db181c06 100644 --- a/bindings/c/test/placeholder_test.cc +++ b/bindings/c/test/placeholder_test.cc @@ -1,5 +1,5 @@ -#include - #include "vw/experimental/placeholder.h" +#include + BOOST_AUTO_TEST_CASE(placeholder_test) {} \ No newline at end of file diff --git a/java/src/main/c++/jni_base_learner.h b/java/src/main/c++/jni_base_learner.h index b0817bd780b..27cabaaa52d 100644 --- a/java/src/main/c++/jni_base_learner.h +++ b/java/src/main/c++/jni_base_learner.h @@ -28,8 +28,7 @@ T base_predict(JNIEnv* env, example* ex, bool learn, VW::workspace* vwInstance, else vwInstance->predict(*ex); - if (predict) - result = predictor(ex, env); + if (predict) result = predictor(ex, env); vwInstance->finish_example(*ex); } @@ -60,8 +59,7 @@ T base_predict(JNIEnv* env, jobjectArray example_strings, jboolean learn, jlong jstring example_string = (jstring)(env->GetObjectArrayElement(example_strings, i)); example* ex = read_example(env, example_string, vwInstance); ex_coll.push_back(ex); - if (i == 0) - first_example = ex; + if (i == 0) first_example = ex; } env->DeleteLocalRef(example_strings); diff --git a/java/src/main/c++/jni_spark_cluster.cc b/java/src/main/c++/jni_spark_cluster.cc index f442a520b97..f0a6ef4a7bb 100644 --- a/java/src/main/c++/jni_spark_cluster.cc +++ b/java/src/main/c++/jni_spark_cluster.cc @@ -3,7 +3,7 @@ #include "vw/spanning_tree/spanning_tree.h" JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_create( - JNIEnv *env, jclass, jint port, jboolean quiet) + JNIEnv* env, jclass, jint port, jboolean quiet) { try { @@ -16,9 +16,9 @@ JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_create( } } -JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_delete(JNIEnv *env, jobject clusterObj) +JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_delete(JNIEnv* env, jobject clusterObj) { - auto tree = (VW::SpanningTree *)get_native_pointer(env, clusterObj); + auto tree = (VW::SpanningTree*)get_native_pointer(env, clusterObj); try { @@ -30,9 +30,9 @@ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_delete(JN } } -JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_start(JNIEnv *env, jobject clusterObj) +JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_start(JNIEnv* env, jobject clusterObj) { - auto tree = (VW::SpanningTree *)get_native_pointer(env, clusterObj); + auto tree = (VW::SpanningTree*)get_native_pointer(env, clusterObj); try { @@ -44,9 +44,9 @@ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_start(JNI } } -JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_stop(JNIEnv *env, jobject clusterObj) +JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_stop(JNIEnv* env, jobject clusterObj) { - auto tree = (VW::SpanningTree *)get_native_pointer(env, clusterObj); + auto tree = (VW::SpanningTree*)get_native_pointer(env, clusterObj); try { @@ -58,9 +58,9 @@ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_stop(JNIE } } -JNIEXPORT jint JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_getPort(JNIEnv *env, jobject clusterObj) +JNIEXPORT jint JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_getPort(JNIEnv* env, jobject clusterObj) { - auto tree = (VW::SpanningTree *)get_native_pointer(env, clusterObj); + auto tree = (VW::SpanningTree*)get_native_pointer(env, clusterObj); try { diff --git a/java/src/main/c++/jni_spark_vw.h b/java/src/main/c++/jni_spark_vw.h index 7120781d90d..b5f9a214f55 100644 --- a/java/src/main/c++/jni_spark_vw.h +++ b/java/src/main/c++/jni_spark_vw.h @@ -10,7 +10,7 @@ class StringGuard jstring _source; const char* _cstr; - public: +public: StringGuard(JNIEnv* env, jstring source); ~StringGuard(); @@ -24,7 +24,7 @@ class CriticalArrayGuard jarray _arr; void* _arr0; - public: +public: CriticalArrayGuard(JNIEnv* env, jarray arr); ~CriticalArrayGuard(); @@ -34,9 +34,9 @@ class CriticalArrayGuard // bind VW instance and example together to reduce the number of variables passed around class VowpalWabbitExampleWrapper { - public: - VW::workspace* _all; - example* _example; +public: + VW::workspace* _all; + example* _example; - VowpalWabbitExampleWrapper(VW::workspace* all, example* example) : _all(all), _example(example) {} + VowpalWabbitExampleWrapper(VW::workspace* all, example* example) : _all(all), _example(example) {} }; \ No newline at end of file diff --git a/java/src/main/c++/jni_spark_vw_generated.h b/java/src/main/c++/jni_spark_vw_generated.h index 38b8c52abbe..cc541fdc2bd 100644 --- a/java/src/main/c++/jni_spark_vw_generated.h +++ b/java/src/main/c++/jni_spark_vw_generated.h @@ -3,17 +3,17 @@ /* Header for class org_vowpalwabbit_spark_VowpalWabbitNative */ #ifndef _Included_org_vowpalwabbit_spark_VowpalWabbitNative -#define _Included_org_vowpalwabbit_spark_VowpalWabbitNative -#ifdef __cplusplus +# define _Included_org_vowpalwabbit_spark_VowpalWabbitNative +# ifdef __cplusplus extern "C" { -#endif +# endif /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: initialize * Signature: (Ljava/lang/String;)J */ - JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_initialize(JNIEnv *, jclass, jstring); + JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_initialize(JNIEnv*, jclass, jstring); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative @@ -21,42 +21,42 @@ extern "C" * Signature: (Ljava/lang/String;[B)J */ JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_initializeFromModel( - JNIEnv *, jclass, jstring, jbyteArray); + JNIEnv*, jclass, jstring, jbyteArray); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: learn * Signature: ([)J */ - JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_learn(JNIEnv *, jobject, jobjectArray); + JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_learn(JNIEnv*, jobject, jobjectArray); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: predict * Signature: ([])J */ - JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_predict(JNIEnv *, jobject, jobjectArray); + JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_predict(JNIEnv*, jobject, jobjectArray); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: performRemainingPasses * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_performRemainingPasses(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_performRemainingPasses(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: getModel * Signature: ()[B */ - JNIEXPORT jbyteArray JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getModel(JNIEnv *, jobject); + JNIEXPORT jbyteArray JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getModel(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: getArguments * Signature: ()Lorg/vowpalwabbit/spark/VowpalWabbitArguments; */ - JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getArguments(JNIEnv *, jobject); + JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getArguments(JNIEnv*, jobject); JNIEXPORT jstring JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getOutputPredictionType(JNIEnv*, jobject); @@ -65,21 +65,21 @@ extern "C" * Method: getPerformanceStatistic * Signature: ()Lorg/vowpalwabbit/bare/VowpalWabbitPerformanceStatistics; */ - JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getPerformanceStatistics(JNIEnv *, jobject); + JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_getPerformanceStatistics(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: endPass * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_endPass(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_endPass(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative * Method: finish * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_finish(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_finish(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitNative @@ -87,42 +87,42 @@ extern "C" * Signature: ([BIII)I */ JNIEXPORT jint JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitNative_hash( - JNIEnv *, jclass, jbyteArray, jint, jint, jint); + JNIEnv*, jclass, jbyteArray, jint, jint, jint); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif /* Header for class org_vowpalwabbit_spark_VowpalWabbitExample */ #ifndef _Included_org_vowpalwabbit_spark_VowpalWabbitExample -#define _Included_org_vowpalwabbit_spark_VowpalWabbitExample -#ifdef __cplusplus +# define _Included_org_vowpalwabbit_spark_VowpalWabbitExample +# ifdef __cplusplus extern "C" { -#endif +# endif /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: initialize * Signature: (JZ)J */ - JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_initialize(JNIEnv *, jclass, jlong, jboolean); + JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_initialize(JNIEnv*, jclass, jlong, jboolean); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: finish * Signature: ()J */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_finish(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_finish(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: clear * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_clear(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_clear(JNIEnv*, jobject); - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setDefaultLabel(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setDefaultLabel(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample @@ -130,7 +130,7 @@ extern "C" * Signature: (CI[D)V */ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_addToNamespaceDense( - JNIEnv *, jobject, jchar, jint, jdoubleArray); + JNIEnv*, jobject, jchar, jint, jdoubleArray); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample @@ -138,14 +138,14 @@ extern "C" * Signature: (C[I[D)V */ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_addToNamespaceSparse( - JNIEnv *, jobject, jchar, jintArray, jdoubleArray); + JNIEnv*, jobject, jchar, jintArray, jdoubleArray); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: setLabel * Signature: (FF)V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setLabel(JNIEnv *, jobject, jfloat, jfloat); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setLabel(JNIEnv*, jobject, jfloat, jfloat); JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setMulticlassLabel( JNIEnv*, jobject, jfloat, jint); @@ -159,9 +159,9 @@ extern "C" JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setMultiLabels(JNIEnv*, jobject, jintArray); JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setContextualBanditLabel( - JNIEnv *, jobject, jint, jdouble, jdouble); + JNIEnv*, jobject, jint, jdouble, jdouble); - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setSharedLabel(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setSharedLabel(JNIEnv*, jobject); JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setSlatesSharedLabel(JNIEnv*, jobject, jfloat); @@ -175,77 +175,77 @@ extern "C" * Method: learn * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_learn(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_learn(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: getPrediction * Signature: ()Ljava/lang/Object; */ - JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_getPrediction(JNIEnv *, jobject); + JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_getPrediction(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: toString * Signature: ()Ljava/lang/String; */ - JNIEXPORT jstring JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_toString(JNIEnv *, jobject); + JNIEXPORT jstring JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_toString(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_VowpalWabbitExample * Method: predict * Signature: ()Ljava/lang/Object; */ - JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_predict(JNIEnv *, jobject); + JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_predict(JNIEnv*, jobject); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif /* Header for class org_vowpalwabbit_spark_ClusterSpanningTree */ #ifndef _Included_org_vowpalwabbit_spark_ClusterSpanningTree -#define _Included_org_vowpalwabbit_spark_ClusterSpanningTree -#ifdef __cplusplus +# define _Included_org_vowpalwabbit_spark_ClusterSpanningTree +# ifdef __cplusplus extern "C" { -#endif +# endif /* * Class: org_vowpalwabbit_spark_ClusterSpanningTree * Method: create * Signature: (IZ)J */ - JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_create(JNIEnv *, jclass, jint, jboolean); + JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_create(JNIEnv*, jclass, jint, jboolean); /* * Class: org_vowpalwabbit_spark_ClusterSpanningTree * Method: delete * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_delete(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_delete(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_ClusterSpanningTree * Method: start * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_start(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_start(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_ClusterSpanningTree * Method: stop * Signature: ()V */ - JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_stop(JNIEnv *, jobject); + JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_stop(JNIEnv*, jobject); /* * Class: org_vowpalwabbit_spark_ClusterSpanningTree * Method: getPort * Signature: ()I */ - JNIEXPORT jint JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_getPort(JNIEnv *, jobject); + JNIEXPORT jint JNICALL Java_org_vowpalwabbit_spark_ClusterSpanningTree_getPort(JNIEnv*, jobject); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/util.cc b/java/src/main/c++/util.cc index 68ab97bcc88..10c340d092c 100644 --- a/java/src/main/c++/util.cc +++ b/java/src/main/c++/util.cc @@ -14,8 +14,7 @@ jlong get_native_pointer(JNIEnv* env, jobject obj) void throw_java_exception(JNIEnv* env, const char* name, const char* msg) { jclass jc = env->FindClass(name); - if (jc) - env->ThrowNew(jc, msg); + if (jc) env->ThrowNew(jc, msg); } void rethrow_cpp_exception_as_java_exception(JNIEnv* env) diff --git a/java/src/main/c++/util.h b/java/src/main/c++/util.h index 7db34f2c680..7a23e2ae944 100644 --- a/java/src/main/c++/util.h +++ b/java/src/main/c++/util.h @@ -2,11 +2,10 @@ // Java JNI exception check (if another JNI function is invoked it segfaults) #define CHECK_JNI_EXCEPTION(ret) \ - if (env->ExceptionCheck()) \ - return ret; + if (env->ExceptionCheck()) return ret; -jlong get_native_pointer(JNIEnv *env, jobject obj); +jlong get_native_pointer(JNIEnv* env, jobject obj); -void throw_java_exception(JNIEnv *env, const char *name, const char *msg); +void throw_java_exception(JNIEnv* env, const char* name, const char* msg); -void rethrow_cpp_exception_as_java_exception(JNIEnv *env); \ No newline at end of file +void rethrow_cpp_exception_as_java_exception(JNIEnv* env); \ No newline at end of file diff --git a/java/src/main/c++/vowpalWabbit_VW.cc b/java/src/main/c++/vowpalWabbit_VW.cc index 3158d8176b7..a14a35effae 100644 --- a/java/src/main/c++/vowpalWabbit_VW.cc +++ b/java/src/main/c++/vowpalWabbit_VW.cc @@ -2,7 +2,7 @@ #include "vw/core/vw.h" -JNIEXPORT jstring JNICALL Java_vowpalWabbit_VW_version(JNIEnv *env, jclass obj) +JNIEXPORT jstring JNICALL Java_vowpalWabbit_VW_version(JNIEnv* env, jclass obj) { return env->NewStringUTF(PACKAGE_VERSION); } \ No newline at end of file diff --git a/java/src/main/c++/vowpalWabbit_VW.h b/java/src/main/c++/vowpalWabbit_VW.h index 1035e024e79..3c110ddf8c2 100644 --- a/java/src/main/c++/vowpalWabbit_VW.h +++ b/java/src/main/c++/vowpalWabbit_VW.h @@ -3,20 +3,19 @@ /* Header for class vowpalWabbit_VW */ #ifndef _Included_vowpalWabbit_VW -#define _Included_vowpalWabbit_VW -#ifdef __cplusplus +# define _Included_vowpalWabbit_VW +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_VW - * Method: version - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_vowpalWabbit_VW_version -(JNIEnv *, jclass); +# endif + /* + * Class: vowpalWabbit_VW + * Method: version + * Signature: ()Ljava/lang/String; + */ + JNIEXPORT jstring JNICALL Java_vowpalWabbit_VW_version(JNIEnv*, jclass); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.cc index 3400aa55702..9b3c2a61520 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.cc @@ -3,7 +3,7 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jobject action_probs_prediction(example *vec, JNIEnv *env) +jobject action_probs_prediction(example* vec, JNIEnv* env) { jclass action_prob_class = env->FindClass("vowpalWabbit/responses/ActionProb"); jmethodID action_prob_constructor = env->GetMethodID(action_prob_class, "", "(IF)V"); @@ -28,13 +28,13 @@ jobject action_probs_prediction(example *vec, JNIEnv *env) } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionProbsLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, action_probs_prediction); } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionProbsLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, action_probs_prediction); } diff --git a/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.h index 8db1c1fb522..81f2800f87b 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWActionProbsLearner.h @@ -3,28 +3,28 @@ /* Header for class vowpalWabbit_learner_VWActionProbsLearner */ #ifndef _Included_vowpalWabbit_learner_VWActionProbsLearner -#define _Included_vowpalWabbit_learner_VWActionProbsLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWActionProbsLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWActionProbsLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionProbs; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionProbsLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWActionProbsLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionProbs; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionProbsLearner_predict( + JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWActionProbsLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionProbs; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionProbsLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWActionProbsLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionProbs; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionProbsLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.cc index be15fb191e6..0d4b69c13d8 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.cc @@ -3,7 +3,7 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jobject action_scores_prediction(example *vec, JNIEnv *env) +jobject action_scores_prediction(example* vec, JNIEnv* env) { jclass action_score_class = env->FindClass("vowpalWabbit/responses/ActionScore"); jmethodID action_score_constructor = env->GetMethodID(action_score_class, "", "(IF)V"); @@ -25,13 +25,13 @@ jobject action_scores_prediction(example *vec, JNIEnv *env) } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionScoresLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, action_scores_prediction); } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionScoresLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, action_scores_prediction); } diff --git a/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.h index 24263a0e92d..61db5ebd459 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWActionScoresLearner.h @@ -3,28 +3,28 @@ /* Header for class vowpalWabbit_learner_VWActionScoresLearner */ #ifndef _Included_vowpalWabbit_learner_VWActionScoresLearner -#define _Included_vowpalWabbit_learner_VWActionScoresLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWActionScoresLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWActionScoresLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionScores; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionScoresLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWActionScoresLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionScores; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionScoresLearner_predict( + JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWActionScoresLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionScores; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionScoresLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWActionScoresLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/ActionScores; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWActionScoresLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.cc index 95981d1ee35..d507964d8e0 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.cc @@ -3,7 +3,7 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jobject decision_scores_prediction(example *vec, JNIEnv *env) +jobject decision_scores_prediction(example* vec, JNIEnv* env) { jclass action_score_class = env->FindClass("vowpalWabbit/responses/ActionScore"); jmethodID action_score_constructor = env->GetMethodID(action_score_class, "", "(IF)V"); @@ -37,13 +37,13 @@ jobject decision_scores_prediction(example *vec, JNIEnv *env) } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWCCBLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, decision_scores_prediction); } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWCCBLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, decision_scores_prediction); } diff --git a/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.h index 0b586346b46..115b4e133d9 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWCCBLearner.h @@ -13,7 +13,7 @@ extern "C" * Method: predict * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/DecisionScores; */ - JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWCCBLearner_predict(JNIEnv *, jobject, jstring, jboolean, jlong); + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWCCBLearner_predict(JNIEnv*, jobject, jstring, jboolean, jlong); /* * Class: vowpalWabbit_learner_VWCCBLearner @@ -21,7 +21,7 @@ extern "C" * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/DecisionScores; */ JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWCCBLearner_predictMultiline( - JNIEnv *, jobject, jobjectArray, jboolean, jlong); + JNIEnv*, jobject, jobjectArray, jboolean, jlong); # ifdef __cplusplus } diff --git a/java/src/main/c++/vowpalWabbit_learner_VWLearners.h b/java/src/main/c++/vowpalWabbit_learner_VWLearners.h index de1e4f5f9d4..03de761a1bf 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWLearners.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWLearners.h @@ -3,62 +3,59 @@ /* Header for class vowpalWabbit_learner_VWLearners */ #ifndef _Included_vowpalWabbit_learner_VWLearners -#define _Included_vowpalWabbit_learner_VWLearners -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWLearners - * Method: initialize - * Signature: (Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_vowpalWabbit_learner_VWLearners_initialize - (JNIEnv *, jclass, jstring); +# define _Included_vowpalWabbit_learner_VWLearners +# ifdef __cplusplus +extern "C" +{ +# endif + /* + * Class: vowpalWabbit_learner_VWLearners + * Method: initialize + * Signature: (Ljava/lang/String;)J + */ + JNIEXPORT jlong JNICALL Java_vowpalWabbit_learner_VWLearners_initialize(JNIEnv*, jclass, jstring); -/* - * Class: vowpalWabbit_learner_VWLearners - * Method: getReturnType - * Signature: (J)LvowpalWabbit/learner/VWLearners/VWReturnType; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWLearners_getReturnType - (JNIEnv *, jclass, jlong); + /* + * Class: vowpalWabbit_learner_VWLearners + * Method: getReturnType + * Signature: (J)LvowpalWabbit/learner/VWLearners/VWReturnType; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWLearners_getReturnType(JNIEnv*, jclass, jlong); -/* - * Class: vowpalWabbit_learner_VWLearners - * Method: closeInstance - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_vowpalWabbit_learner_VWLearners_closeInstance - (JNIEnv *, jclass, jlong); + /* + * Class: vowpalWabbit_learner_VWLearners + * Method: closeInstance + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_vowpalWabbit_learner_VWLearners_closeInstance(JNIEnv*, jclass, jlong); -/* - * Class: vowpalWabbit_learner_VWLearners - * Method: performRemainingPasses - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_vowpalWabbit_learner_VWLearners_performRemainingPasses - (JNIEnv *, jclass, jlong); + /* + * Class: vowpalWabbit_learner_VWLearners + * Method: performRemainingPasses + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_vowpalWabbit_learner_VWLearners_performRemainingPasses(JNIEnv*, jclass, jlong); -/* - * Class: vowpalWabbit_learner_VWLearners - * Method: saveModel - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_vowpalWabbit_learner_VWLearners_saveModel - (JNIEnv *, jclass, jlong, jstring); + /* + * Class: vowpalWabbit_learner_VWLearners + * Method: saveModel + * Signature: (JLjava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_vowpalWabbit_learner_VWLearners_saveModel(JNIEnv*, jclass, jlong, jstring); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif /* Header for class vowpalWabbit_learner_VWLearners_VWReturnType */ #ifndef _Included_vowpalWabbit_learner_VWLearners_VWReturnType -#define _Included_vowpalWabbit_learner_VWLearners_VWReturnType -#ifdef __cplusplus -extern "C" { -#endif -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWLearners_VWReturnType +# ifdef __cplusplus +extern "C" +{ +# endif +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.cc index 4b0669f27e1..745af736a86 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.cc @@ -3,16 +3,16 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jint multiclass_predictor(example *vec, JNIEnv *env) { return vec->pred.multiclass; } +jint multiclass_predictor(example* vec, JNIEnv* env) { return vec->pred.multiclass; } JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, multiclass_predictor); } JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, multiclass_predictor); } \ No newline at end of file diff --git a/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.h index 05204d53e91..d100e3fcc1c 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.h @@ -3,28 +3,28 @@ /* Header for class vowpalWabbit_learner_VWMulticlassLearner */ #ifndef _Included_vowpalWabbit_learner_VWMulticlassLearner -#define _Included_vowpalWabbit_learner_VWMulticlassLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWMulticlassLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWMulticlassLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)I - */ -JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWMulticlassLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)I + */ + JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predict( + JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWMulticlassLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)I - */ -JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWMulticlassLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)I + */ + JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.cc index 91b180907c0..16d89aba10b 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.cc @@ -3,12 +3,12 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jobject multilabel_predictor(example *vec, JNIEnv *env) +jobject multilabel_predictor(example* vec, JNIEnv* env) { auto& labels = vec->pred.multilabels.label_v; size_t num_values = labels.size(); jintArray j_labels = env->NewIntArray(num_values); - env->SetIntArrayRegion(j_labels, 0, num_values, (int *)labels.begin()); + env->SetIntArrayRegion(j_labels, 0, num_values, (int*)labels.begin()); jclass clazz = env->FindClass("vowpalWabbit/responses/Multilabels"); jmethodID constructor = env->GetMethodID(clazz, "", "([I)V"); @@ -16,13 +16,13 @@ jobject multilabel_predictor(example *vec, JNIEnv *env) } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWMultilabelsLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, multilabel_predictor); } JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWMultilabelsLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, multilabel_predictor); } diff --git a/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.h index 365394e0e15..e9714d4b526 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWMultilabelsLearner.h @@ -3,28 +3,28 @@ /* Header for class vowpalWabbit_learner_VWMultilabelsLearner */ #ifndef _Included_vowpalWabbit_learner_VWMultilabelsLearner -#define _Included_vowpalWabbit_learner_VWMultilabelsLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWMultilabelsLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWMultilabelsLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/Multilabels; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWMultilabelsLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWMultilabelsLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)LvowpalWabbit/responses/Multilabels; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWMultilabelsLearner_predict( + JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWMultilabelsLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/Multilabels; - */ -JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWMultilabelsLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWMultilabelsLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)LvowpalWabbit/responses/Multilabels; + */ + JNIEXPORT jobject JNICALL Java_vowpalWabbit_learner_VWMultilabelsLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.cc index e521861b319..18e76dc5275 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.cc @@ -3,16 +3,16 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jfloat prob_predictor(example *vec, JNIEnv *env) { return vec->pred.prob; } +jfloat prob_predictor(example* vec, JNIEnv* env) { return vec->pred.prob; } JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWProbLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, prob_predictor); } JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWProbLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, prob_predictor); } \ No newline at end of file diff --git a/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.h index e74d507fd3a..c1c3efe59ca 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWProbLearner.h @@ -3,28 +3,27 @@ /* Header for class vowpalWabbit_learner_VWProbLearner */ #ifndef _Included_vowpalWabbit_learner_VWProbLearner -#define _Included_vowpalWabbit_learner_VWProbLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWProbLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWProbLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)F - */ -JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWProbLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWProbLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)F + */ + JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWProbLearner_predict(JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWProbLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)F - */ -JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWProbLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWProbLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)F + */ + JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWProbLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.cc index 91ce9648a19..bc5c17112a9 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.cc @@ -3,16 +3,16 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jfloat scalar_predictor(example *vec, JNIEnv *env) { return vec->pred.scalar; } +jfloat scalar_predictor(example* vec, JNIEnv* env) { return vec->pred.scalar; } JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWScalarLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, scalar_predictor); } JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWScalarLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, scalar_predictor); } \ No newline at end of file diff --git a/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.h index cac82662760..3de617ac25c 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWScalarLearner.h @@ -3,28 +3,28 @@ /* Header for class vowpalWabbit_learner_VWScalarLearner */ #ifndef _Included_vowpalWabbit_learner_VWScalarLearner -#define _Included_vowpalWabbit_learner_VWScalarLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWScalarLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWScalarLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)F - */ -JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWScalarLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWScalarLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)F + */ + JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWScalarLearner_predict( + JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWScalarLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)F - */ -JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWScalarLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWScalarLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)F + */ + JNIEXPORT jfloat JNICALL Java_vowpalWabbit_learner_VWScalarLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.cc b/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.cc index 734063f2b90..da51f07df16 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.cc +++ b/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.cc @@ -3,23 +3,23 @@ #include "jni_base_learner.h" #include "vw/core/vw.h" -jfloatArray scalars_predictor(example *vec, JNIEnv *env) +jfloatArray scalars_predictor(example* vec, JNIEnv* env) { auto& scalars = vec->pred.scalars; size_t num_values = scalars.size(); jfloatArray r = env->NewFloatArray(num_values); - env->SetFloatArrayRegion(r, 0, num_values, (float *)scalars.begin()); + env->SetFloatArrayRegion(r, 0, num_values, (float*)scalars.begin()); return r; } JNIEXPORT jfloatArray JNICALL Java_vowpalWabbit_learner_VWScalarsLearner_predict( - JNIEnv *env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jstring example_string, jboolean learn, jlong vwPtr) { return base_predict(env, example_string, learn, vwPtr, scalars_predictor); } JNIEXPORT jfloatArray JNICALL Java_vowpalWabbit_learner_VWScalarsLearner_predictMultiline( - JNIEnv *env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) + JNIEnv* env, jobject obj, jobjectArray example_strings, jboolean learn, jlong vwPtr) { return base_predict(env, example_strings, learn, vwPtr, scalars_predictor); } diff --git a/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.h b/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.h index 461bd946740..e893518968e 100644 --- a/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.h +++ b/java/src/main/c++/vowpalWabbit_learner_VWScalarsLearner.h @@ -3,28 +3,28 @@ /* Header for class vowpalWabbit_learner_VWScalarsLearner */ #ifndef _Included_vowpalWabbit_learner_VWScalarsLearner -#define _Included_vowpalWabbit_learner_VWScalarsLearner -#ifdef __cplusplus +# define _Included_vowpalWabbit_learner_VWScalarsLearner +# ifdef __cplusplus extern "C" { -#endif -/* - * Class: vowpalWabbit_learner_VWScalarsLearner - * Method: predict - * Signature: (Ljava/lang/String;ZJ)[F - */ -JNIEXPORT jfloatArray JNICALL Java_vowpalWabbit_learner_VWScalarsLearner_predict -(JNIEnv *, jobject, jstring, jboolean, jlong); +# endif + /* + * Class: vowpalWabbit_learner_VWScalarsLearner + * Method: predict + * Signature: (Ljava/lang/String;ZJ)[F + */ + JNIEXPORT jfloatArray JNICALL Java_vowpalWabbit_learner_VWScalarsLearner_predict( + JNIEnv*, jobject, jstring, jboolean, jlong); -/* - * Class: vowpalWabbit_learner_VWScalarsLearner - * Method: predictMultiline - * Signature: ([Ljava/lang/String;ZJ)[F - */ -JNIEXPORT jfloatArray JNICALL Java_vowpalWabbit_learner_VWScalarsLearner_predictMultiline -(JNIEnv *, jobject, jobjectArray, jboolean, jlong); + /* + * Class: vowpalWabbit_learner_VWScalarsLearner + * Method: predictMultiline + * Signature: ([Ljava/lang/String;ZJ)[F + */ + JNIEXPORT jfloatArray JNICALL Java_vowpalWabbit_learner_VWScalarsLearner_predictMultiline( + JNIEnv*, jobject, jobjectArray, jboolean, jlong); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/library/library_example.cc b/library/library_example.cc index 5f6adb0583f..d1a16341921 100644 --- a/library/library_example.cc +++ b/library/library_example.cc @@ -4,12 +4,13 @@ #include inline feature vw_feature_from_string(VW::workspace& v, const std::string& fstr, unsigned long seed, float val) -{ auto foo = VW::hash_feature(v, fstr, seed); - feature f = { val, foo}; +{ + auto foo = VW::hash_feature(v, fstr, seed); + feature f = {val, foo}; return f; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { VW::workspace* model = VW::initialize("--hash all -q st --noconstant -f train2.vw --no_stdin"); @@ -50,10 +51,11 @@ int main(int argc, char *argv[]) model2->learn(*vec2); std::cerr << "p4 = " << vec2->pred.scalar << std::endl; - size_t len=0; + size_t len = 0; VW::primitive_feature_space* pfs = VW::export_example(*model2, vec2, len); for (size_t i = 0; i < len; i++) - { std::cout << "namespace = " << pfs[i].name; + { + std::cout << "namespace = " << pfs[i].name; for (size_t j = 0; j < pfs[i].len; j++) { std::cout << " " << pfs[i].fs[j].weight_index << ":" << pfs[i].fs[j].x << ":" diff --git a/library/libsearch.h b/library/libsearch.h index 08f10bf4d76..d21af16da2f 100644 --- a/library/libsearch.h +++ b/library/libsearch.h @@ -4,7 +4,7 @@ individual contributors. All rights reserved. Released under a BSD license as described in the file LICENSE. */ #ifndef LIBSEARCH_HOOKTASK_H -#define LIBSEARCH_HOOKTASK_H +# define LIBSEARCH_HOOKTASK_H # include "vw/core/parse_example.h" # include "vw/core/parser.h" @@ -33,16 +33,25 @@ class SearchTask d->run_object = std::shared_ptr>(this); } virtual ~SearchTask() - { trigger.clear(); // the individual examples get cleaned up below + { + trigger.clear(); // the individual examples get cleaned up below VW::dealloc_examples(bogus_example, 1); } - virtual void _run(Search::search&sch, INPUT& input_example, OUTPUT& output) {} // YOU MUST DEFINE THIS FUNCTION! - void _setup(Search::search&sch, INPUT& input_example, OUTPUT& output) {} // OPTIONAL - void _takedown(Search::search&sch, INPUT& input_example, OUTPUT& output) {} // OPTIONAL + virtual void _run(Search::search& sch, INPUT& input_example, OUTPUT& output) {} // YOU MUST DEFINE THIS FUNCTION! + void _setup(Search::search& sch, INPUT& input_example, OUTPUT& output) {} // OPTIONAL + void _takedown(Search::search& sch, INPUT& input_example, OUTPUT& output) {} // OPTIONAL - void learn(INPUT& input_example, OUTPUT& output) { bogus_example->test_only = false; call_vw(input_example, output); } - void predict(INPUT& input_example, OUTPUT& output) { bogus_example->test_only = true; call_vw(input_example, output); } + void learn(INPUT& input_example, OUTPUT& output) + { + bogus_example->test_only = false; + call_vw(input_example, output); + } + void predict(INPUT& input_example, OUTPUT& output) + { + bogus_example->test_only = true; + call_vw(input_example, output); + } protected: VW::workspace& vw_obj; @@ -58,25 +67,28 @@ class SearchTask { _input = input_example; _output = output; - vw_obj.learn(trigger); // this will cause our search_run_fn hook to get called + vw_obj.learn(trigger); // this will cause our search_run_fn hook to get called } - static void _search_run_fn(Search::search&sch) - { HookTask::task_data* d = sch.get_task_data(); + static void _search_run_fn(Search::search& sch) + { + HookTask::task_data* d = sch.get_task_data(); if (d->run_object == nullptr) { THROW("error: calling _search_run_fn without setting run object"); } auto* run_obj = static_cast*>(d->run_object.get()); run_obj->_run(sch, run_obj->_input, run_obj->_output); } - static void _search_setup_fn(Search::search&sch) - { HookTask::task_data* d = sch.get_task_data(); + static void _search_setup_fn(Search::search& sch) + { + HookTask::task_data* d = sch.get_task_data(); if (d->run_object == nullptr) { THROW("error: calling _search_setup_fn without setting run object"); } auto* run_obj = static_cast*>(d->run_object.get()); run_obj->_setup(sch, run_obj->_input, run_obj->_output); } - static void _search_takedown_fn(Search::search&sch) - { HookTask::task_data* d = sch.get_task_data(); + static void _search_takedown_fn(Search::search& sch) + { + HookTask::task_data* d = sch.get_task_data(); if (d->run_object == nullptr) { THROW("error: calling _search_takedown_fn without setting run object"); } auto* run_obj = static_cast*>(d->run_object.get()); run_obj->_takedown(sch, run_obj->_input, run_obj->_output); @@ -88,17 +100,21 @@ class BuiltInTask : public SearchTask> public: BuiltInTask(VW::workspace& vw_obj, Search::search_task* task) : SearchTask>(vw_obj) - { HookTask::task_data* d = sch.get_task_data(); + { + HookTask::task_data* d = sch.get_task_data(); size_t num_actions = d->num_actions; my_task = task; - if (my_task->initialize) - my_task->initialize(sch, num_actions, *d->arg); + if (my_task->initialize) my_task->initialize(sch, num_actions, *d->arg); } - ~BuiltInTask() { if (my_task->finish) my_task->finish(sch); } + ~BuiltInTask() + { + if (my_task->finish) my_task->finish(sch); + } void _run(Search::search& sch, VW::multi_ex& input_example, std::vector& output) - { my_task->run(sch, input_example); + { + my_task->run(sch, input_example); sch.get_test_action_sequence(output); } @@ -106,5 +122,4 @@ class BuiltInTask : public SearchTask> Search::search_task* my_task; }; - #endif diff --git a/library/recommend.cc b/library/recommend.cc index 414e70b66d2..8d2c4a7f37d 100644 --- a/library/recommend.cc +++ b/library/recommend.cc @@ -58,7 +58,7 @@ void get_hashv(char* in, size_t len, unsigned* out) char* bf_new(unsigned b) { - char* bf = (char* )calloc(1, byte_len(b)); + char* bf = (char*)calloc(1, byte_len(b)); return bf; } @@ -96,7 +96,7 @@ std::vector scored_examples; struct compare_scored_examples { - bool operator()(scored_example const &lhs, scored_example const &rhs) const { return lhs.first > rhs.first; } + bool operator()(scored_example const& lhs, scored_example const& rhs) const { return lhs.first > rhs.first; } }; std::priority_queue, compare_scored_examples> pr_queue; @@ -235,10 +235,7 @@ int main(int argc, char* argv[]) const std::string str(estr); - if (pr_queue.size() < (size_t)topk) - { - pr_queue.push(std::make_pair(ex->pred.scalar, str)); - } + if (pr_queue.size() < (size_t)topk) { pr_queue.push(std::make_pair(ex->pred.scalar, str)); } else if (pr_queue.top().first < ex->pred.scalar) { pr_queue.pop(); @@ -262,10 +259,7 @@ int main(int argc, char* argv[]) } } - if (verbose > 0) - { - progress(); - } + if (verbose > 0) { progress(); } VW::finish(*model); fclose(fI); diff --git a/library/search_generate.cc b/library/search_generate.cc index c66ccc03e2f..378599e9e28 100644 --- a/library/search_generate.cc +++ b/library/search_generate.cc @@ -12,9 +12,10 @@ using std::cerr; using std::endl; -size_t sed(const std::string &s1, const std::string &s2, size_t subst_cost=1, size_t ins_cost=1, size_t del_cost=1); +size_t sed( + const std::string& s1, const std::string& s2, size_t subst_cost = 1, size_t ins_cost = 1, size_t del_cost = 1); -action char2action(char c) // 1=EOS, 2=' ', 3..28=a..z, 29=other +action char2action(char c) // 1=EOS, 2=' ', 3..28=a..z, 29=other { if (c == '$') { return 1; } if (c == ' ') { return 2; } @@ -31,7 +32,8 @@ char action2char(action a) } struct nextstr -{ char c; +{ + char c; float cw; std::string s; float sw; @@ -51,37 +53,43 @@ class Trie } Trie* step(const char c) - { size_t id = char2action(c) - 1; + { + size_t id = char2action(c) - 1; if (children.size() <= id) { return nullptr; } return children[id]; } - void insert(const char*str, size_t c=1) - { if (str == nullptr || *str == 0) - { terminus += c; - count += c; + void insert(const char* str, size_t c = 1) + { + if (str == nullptr || *str == 0) + { + terminus += c; + count += c; } else - { count += c; + { + count += c; size_t id = char2action(*str) - 1; while (children.size() <= id) { children.push_back(nullptr); } if (children[id] == nullptr) { children[id] = new Trie(); } - children[id]->insert(str+1, c); + children[id]->insert(str + 1, c); } } - size_t contains(const char*str) + size_t contains(const char* str) { if (str == nullptr || *str == 0) { return terminus; } size_t id = char2action(*str) - 1; if (children.size() <= id) { return 0; } if (children[id] == nullptr) { return 0; } - return children[id]->contains(str+1); + return children[id]->contains(str + 1); } - void get_next(const char*prefix, std::vector& next) - { if (prefix == nullptr || *prefix == 0) - { next.clear(); + void get_next(const char* prefix, std::vector& next) + { + if (prefix == nullptr || *prefix == 0) + { + next.clear(); float c = 1.0f / (float)count; next.push_back(nextstr('$', std::log(1.0f + c * (float)terminus), max_string, std::log(1.0f + (float)max_count))); for (size_t id = 0; id < children.size(); id++) @@ -94,31 +102,36 @@ class Trie } } else - { size_t id = char2action(*prefix) - 1; + { + size_t id = char2action(*prefix) - 1; if (children.size() <= id) { return; } if (children[id] == nullptr) { return; } - children[id]->get_next(prefix+1, next); + children[id]->get_next(prefix + 1, next); } } void build_max(const std::string& prefix = "") - { max_count = terminus; + { + max_count = terminus; max_string = prefix; for (size_t id = 0; id < children.size(); id++) { if (children[id]) - { char c = action2char((action)(id + 1)); + { + char c = action2char((action)(id + 1)); children[id]->build_max(prefix + c); if (children[id]->max_count > max_count) - { max_count = children[id]->max_count; + { + max_count = children[id]->max_count; max_string = children[id]->max_string; } } } } - void print(char c='^', size_t indent=0) - { cerr << std::string(indent*2, ' '); + void print(char c = '^', size_t indent = 0) + { + cerr << std::string(indent * 2, ' '); cerr << '\'' << c << "' " << count << " [max_string=" << max_string << " max_count=" << max_count << "]" << endl; for (size_t i = 0; i < children.size(); i++) { @@ -127,20 +140,26 @@ class Trie } private: - size_t terminus; // count of words that end here? - size_t count; // count of all words under here (including us) - size_t max_count; // count of most frequent word under here - std::string max_string; // the corresponding std::string + size_t terminus; // count of words that end here? + size_t count; // count of all words under here (including us) + size_t max_count; // count of most frequent word under here + std::string max_string; // the corresponding std::string std::vector children; }; class IncrementalEditDistance { public: - IncrementalEditDistance(std::string& target, size_t subst_cost=1, size_t ins_cost=1, size_t del_cost=1) - : target(target), subst_cost(subst_cost), ins_cost(ins_cost), del_cost(del_cost), N(target.length()), output_string("") - { prev_row = new size_t[N+1]; - cur_row = new size_t[N+1]; + IncrementalEditDistance(std::string& target, size_t subst_cost = 1, size_t ins_cost = 1, size_t del_cost = 1) + : target(target) + , subst_cost(subst_cost) + , ins_cost(ins_cost) + , del_cost(del_cost) + , N(target.length()) + , output_string("") + { + prev_row = new size_t[N + 1]; + cur_row = new size_t[N + 1]; for (size_t n = 0; n <= N; n++) { prev_row[n] = del_cost * n; } @@ -148,13 +167,14 @@ class IncrementalEditDistance } void append(char c) - { output_string += c; + { + output_string += c; cur_row[0] = prev_row[0] + ins_cost; prev_row_min = cur_row[0]; - for (size_t n=1; n<=N; n++) - { cur_row[n] = min3( prev_row[n] + ins_cost, - prev_row[n-1] + ((target[n-1] == c) ? 0 : subst_cost), - cur_row[n-1] + del_cost ); + for (size_t n = 1; n <= N; n++) + { + cur_row[n] = min3( + prev_row[n] + ins_cost, prev_row[n - 1] + ((target[n - 1] == c) ? 0 : subst_cost), cur_row[n - 1] + del_cost); prev_row_min = std::min(prev_row_min, cur_row[n]); } // swap cur_row and prev_row @@ -169,15 +189,16 @@ class IncrementalEditDistance } std::vector& next() - { A.clear(); - for (size_t n=0; n<=N; n++) + { + A.clear(); + for (size_t n = 0; n <= N; n++) { if (prev_row[n] == prev_row_min) { A.push_back((n < N) ? target[n] : '$'); } } return A; } - std::vector> all_next() + std::vector> all_next() { std::vector> B; for (action a = 1; a <= 29; a++) { B.push_back(std::make_pair(a, 1.f)); } @@ -197,24 +218,29 @@ class IncrementalEditDistance { // find last occurrence of prev_row_min int n = (int)N; while (n >= 0 && prev_row[n] > prev_row_min) { n--; } - return (N-n) * ins_cost + prev_row_min; + return (N - n) * ins_cost + prev_row_min; } - ~IncrementalEditDistance() { delete[] prev_row; delete[] cur_row; } + ~IncrementalEditDistance() + { + delete[] prev_row; + delete[] cur_row; + } private: size_t* prev_row; size_t* cur_row; - std::string target; - size_t subst_cost, ins_cost, del_cost, prev_row_min, N; - std::string output_string; + std::string target; + size_t subst_cost, ins_cost, del_cost, prev_row_min, N; + std::string output_string; std::vector A; inline size_t min3(size_t a, size_t b, size_t c) { return (a < b) ? (a < c) ? a : c : (b < c) ? b : c; } }; struct input -{ std::string in; +{ + std::string in; std::string out; float weight; input(std::string _in, std::string _out, float _weight) : in(std::move(_in)), out(std::move(_out)), weight(_weight) {} @@ -227,8 +253,8 @@ using output = std::string; float max_cost = 100.; -float get_or_one(std::vector >& v, char c) -{ // TODO: could binary search +float get_or_one(std::vector>& v, char c) +{ // TODO: could binary search for (auto& p : v) { if (p.first == c) { return min_float(max_cost, (float)p.second); } @@ -245,22 +271,20 @@ class Generator : public SearchTask // TODO: if action costs is specified but no allowed actions provided, don't segfault :P sch.set_options(Search::AUTO_CONDITION_FEATURES | Search::NO_CACHING | Search::ACTION_COSTS); HookTask::task_data& d = *sch.get_task_data(); - if (d.num_actions != 29) - { - THROW("Error: d.num_actions was not 29"); - } + if (d.num_actions != 29) { THROW("Error: d.num_actions was not 29"); } } void _run(Search::search& sch, input& in, output& out) - { IncrementalEditDistance ied(in.out); + { + IncrementalEditDistance ied(in.out); auto& vw_obj = sch.get_vw_pointer_unsafe(); VW::v_array ref; int N = (int)in.in.length(); out = "^"; - std::vector next; - for (int m=1; m<=N*2; m++) // at most |in|*2 outputs + std::vector next; + for (int m = 1; m <= N * 2; m++) // at most |in|*2 outputs { VW::example ex; @@ -277,7 +301,7 @@ class Generator : public SearchTask auto& fs_s = ex.feature_space['s']; ex.indices.push_back('s'); std::string tmp("$"); - for (int i=m; i >= m-15 && i >= 0; i--) + for (int i = m; i >= m - 15 && i >= 0; i--) { std::stringstream ss; ss << out[i] << tmp; @@ -314,14 +338,16 @@ class Generator : public SearchTask // do we match the trie? if (dict) - { next.clear(); + { + next.clear(); dict->get_next(nullptr, next); auto ns_hash_d = VW::hash_space(vw_obj, "d"); auto& fs_d = ex.feature_space['d']; ex.indices.push_back('d'); - char best_char = '~'; float best_count = 0.; + char best_char = '~'; + float best_count = 0.; for (const auto& xx : next) { if (xx.cw > 0.) { fs_d.push_back(xx.cw, VW::hash_feature(vw_obj, "c=" + std::string(1, xx.c), ns_hash_d)); } @@ -349,7 +375,8 @@ class Generator : public SearchTask ex.indices.push_back('i'); tmp = ""; for (char c : in.in) - { if (c == ' ') + { + if (c == ' ') { fs_i.push_back(1.f, VW::hash_feature(vw_obj, "w=" + tmp, ns_hash_i)); tmp = ""; @@ -373,7 +400,7 @@ class Generator : public SearchTask .predict() ); */ VW::setup_example(vw_obj, &ex); - std::vector > all = ied.all_next(); + std::vector> all = ied.all_next(); char c = action2char(Search::predictor(sch, m).set_input(ex).set_allowed(all).predict()); VW::finish_example(vw_obj, ex); @@ -402,47 +429,42 @@ void run_easy() Generator task(vw_obj); output out(""); - std::vector training_data = - { input("maison", "house"), - input("lune", "moon"), - input("petite lune", "little moon"), - input("la fleur", "the flower"), - input("petite maison", "little house"), - input("fleur", "flower"), - input("la maison", "the house"), - input("grande lune", "big moon"), - input("grande fleur", "big flower") - }; - std::vector test_data = - { input("petite fleur", "little flower"), - input("grande maison", "big house") - }; - for (size_t i=0; i<100; i++) - { //if (i == 9999) max_cost = 1.; + std::vector training_data = {input("maison", "house"), input("lune", "moon"), + input("petite lune", "little moon"), input("la fleur", "the flower"), input("petite maison", "little house"), + input("fleur", "flower"), input("la maison", "the house"), input("grande lune", "big moon"), + input("grande fleur", "big flower")}; + std::vector test_data = {input("petite fleur", "little flower"), input("grande maison", "big house")}; + for (size_t i = 0; i < 100; i++) + { // if (i == 9999) max_cost = 1.; if (i % 10 == 0) { cerr << '.'; } for (auto x : training_data) { task.learn(x, out); } } cerr << endl; for (auto x : training_data) - { task.predict(x, out); + { + task.predict(x, out); cerr << "output = " << out << endl; } for (auto x : test_data) - { task.predict(x, out); + { + task.predict(x, out); cerr << "output = " << out << endl; } } Trie load_dictionary(const char* fname) -{ std::ifstream h(fname); +{ + std::ifstream h(fname); Trie t; std::string line; - while (getline(h,line)) - { const char* str = line.c_str(); + while (getline(h, line)) + { + const char* str = line.c_str(); char* space = (char*)strchr(str, ' '); if (space) - { *space = 0; + { + *space = 0; space++; t.insert(space, atoi(str)); } @@ -454,31 +476,32 @@ Trie load_dictionary(const char* fname) return t; } -void run_istream(Generator& gen, const char* fname, bool is_learn=true, size_t print_every=0) -{ std::ifstream h(fname); - if (!h.is_open()) - { - THROW("cannot open file " << fname); - } +void run_istream(Generator& gen, const char* fname, bool is_learn = true, size_t print_every = 0) +{ + std::ifstream h(fname); + if (!h.is_open()) { THROW("cannot open file " << fname); } std::string line; output out; size_t n = 0; float dist = 0.; float weight = 0.; while (getline(h, line)) - { n++; + { + n++; if (n % 500 == 0) { cerr << '.'; } size_t i = line.find(" ||| "); - size_t j = line.find(" ||| ", i+1); + size_t j = line.find(" ||| ", i + 1); if (i == std::string::npos || j == std::string::npos) - { cerr << "skipping line " << n << ": '" << line << "'" << endl; + { + cerr << "skipping line " << n << ": '" << line << "'" << endl; continue; } - input dat(line.substr(j+5), line.substr(i+5,j-i-5), (float)(atof(line.substr(0,i).c_str())/10.)); + input dat(line.substr(j + 5), line.substr(i + 5, j - i - 5), (float)(atof(line.substr(0, i).c_str()) / 10.)); weight += dat.weight; if (is_learn) { gen.learn(dat, out); } else - { gen.predict(dat, out); + { + gen.predict(dat, out); if (print_every > 0 && (n % print_every == 0)) { std::cout << gen.get_dist() << "\t" << out << "\t\t\t" << dat.in << " ||| " << dat.out << endl; } dist += dat.weight * (float)gen.get_dist(); @@ -489,10 +512,10 @@ void run_istream(Generator& gen, const char* fname, bool is_learn=true, size_t p } void train() -{ // initialize VW as usual, but use 'hook' as the search_task +{ // initialize VW as usual, but use 'hook' as the search_task Trie dict = load_dictionary("phrase-table.vocab"); dict.build_max(); - //dict.print(); + // dict.print(); std::string init_str( "--search 29 -b 28 --quiet --search_task hook --example_queue_limit 1024 --search_rollin learn --search_rollout " @@ -502,7 +525,7 @@ void train() VW::workspace* vw_obj = VW::initialize(init_str); cerr << init_str << endl; // Generator gen(*vw_obj, nullptr); // &dict); - for (size_t pass=1; pass<=20; pass++) + for (size_t pass = 1; pass <= 20; pass++) { cerr << "===== pass " << pass << " =====" << endl; // run_istream(gen, "phrase-table.tr", true); @@ -516,11 +539,11 @@ void train() void predict() { VW::workspace& vw_obj = *VW::initialize("--quiet -t --example_queue_limit 1024 -i my_model"); - //run(vw_obj); + // run(vw_obj); VW::finish(vw_obj); } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { /* std::string target(argv[1]); cerr << "target = " << target << endl; @@ -551,6 +574,6 @@ int main(int argc, char *argv[]) return 0; */ train(); - //predict(); - //run_easy(); + // predict(); + // run_easy(); } diff --git a/library/test_search.cc b/library/test_search.cc index 3a6716157ee..bb3310c7aef 100644 --- a/library/test_search.cc +++ b/library/test_search.cc @@ -28,11 +28,11 @@ class SequenceLabelerTask : public SearchTask, std::vector & input_example, std::vector & output) + void _run(Search::search& sch, std::vector& input_example, std::vector& output) { output.clear(); - //ptag currently uint32_t - for (ptag i=0; i, std::vector & input_example, std::vector & output) + void _run2(Search::search& sch, std::vector& input_example, std::vector& output) { auto& vw_obj = sch.get_vw_pointer_unsafe(); output.clear(); - //ptag currently uint32_t - for (ptag i=0; i data; std::vector output; uint32_t DET = 1, NOUN = 2, VERB = 3, ADJ = 4; - data.push_back( wt("the", DET) ); - data.push_back( wt("monster", NOUN) ); - data.push_back( wt("ate", VERB) ); - data.push_back( wt("a", DET) ); - data.push_back( wt("big", ADJ) ); - data.push_back( wt("sandwich", NOUN) ); + data.push_back(wt("the", DET)); + data.push_back(wt("monster", NOUN)); + data.push_back(wt("ate", VERB)); + data.push_back(wt("a", DET)); + data.push_back(wt("big", ADJ)); + data.push_back(wt("sandwich", NOUN)); task.learn(data, output); task.learn(data, output); task.learn(data, output); @@ -120,14 +120,14 @@ void test_buildin_task() // now, load that model using the BuiltInTask library cerr << endl << endl << "##### test BuiltInTask #####" << endl << endl; VW::workspace& vw_obj = *VW::initialize("-t --search_task hook"); - { // create a new scope for the task object + { // create a new scope for the task object BuiltInTask task(vw_obj, &SequenceTask::task); VW::multi_ex V; - V.push_back( VW::read_example(vw_obj, (char*)"1 | a") ); - V.push_back( VW::read_example(vw_obj, (char*)"1 | a") ); - V.push_back( VW::read_example(vw_obj, (char*)"1 | a") ); - V.push_back( VW::read_example(vw_obj, (char*)"1 | a") ); - V.push_back( VW::read_example(vw_obj, (char*)"1 | a") ); + V.push_back(VW::read_example(vw_obj, (char*)"1 | a")); + V.push_back(VW::read_example(vw_obj, (char*)"1 | a")); + V.push_back(VW::read_example(vw_obj, (char*)"1 | a")); + V.push_back(VW::read_example(vw_obj, (char*)"1 | a")); + V.push_back(VW::read_example(vw_obj, (char*)"1 | a")); std::vector out; task.predict(V, out); cerr << "out (should be 1 2 3 4 3) ="; diff --git a/test/benchmarks/benchmarks_common.h b/test/benchmarks/benchmarks_common.h index 41c9186d09f..3fd3045d972 100644 --- a/test/benchmarks/benchmarks_common.h +++ b/test/benchmarks/benchmarks_common.h @@ -1,6 +1,6 @@ -#include #include #include +#include inline std::string get_x_numerical_fts(int feature_size) { diff --git a/test/benchmarks/standalone/rcv1_benchmarks.cc b/test/benchmarks/standalone/rcv1_benchmarks.cc index 62cbae81d5d..e1c79fa8491 100644 --- a/test/benchmarks/standalone/rcv1_benchmarks.cc +++ b/test/benchmarks/standalone/rcv1_benchmarks.cc @@ -5319,10 +5319,7 @@ static void benchmark_rcv1_dataset(benchmark::State& state, std::string command_ for (auto _ : state) { - for (auto* example : examples) - { - vw->learn(*example); - } + for (auto* example : examples) { vw->learn(*example); } benchmark::ClobberMemory(); } diff --git a/test/tools/fuzzing/main.cc b/test/tools/fuzzing/main.cc index 9ff3744035b..6ffbbcb4651 100644 --- a/test/tools/fuzzing/main.cc +++ b/test/tools/fuzzing/main.cc @@ -8,10 +8,11 @@ int main(int argc, char** argv) { std::unique_ptr ptr( new VW::config::options_cli(std::vector(argv + 1, argv + argc))); - try { + try + { VW::workspace* all = VW::initialize(*ptr); } - catch(...) + catch (...) { exit(1); } diff --git a/test/tools/parser_throughput/main.cc b/test/tools/parser_throughput/main.cc index efb12b3580d..77b90ae12a5 100644 --- a/test/tools/parser_throughput/main.cc +++ b/test/tools/parser_throughput/main.cc @@ -107,10 +107,7 @@ int main(int argc, char** argv) } const auto type = to_parser_type(type_str); - if (type == parser_type::dsjson) - { - args += " --dsjson"; - } + if (type == parser_type::dsjson) { args += " --dsjson"; } auto vw = VW::initialize(args, nullptr, false, nullptr, nullptr); const auto is_multiline = vw->l->is_multiline(); @@ -163,10 +160,7 @@ int main(int argc, char** argv) (VW::example_factory_t)&VW::get_unused_example, (void*)vw, &interaction); VW::multi_ex result; result.reserve(examples.size()); - for (size_t i = 0; i < examples.size(); ++i) - { - result.push_back(examples[i]); - } + for (size_t i = 0; i < examples.size(); ++i) { result.push_back(examples[i]); } // TODO - finish_example should support a v_array as input. VW::finish_example(*vw, result); } diff --git a/test/unit_test/automl_test.cc b/test/unit_test/automl_test.cc index ba7b03536d5..b73ff0b0281 100644 --- a/test/unit_test/automl_test.cc +++ b/test/unit_test/automl_test.cc @@ -36,7 +36,7 @@ void check_interactions_match_exclusions(VW::reductions::automl::automl ns{ns1, ns2}; + std::vector ns{ns1, ns2}; BOOST_CHECK(exclusions.find(ns) == exclusions.end()); } else @@ -44,7 +44,7 @@ void check_interactions_match_exclusions(VW::reductions::automl::automl ns{ns1, ns2, ns3}; + std::vector ns{ns1, ns2, ns3}; BOOST_CHECK(exclusions.find(ns) == exclusions.end()); } } @@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(automl_namespace_switch) auto champ_exclusions = aml->cm->configs[aml->cm->scores[aml->cm->current_champ].first.config_index].exclusions; BOOST_CHECK_EQUAL(champ_exclusions.size(), 1); - std::vector ans{'U', 'U'}; + std::vector ans{'U', 'U'}; BOOST_CHECK(champ_exclusions.find(ans) != champ_exclusions.end()); auto champ_interactions = aml->cm->scores[aml->cm->current_champ].first.live_interactions; BOOST_CHECK_EQUAL(champ_interactions.size(), 5); diff --git a/test/unit_test/cats_user_provided_pdf.cc b/test/unit_test/cats_user_provided_pdf.cc index 8553a19a631..5458354ba02 100644 --- a/test/unit_test/cats_user_provided_pdf.cc +++ b/test/unit_test/cats_user_provided_pdf.cc @@ -2,11 +2,10 @@ // individual contributors. All rights reserved. Released under a BSD (revised) // license as described in the file LICENSE. -#include -#include - #include "test_common.h" +#include +#include #include BOOST_AUTO_TEST_CASE(cats_no_model_action_provided) diff --git a/test/unit_test/cb_explore_adf_test.cc b/test/unit_test/cb_explore_adf_test.cc index 1199647d9cf..0afa92f449f 100644 --- a/test/unit_test/cb_explore_adf_test.cc +++ b/test/unit_test/cb_explore_adf_test.cc @@ -6,7 +6,8 @@ #include -BOOST_AUTO_TEST_CASE(cb_explore_adf_should_throw_empty_multi_example) { +BOOST_AUTO_TEST_CASE(cb_explore_adf_should_throw_empty_multi_example) +{ auto vw = VW::initialize("--cb_explore_adf --quiet", nullptr, false, nullptr, nullptr); VW::multi_ex example_collection; diff --git a/test/unit_test/custom_reduction_test.cc b/test/unit_test/custom_reduction_test.cc index 4a0eaccdd84..b0eda2aa935 100644 --- a/test/unit_test/custom_reduction_test.cc +++ b/test/unit_test/custom_reduction_test.cc @@ -2,8 +2,8 @@ // individual contributors. All rights reserved. Released under a BSD (revised) // license as described in the file LICENSE. -#include #include +#include // this test is a copy from unit_test/prediction_test.cc // it adds a noop reduction on top diff --git a/test/unit_test/dsjson_parser_test.cc b/test/unit_test/dsjson_parser_test.cc index 2609949936b..c6cfa7ca5a5 100644 --- a/test/unit_test/dsjson_parser_test.cc +++ b/test/unit_test/dsjson_parser_test.cc @@ -777,7 +777,7 @@ BOOST_AUTO_TEST_CASE(parse_dsjson_slates) BOOST_CHECK_EQUAL(ds_interaction.eventId, "test_id"); BOOST_CHECK_CLOSE(ds_interaction.probabilityOfDrop, 0.1, FLOAT_TOL); BOOST_CHECK_EQUAL(ds_interaction.skipLearn, true); - check_collections_exact(ds_interaction.actions, std::vector{1,0}); + check_collections_exact(ds_interaction.actions, std::vector{1, 0}); check_collections_with_float_tolerance(ds_interaction.probabilities, std::vector{0.8f, 0.6f}, FLOAT_TOL); VW::finish_example(*vw, examples); @@ -844,12 +844,18 @@ BOOST_AUTO_TEST_CASE(parse_dsjson_slates_dom_parser) check_collections_exact(slates_ex.feature_space['d'].indices, ccb_ex.feature_space['d'].indices); check_collections_exact(slates_ex.feature_space['e'].indices, ccb_ex.feature_space['e'].indices); - check_collections_with_float_tolerance(slates_ex.feature_space[' '].values, ccb_ex.feature_space[' '].values, FLOAT_TOL); - check_collections_with_float_tolerance(slates_ex.feature_space['a'].values, ccb_ex.feature_space['a'].values, FLOAT_TOL); - check_collections_with_float_tolerance(slates_ex.feature_space['b'].values, ccb_ex.feature_space['b'].values, FLOAT_TOL); - check_collections_with_float_tolerance(slates_ex.feature_space['c'].values, ccb_ex.feature_space['c'].values, FLOAT_TOL); - check_collections_with_float_tolerance(slates_ex.feature_space['d'].values, ccb_ex.feature_space['d'].values, FLOAT_TOL); - check_collections_with_float_tolerance(slates_ex.feature_space['e'].values, ccb_ex.feature_space['e'].values, FLOAT_TOL); + check_collections_with_float_tolerance( + slates_ex.feature_space[' '].values, ccb_ex.feature_space[' '].values, FLOAT_TOL); + check_collections_with_float_tolerance( + slates_ex.feature_space['a'].values, ccb_ex.feature_space['a'].values, FLOAT_TOL); + check_collections_with_float_tolerance( + slates_ex.feature_space['b'].values, ccb_ex.feature_space['b'].values, FLOAT_TOL); + check_collections_with_float_tolerance( + slates_ex.feature_space['c'].values, ccb_ex.feature_space['c'].values, FLOAT_TOL); + check_collections_with_float_tolerance( + slates_ex.feature_space['d'].values, ccb_ex.feature_space['d'].values, FLOAT_TOL); + check_collections_with_float_tolerance( + slates_ex.feature_space['e'].values, ccb_ex.feature_space['e'].values, FLOAT_TOL); VW::finish_example(*slates_vw, slates_examples); VW::finish(*slates_vw); diff --git a/test/unit_test/error_test.cc b/test/unit_test/error_test.cc index c88bd6d220c..de4959402e5 100644 --- a/test/unit_test/error_test.cc +++ b/test/unit_test/error_test.cc @@ -7,7 +7,8 @@ #include #include -BOOST_AUTO_TEST_CASE(check_strerr_can_retrieve_error_message) { +BOOST_AUTO_TEST_CASE(check_strerr_can_retrieve_error_message) +{ // EIO is just a randomly chosen error to test with. auto message = VW::strerror_to_string(EIO); // If the error message contains unknown, then the error retrieval failed and it returned a generic message. diff --git a/test/unit_test/example_header_test.cc b/test/unit_test/example_header_test.cc index cb95c3192ec..79ab4b0c226 100644 --- a/test/unit_test/example_header_test.cc +++ b/test/unit_test/example_header_test.cc @@ -10,7 +10,8 @@ #include #include -BOOST_AUTO_TEST_CASE(is_example_header_cb) { +BOOST_AUTO_TEST_CASE(is_example_header_cb) +{ auto& vw = *VW::initialize("--cb_explore_adf --quiet", nullptr, false, nullptr, nullptr); VW::multi_ex examples; examples.push_back(VW::read_example(vw, "shared | s_1 s_2")); @@ -29,7 +30,8 @@ BOOST_AUTO_TEST_CASE(is_example_header_cb) { VW::finish(vw); } -BOOST_AUTO_TEST_CASE(is_example_header_ccb) { +BOOST_AUTO_TEST_CASE(is_example_header_ccb) +{ auto& vw = *VW::initialize("--ccb_explore_adf --quiet", nullptr, false, nullptr, nullptr); VW::multi_ex examples; examples.push_back(VW::read_example(vw, "ccb shared |User f")); @@ -41,7 +43,8 @@ BOOST_AUTO_TEST_CASE(is_example_header_ccb) { VW::finish(vw); } -BOOST_AUTO_TEST_CASE(is_example_header_csoaa) { +BOOST_AUTO_TEST_CASE(is_example_header_csoaa) +{ auto& vw = *VW::initialize("--csoaa_ldf multiline --quiet", nullptr, false, nullptr, nullptr); VW::multi_ex examples; examples.push_back(VW::read_example(vw, "shared | a_2 b_2 c_2")); diff --git a/test/unit_test/guard_test.cc b/test/unit_test/guard_test.cc index 6363e62aeb6..5686695fd51 100644 --- a/test/unit_test/guard_test.cc +++ b/test/unit_test/guard_test.cc @@ -20,7 +20,6 @@ struct non_copyable_struct non_copyable_struct& operator=(non_copyable_struct&& other) = default; }; - BOOST_AUTO_TEST_CASE(swap_guard_execute_on_scope_end) { int original_location = 1; diff --git a/test/unit_test/minimal_custom_reduction.cc b/test/unit_test/minimal_custom_reduction.cc index a442f1694d9..debfa9be764 100644 --- a/test/unit_test/minimal_custom_reduction.cc +++ b/test/unit_test/minimal_custom_reduction.cc @@ -2,8 +2,8 @@ // individual contributors. All rights reserved. Released under a BSD (revised) // license as described in the file LICENSE. -#include #include +#include // this test is a copy from unit_test/prediction_test.cc // it adds a noop reduction on top diff --git a/test/unit_test/pmf_to_pdf_test.cc b/test/unit_test/pmf_to_pdf_test.cc index 4f5bcca30f1..ce19d83db4c 100644 --- a/test/unit_test/pmf_to_pdf_test.cc +++ b/test/unit_test/pmf_to_pdf_test.cc @@ -30,16 +30,16 @@ struct reduction_test_harness { ec.pred.a_s.push_back(ACTION_SCORE::action_score{_predictions[i].first, _predictions[i].second}); } } - void test_learn(base_learner& base, example& ec) + void test_learn(base_learner& base, VW::example& ec) { /*noop*/ } - static void predict(reduction_test_harness& test_reduction, base_learner& base, example& ec) + static void predict(reduction_test_harness& test_reduction, base_learner& base, VW::example& ec) { test_reduction.test_predict(base, ec); } - static void learn(reduction_test_harness& test_reduction, base_learner& base, example& ec) + static void learn(reduction_test_harness& test_reduction, base_learner& base, VW::example& ec) { test_reduction.test_learn(base, ec); }; @@ -49,7 +49,7 @@ struct reduction_test_harness int _curr_idx; }; -using test_learner_t = learner; +using test_learner_t = learner; using predictions_t = vector>; test_learner_t* get_test_harness_reduction(const predictions_t& base_reduction_predictions) diff --git a/test/unit_test/power_test.cc b/test/unit_test/power_test.cc index 5e9ff4a087c..8e190664836 100644 --- a/test/unit_test/power_test.cc +++ b/test/unit_test/power_test.cc @@ -12,7 +12,8 @@ bool are_same(float a, float b) { return std::abs(a - b) < std::numeric_limits(std::pow(base, -127)))); BOOST_CHECK(are_same(VW::fast_pow10(-46), static_cast(std::pow(base, -46)))); diff --git a/test/unit_test/slates_test.cc b/test/unit_test/slates_test.cc index 3d4ef2f2722..0c1804bac61 100644 --- a/test/unit_test/slates_test.cc +++ b/test/unit_test/slates_test.cc @@ -25,12 +25,12 @@ struct test_base static void invoke_learn( test_base& data, VW::LEARNER::base_learner& /*base*/, VW::multi_ex& examples) { - data.test_learn_func(examples); + data.test_learn_func(examples); } static void invoke_predict( test_base& data, VW::LEARNER::base_learner& /*base*/, VW::multi_ex& examples) { - data.test_predict_func(examples); + data.test_predict_func(examples); } }; @@ -69,14 +69,14 @@ BOOST_AUTO_TEST_CASE(slates_reduction_mock_test) BOOST_CHECK_CLOSE(examples[4]->l.conditional_contextual_bandit.outcome->cost, 0.8f, FLOAT_TOL); check_collections_with_float_tolerance(examples[4]->l.conditional_contextual_bandit.outcome->probabilities, std::vector{{0, 0.8f}}); - check_collections_exact(examples[4]->l.conditional_contextual_bandit.explicit_included_actions, - std::vector{0}); + check_collections_exact( + examples[4]->l.conditional_contextual_bandit.explicit_included_actions, std::vector{0}); BOOST_CHECK_EQUAL(examples[5]->l.conditional_contextual_bandit.type, CCB::example_type::slot); BOOST_CHECK_CLOSE(examples[5]->l.conditional_contextual_bandit.outcome->cost, 0.8f, FLOAT_TOL); check_collections_with_float_tolerance(examples[5]->l.conditional_contextual_bandit.outcome->probabilities, std::vector{{2, 0.6f}}); check_collections_exact( - examples[5]->l.conditional_contextual_bandit.explicit_included_actions, std::vector{1,2}); + examples[5]->l.conditional_contextual_bandit.explicit_included_actions, std::vector{1, 2}); // Prepare and return the prediction VW::v_array slot_zero; diff --git a/test/unit_test/stable_unique_test.cc b/test/unit_test/stable_unique_test.cc index a1df711a297..67894943faf 100644 --- a/test/unit_test/stable_unique_test.cc +++ b/test/unit_test/stable_unique_test.cc @@ -10,8 +10,8 @@ BOOST_AUTO_TEST_CASE(stable_unique_sorted) { - std::vector v = {1,1,2,2,2,6,78,89,89}; - std::vector expected = {1,2,6,78,89}; + std::vector v = {1, 1, 2, 2, 2, 6, 78, 89, 89}; + std::vector expected = {1, 2, 6, 78, 89}; v.erase(stable_unique(v.begin(), v.end()), v.end()); @@ -20,8 +20,8 @@ BOOST_AUTO_TEST_CASE(stable_unique_sorted) BOOST_AUTO_TEST_CASE(stable_unique_unsorted) { - std::vector v = {45,65,76,23,45,11,34,23,45,-34,-1,22,23,22,0,0,11,23,109}; - std::vector expected = {45,65,76,23,11,34,-34,-1,22,0,109}; + std::vector v = {45, 65, 76, 23, 45, 11, 34, 23, 45, -34, -1, 22, 23, 22, 0, 0, 11, 23, 109}; + std::vector expected = {45, 65, 76, 23, 11, 34, -34, -1, 22, 0, 109}; v.erase(stable_unique(v.begin(), v.end()), v.end()); diff --git a/test/unit_test/test_common.cc b/test/unit_test/test_common.cc index f0350e9eb3b..ae417aa75b0 100644 --- a/test/unit_test/test_common.cc +++ b/test/unit_test/test_common.cc @@ -14,10 +14,7 @@ VW::multi_ex parse_json(VW::workspace& all, const std::string& line) setup_examples(all, examples); VW::multi_ex result; - for (size_t i = 0; i < examples.size(); ++i) - { - result.push_back(examples[i]); - } + for (size_t i = 0; i < examples.size(); ++i) { result.push_back(examples[i]); } return result; } @@ -42,6 +39,7 @@ bool is_invoked_with(const std::string& arg) for (size_t i = 0; i < boost::unit_test::framework::master_test_suite().argc; i++) { if (VW::string_view(boost::unit_test::framework::master_test_suite().argv[i]).find(arg) != std::string::npos) - { return true; } } + { return true; } + } return false; } \ No newline at end of file diff --git a/test/unit_test/test_common.h b/test/unit_test/test_common.h index 8af82af55fb..c9caa75b4a7 100644 --- a/test/unit_test/test_common.h +++ b/test/unit_test/test_common.h @@ -25,15 +25,13 @@ inline void compare(const ACTION_SCORE::action_score& l, const ACTION_SCORE::act } template -void check_collections_with_float_tolerance(const ContainerOneT& lhs, const ContainerTwoT& rhs, float float_tolerance = FLOAT_TOL) +void check_collections_with_float_tolerance( + const ContainerOneT& lhs, const ContainerTwoT& rhs, float float_tolerance = FLOAT_TOL) { BOOST_CHECK_EQUAL(lhs.size(), rhs.size()); auto l = std::begin(lhs); auto r = std::begin(rhs); - for (; l < std::end(lhs); ++l, ++r) - { - compare(*l, *r, float_tolerance); - } + for (; l < std::end(lhs); ++l, ++r) { compare(*l, *r, float_tolerance); } } template