/* Copyright (c) by respective owners including Yahoo!, Microsoft, and individual contributors. All rights reserved. Released under a BSD (revised) license as described in the file LICENSE. */ #pragma once #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include "vw.h" #include "vw_settings.h" #include using namespace System; using namespace System::Runtime::InteropServices; namespace VW { /// /// Collected performance statistics. /// public ref class VowpalWabbitPerformanceStatistics { public: /// /// The total number of features seen since instance creation. /// property uint64_t TotalNumberOfFeatures; /// /// The weighted sum of examples. /// property double WeightedExampleSum; /// /// The total number of examples per pass. /// property uint64_t NumberOfExamplesPerPass; /// /// The weighted sum of labels. /// property double WeightedLabelSum; /// /// The average loss since instance creation. /// property double AverageLoss; /// /// The best constant since instance creation. /// property double BestConstant; /// /// The best constant loss since instance creation. /// property double BestConstantLoss; }; /// /// A managed wrapper for native vowpal wabbit exceptions. /// /// /// As the default managed exception wrapping any native exception doesn't even capture exception::what() /// this wrapper was created. /// [Serializable] public ref class VowpalWabbitException : Exception { private: /// /// The source filename in which the wrapped exception occurred. /// initonly String^ m_filename; /// /// The line number in which the wrapped exception occurred. /// initonly Int32 m_lineNumber; public: /// /// Initializes a new instance of . /// /// The native vowpal wabbit exception VowpalWabbitException(const vw_exception& ex); /// /// Gets the source filename in which the wrapped exception occurred. /// property String^ Filename { String^ get(); } /// /// Gets the line number in which the wrapped exception occurred. /// property Int32 LineNumber { Int32 get(); } }; /// /// A managed wrapper for native vowpal wabbit exceptions. /// /// /// As the default managed exception wrapping any native exception doesn't even capture exception::what() /// this wrapper was created. /// [Serializable] public ref class VowpalWabbitArgumentDisagreementException : VowpalWabbitException { public: /// /// Initializes a new instance of . /// /// The native vowpal wabbit exception VowpalWabbitArgumentDisagreementException(const vw_argument_disagreement_exception& ex); }; #ifdef _DEBUG [System::ComponentModel::Browsable(false)] [System::ComponentModel::EditorBrowsable(System::ComponentModel::EditorBrowsableState::Never)] public ref class VowpalWabbitLeakTest abstract sealed { public: static void Leak() { new float[123]; } static void NoLeak() { void* ptr = calloc(128, 2); ptr = realloc(ptr, 128 * 3); free(ptr); } }; #endif } #define CATCHRETHROW \ catch (VW::vw_exception const& ex) \ { throw gcnew VW::VowpalWabbitException(ex); } \ catch (std::exception const& ex) \ { throw gcnew System::Exception(gcnew System::String(ex.what())); }