Merged PR 5150: Functionality to specify an optional data root dir

- Functionality to specify an optional data root dir
- Moved sg_pointerTable to a single compilation unit and renamed it to g_pointerTable
This commit is contained in:
David Brownell 2019-09-23 21:42:22 +00:00
Родитель 77c02d515d
Коммит 733ca71a36
17 изменённых файлов: 577 добавлений и 445 удалений

Просмотреть файл

@ -111,15 +111,36 @@ namespace {
return result;
}
std::string GetDataDirectory(void) {
std::string const binaryPath(GetBinaryPath());
std::string GetDataDirectory(std::string optionalDataRootDir) {
std::string const binaryPath(
[&optionalDataRootDir](void) {
if(optionalDataRootDir.empty() == false) {
if(*optionalDataRootDir.rbegin() == '\\')
optionalDataRootDir.resize(optionalDataRootDir.size() - 1);
return binaryPath.substr(0, binaryPath.find_last_of("\\")) + "\\Data\\DateTimeFeaturizer\\";
unsigned long const attributes(GetFileAttributes(optionalDataRootDir.c_str()));
if(attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
throw std::invalid_argument("Invalid 'dataRootDir'");
return optionalDataRootDir;
}
std::string result(GetBinaryPath());
return result.substr(0, result.find_last_of("\\"));
}()
);
return binaryPath + "\\Data\\DateTimeFeaturizer\\";
}
bool EnumCountries(std::function<bool (std::string)> const &callback) {
bool EnumCountries(
std::function<bool (std::string)> const &callback,
std::string const &optionalDataRootDir
) {
// Note that this code is not exception safe!
std::string dataDir(GetDataDirectory() + "*");
std::string dataDir(GetDataDirectory(optionalDataRootDir) + "*");
WIN32_FIND_DATA data;
HANDLE handle;
bool result(true);
@ -158,16 +179,39 @@ namespace {
return result;
}
std::string GetDataDirectory(void) {
std::string const binaryPath(GetBinaryPath());
std::string GetDataDirectory(std::string optionalDataRootDir) {
std::string const binaryPath(
[&optionalDataRootDir](void) {
if(optionalDataRootDir.empty() == false) {
if(*optionalDataRootDir.rbegin() == '/')
optionalDataRootDir.resize(optionalDataRootDir.size() - 1);
return binaryPath.substr(0, binaryPath.find_last_of("/")) + "/Data/DateTimeFeaturizer/";
DIR * dir(opendir(optionalDataRootDir.c_str()));
if(dir == nullptr)
throw std::invalid_argument("Invalid 'dataRootDir'");
closedir(dir);
return optionalDataRootDir;
}
std::string result(GetBinaryPath());
return result.substr(0, result.find_last_of("/"));
}()
);
return binaryPath + "/Data/DateTimeFeaturizer/";
}
bool EnumCountries(std::function<bool (std::string)> const &callback) {
bool EnumCountries(
std::function<bool (std::string)> const &callback,
std::string const &optionalDataRootDir
) {
// Note that this code is not exception safe
bool result(true);
DIR * dir(opendir(GetDataDirectory().c_str()));
DIR * dir(opendir(GetDataDirectory(optionalDataRootDir).c_str()));
if(dir == nullptr)
return result;
@ -236,12 +280,15 @@ bool DoesCountryMatch(std::string const &country, std::string query) {
} // anonymous namespace
DateTimeTransformer::DateTimeTransformer(Archive &ar) :
_countryName(Traits<std::string>::deserialize(ar)) {
DateTimeTransformer(this->_countryName);
DateTimeTransformer(Traits<std::string>::deserialize(ar), "") {
}
DateTimeTransformer::DateTimeTransformer(std::string countryName):
_countryName(std::move(countryName)) {
DateTimeTransformer::DateTimeTransformer(Archive &ar, std::string dataRootDir) :
DateTimeTransformer(Traits<std::string>::deserialize(ar), std::move(dataRootDir)) {
}
DateTimeTransformer::DateTimeTransformer(std::string optionalCountryName, std::string optionalDataRootDir):
_countryName(std::move(optionalCountryName)) {
if (!_countryName.empty()) {
// Get the corresponding file
@ -258,14 +305,15 @@ DateTimeTransformer::DateTimeTransformer(std::string countryName):
}
return true;
}
},
optionalDataRootDir
)
) {
// A true return value means that we have enumerated through all of the country names and didn't find a match
throw std::invalid_argument(_countryName);
}
JsonStream holidaysByCountry = GetJsonStream(GetDataDirectory() + filename);
JsonStream holidaysByCountry = GetJsonStream(GetDataDirectory(optionalDataRootDir) + filename);
//Convert Jsonstream to std::unordered_map
//Note that the map keys are generated with "Date" and "Holiday" so no need to check existence
@ -306,7 +354,7 @@ void DateTimeTransformer::save(Archive & ar) const /*override*/ {
// | DateTimeEstimator
// |
// ----------------------------------------------------------------------
/*static*/ bool DateTimeEstimator::IsValidCountry(std::string const &value) {
/*static*/ bool DateTimeEstimator::IsValidCountry(std::string const &value, nonstd::optional<std::string> dataRootDir) {
// EnumCountries will return true if the enumeration completes
// and false if it was terminated. In this case, termination means
// that the country was found.
@ -314,18 +362,20 @@ void DateTimeTransformer::save(Archive & ar) const /*override*/ {
[&value](std::string country) {
// Continue if the countries don't match
return DoesCountryMatch(value, std::move(country)) == false;
}
},
dataRootDir ? *dataRootDir : std::string()
) == false;
}
/*static*/ std::vector<std::string> DateTimeEstimator::GetSupportedCountries(void) {
/*static*/ std::vector<std::string> DateTimeEstimator::GetSupportedCountries(nonstd::optional<std::string> dataRootDir) {
std::vector<std::string> results;
EnumCountries(
[&results](std::string country) {
results.emplace_back(RemoveCountryExtension(country));
return true;
}
},
dataRootDir ? *dataRootDir : std::string()
);
std::sort(results.begin(), results.end());
@ -333,10 +383,15 @@ void DateTimeTransformer::save(Archive & ar) const /*override*/ {
return results;
}
DateTimeEstimator::DateTimeEstimator(nonstd::optional<std::string> const &countryName, AnnotationMapsPtr pAllColumnAnnotations) :
DateTimeEstimator::DateTimeEstimator(
nonstd::optional<std::string> const &countryName,
nonstd::optional<std::string> const &dataRootDir,
AnnotationMapsPtr pAllColumnAnnotations
) :
BaseType("DateTimeEstimator", std::move(pAllColumnAnnotations), true),
Country(countryName) {
if(Country && DateTimeEstimator::IsValidCountry(*Country) == false) {
Country(countryName),
DataRootDir(dataRootDir) {
if(Country && DateTimeEstimator::IsValidCountry(*Country, DataRootDir) == false) {
char buffer[1024];
snprintf(buffer, sizeof(buffer), "'%s' is not a supported country name", Country->c_str());
@ -356,7 +411,10 @@ Estimator::FitResult DateTimeEstimator::complete_training_impl(void) /*override*
}
typename DateTimeEstimator::BaseType::TransformerUniquePtr DateTimeEstimator::create_transformer_impl(void) /*override*/ {
return std::make_unique<DateTimeTransformer>(Country ? *Country : std::string());
return std::make_unique<DateTimeTransformer>(
Country ? *Country : std::string(),
DataRootDir ? *DataRootDir : std::string()
);
}
} // namespace Featurizers

Просмотреть файл

@ -118,9 +118,13 @@ public:
// | Public Methods
// |
// ----------------------------------------------------------------------
DateTimeTransformer(std::string optionalCountryName);
DateTimeTransformer(std::string optionalCountryName, std::string optionalDataRootDir=std::string());
DateTimeTransformer(Archive &ar);
// This constructor is necessary at the dataRootDir may be different between
// the machine that created the archive and this machine that is deserializing it.
DateTimeTransformer(Archive &ar, std::string dataRootDir);
~DateTimeTransformer(void) override = default;
FEATURIZER_MOVE_CONSTRUCTOR_ONLY(DateTimeTransformer);
@ -173,16 +177,21 @@ public:
// |
// ----------------------------------------------------------------------
nonstd::optional<std::string> const Country;
nonstd::optional<std::string> const DataRootDir;
// ----------------------------------------------------------------------
// |
// | Public Methods
// |
// ----------------------------------------------------------------------
static bool IsValidCountry(std::string const &value);
static std::vector<std::string> GetSupportedCountries(void);
static bool IsValidCountry(std::string const &value, nonstd::optional<std::string> dataRootDir=nonstd::optional<std::string>());
static std::vector<std::string> GetSupportedCountries(nonstd::optional<std::string> dataRootDir=nonstd::optional<std::string>());
DateTimeEstimator(nonstd::optional<std::string> const &optionalCountryName, AnnotationMapsPtr pAllColumnAnnotations);
DateTimeEstimator(
nonstd::optional<std::string> const &optionalCountryName,
nonstd::optional<std::string> const &optionalDataRootDir,
AnnotationMapsPtr pAllColumnAnnotations
);
~DateTimeEstimator(void) override = default;
FEATURIZER_MOVE_CONSTRUCTOR_ONLY(DateTimeEstimator);

Просмотреть файл

@ -13,9 +13,9 @@ namespace NS = Microsoft::Featurizer;
using SysClock = std::chrono::system_clock;
TEST_CASE("DateTimeEstimator") {
CHECK(NS::Featurizers::DateTimeEstimator(nonstd::optional<std::string>(), NS::CreateTestAnnotationMapsPtr(2)).Name == "DateTimeEstimator");
CHECK(NS::Featurizers::DateTimeEstimator(nonstd::optional<std::string>(), NS::CreateTestAnnotationMapsPtr(2)).is_training_complete());
CHECK(dynamic_cast<NS::Featurizers::DateTimeTransformer *>(NS::Featurizers::DateTimeEstimator(nonstd::optional<std::string>(), NS::CreateTestAnnotationMapsPtr(2)).create_transformer().get()));
CHECK(NS::Featurizers::DateTimeEstimator(nonstd::optional<std::string>(), nonstd::optional<std::string>(), NS::CreateTestAnnotationMapsPtr(2)).Name == "DateTimeEstimator");
CHECK(NS::Featurizers::DateTimeEstimator(nonstd::optional<std::string>(), nonstd::optional<std::string>(), NS::CreateTestAnnotationMapsPtr(2)).is_training_complete());
CHECK(dynamic_cast<NS::Featurizers::DateTimeTransformer *>(NS::Featurizers::DateTimeEstimator(nonstd::optional<std::string>(), nonstd::optional<std::string>(), NS::CreateTestAnnotationMapsPtr(2)).create_transformer().get()));
}
TEST_CASE("DateTimeEstimator - IsValidCountry") {
@ -25,6 +25,9 @@ TEST_CASE("DateTimeEstimator - IsValidCountry") {
CHECK(NS::Featurizers::DateTimeEstimator::IsValidCountry("unitedstates"));
CHECK(NS::Featurizers::DateTimeEstimator::IsValidCountry("This is not a valid country") == false);
// Invalid data root dir
CHECK_THROWS(NS::Featurizers::DateTimeEstimator::IsValidCountry("United States", "This is not a valid directory"));
}
TEST_CASE("DateTimeEstimator - GetSupportedCountries") {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -16,7 +16,7 @@ FEATURIZER_LIBRARY_API bool GetErrorInfoString(/*in*/ ErrorInfoHandle *pHandle,
if(pHandle == nullptr || output_ptr == nullptr || output_items == nullptr)
return false;
std::string const & str(*sg_pointerTable.Get<std::string>(reinterpret_cast<size_t>(pHandle)));
std::string const & str(*g_pointerTable.Get<std::string>(reinterpret_cast<size_t>(pHandle)));
char * string_buffer(new char[str.size() + 1]);
@ -44,9 +44,9 @@ FEATURIZER_LIBRARY_API bool DestroyErrorInfo(/*in*/ ErrorInfoHandle *pHandle) {
size_t index = reinterpret_cast<size_t>(pHandle);
std::string & str(*sg_pointerTable.Get<std::string>(index));
std::string & str(*g_pointerTable.Get<std::string>(index));
sg_pointerTable.Remove(index);
g_pointerTable.Remove(index);
delete &str;
@ -59,7 +59,7 @@ FEATURIZER_LIBRARY_API bool DestroyErrorInfo(/*in*/ ErrorInfoHandle *pHandle) {
ErrorInfoHandle * CreateErrorInfo(std::exception const &ex) {
std::unique_ptr<std::string> result(std::make_unique<std::string>(ex.what()));
size_t index = sg_pointerTable.Add(result.release());
size_t index = g_pointerTable.Add(result.release());
return reinterpret_cast<ErrorInfoHandle *>(index);
}

Просмотреть файл

@ -27,7 +27,7 @@ extern "C" {
/* | DateTimeFeaturizer */
/* | */
/* ---------------------------------------------------------------------- */
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateEstimator(/*in*/ char const *optionalCountryName, /*out*/ DateTimeFeaturizer_EstimatorHandle **ppHandle, /*out*/ ErrorInfoHandle **ppErrorInfo) {
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateEstimator(/*in*/ char const *optionalCountryName, /*in*/ char const *optionalDataRootDir, /*out*/ DateTimeFeaturizer_EstimatorHandle **ppHandle, /*out*/ ErrorInfoHandle **ppErrorInfo) {
if(ppErrorInfo == nullptr)
return false;
@ -35,8 +35,8 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateEstimator(/*in*/ char const
*ppErrorInfo = nullptr;
// No validation
Microsoft::Featurizer::Featurizers::DateTimeEstimator* pEstimator = new Microsoft::Featurizer::Featurizers::DateTimeEstimator(optionalCountryName ? std::string(optionalCountryName) : nonstd::optional<std::string>(), std::make_shared<Microsoft::Featurizer::AnnotationMaps>(21));
size_t index(sg_pointerTable.Add(pEstimator));
Microsoft::Featurizer::Featurizers::DateTimeEstimator* pEstimator = new Microsoft::Featurizer::Featurizers::DateTimeEstimator(optionalCountryName ? std::string(optionalCountryName) : nonstd::optional<std::string>(), optionalDataRootDir ? std::string(optionalDataRootDir) : nonstd::optional<std::string>(), std::make_shared<Microsoft::Featurizer::AnnotationMaps>(21));
size_t index(g_pointerTable.Add(pEstimator));
*ppHandle = reinterpret_cast<DateTimeFeaturizer_EstimatorHandle*>(index);
@ -59,8 +59,8 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_DestroyEstimator(/*in*/ DateTimeF
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
size_t index = reinterpret_cast<size_t>(pHandle);
Microsoft::Featurizer::Featurizers::DateTimeEstimator * pEstimator = sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(index);
sg_pointerTable.Remove(index);
Microsoft::Featurizer::Featurizers::DateTimeEstimator * pEstimator = g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(index);
g_pointerTable.Remove(index);
delete pEstimator;
@ -82,7 +82,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsTrainingComplete(/*in*/ DateTim
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
if(pIsTrainingComplete == nullptr) throw std::invalid_argument("'pIsTrainingComplete' is null");
Microsoft::Featurizer::Featurizers::DateTimeEstimator const & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator const & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
*pIsTrainingComplete = estimator.is_training_complete();
@ -108,7 +108,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_Fit(/*in*/ DateTimeFeaturizer_Est
// No validation
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
*pFitResult = static_cast<unsigned char>(estimator.fit(input));
@ -136,7 +136,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_FitBuffer(/*in*/ DateTimeFeaturiz
if(input_ptr == nullptr) throw std::invalid_argument("'input_ptr' is null");
if(input_items == 0) throw std::invalid_argument("'input_items' is 0");
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
*pFitResult = static_cast<unsigned char>(estimator.fit(input_ptr, input_items));
@ -160,7 +160,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CompleteTraining(/*in*/ DateTimeF
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pHandle)));
*pFitResult = static_cast<unsigned char>(estimator.complete_training());
@ -184,12 +184,12 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateTransformerFromEstimator(/*
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pEstimatorHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator>(reinterpret_cast<size_t>(pEstimatorHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType * pTransformer = reinterpret_cast<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType*>(estimator.create_transformer().release());
size_t index = sg_pointerTable.Add(pTransformer);
size_t index = g_pointerTable.Add(pTransformer);
*ppTransformerHandle = reinterpret_cast<DateTimeFeaturizer_TransformerHandle*>(index);
return true;
@ -215,7 +215,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateTransformerFromSavedData(/*
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType* pTransformer= (std::make_unique<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(archive).release());
size_t index = sg_pointerTable.Add(pTransformer);
size_t index = g_pointerTable.Add(pTransformer);
*ppTransformerHandle = reinterpret_cast<DateTimeFeaturizer_TransformerHandle*>(index);
return true;
@ -236,8 +236,8 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_DestroyTransformer(/*in*/ DateTim
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
size_t index = reinterpret_cast<size_t>(pHandle);
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType* pTransformer = sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(index);
sg_pointerTable.Remove(index);
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType* pTransformer = g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(index);
g_pointerTable.Remove(index);
delete pTransformer;
@ -261,7 +261,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateTransformerSaveData(/*in*/
if(ppBuffer == nullptr) throw std::invalid_argument("'ppBuffer' is null");
if(pBufferSize == nullptr) throw std::invalid_argument("'pBufferSize' is null");
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType & transformer(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType & transformer(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Archive archive;
transformer.save(archive);
@ -316,7 +316,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_Transform(/*in*/ DateTimeFeaturiz
// No input validation
if(output == nullptr) throw std::invalid_argument("'output' is null");
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType & transformer(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType & transformer(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(reinterpret_cast<size_t>(pHandle)));
// Input
auto result(transformer.execute(input));

Просмотреть файл

@ -46,7 +46,7 @@ struct DateTimeFeaturizer_EstimatorHandle {};
struct DateTimeFeaturizer_TransformerHandle {};
/* Training Methods */
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateEstimator(/*in*/ char const *optionalCountryName, /*out*/ DateTimeFeaturizer_EstimatorHandle **ppHandle, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateEstimator(/*in*/ char const *optionalCountryName, /*in*/ char const *optionalDataRootDir, /*out*/ DateTimeFeaturizer_EstimatorHandle **ppHandle, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_DestroyEstimator(/*in*/ DateTimeFeaturizer_EstimatorHandle *pHandle, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsTrainingComplete(/*in*/ DateTimeFeaturizer_EstimatorHandle *pHandle, /*out*/ bool *pIsTrainingComplete, /*out*/ ErrorInfoHandle **ppErrorInfo);

Просмотреть файл

@ -0,0 +1,16 @@
/* ---------------------------------------------------------------------- */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* Licensed under the MIT License */
/* ---------------------------------------------------------------------- */
#include "SharedLibrary_PointerTable.h"
#if (defined __clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
Microsoft::Featurizer::PointerTable g_pointerTable;
#if (defined __clang__)
# pragma clang diagnostic pop
#endif

Просмотреть файл

@ -6,13 +6,4 @@
#include "../PointerTable.h"
#if (defined __clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
static Microsoft::Featurizer::PointerTable sg_pointerTable;
#if (defined __clang__)
# pragma clang diagnostic pop
#endif
extern Microsoft::Featurizer::PointerTable g_pointerTable;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -34,6 +34,7 @@ TEST_CASE("Standard") {
return true;
},
nullptr,
nullptr
);
}
@ -43,22 +44,22 @@ TEST_CASE("IsValidCountry") {
bool result;
result = false;
CHECK(DateTimeFeaturizer_IsValidCountry("United States", &result, &pErrorInfo));
CHECK(DateTimeFeaturizer_IsValidCountry("United States", nullptr, &result, &pErrorInfo));
CHECK(pErrorInfo == nullptr);
CHECK(result);
result = false;
CHECK(DateTimeFeaturizer_IsValidCountry("united states", &result, &pErrorInfo));
CHECK(DateTimeFeaturizer_IsValidCountry("united states", nullptr, &result, &pErrorInfo));
CHECK(pErrorInfo == nullptr);
CHECK(result);
result = false;
CHECK(DateTimeFeaturizer_IsValidCountry("unitedstates", &result, &pErrorInfo));
CHECK(DateTimeFeaturizer_IsValidCountry("unitedstates", nullptr, &result, &pErrorInfo));
CHECK(pErrorInfo == nullptr);
CHECK(result);
result = true;
CHECK(DateTimeFeaturizer_IsValidCountry("not a valid country", &result, &pErrorInfo));
CHECK(DateTimeFeaturizer_IsValidCountry("not a valid country", nullptr, &result, &pErrorInfo));
CHECK(pErrorInfo == nullptr);
CHECK(result == false);
}
@ -68,7 +69,7 @@ TEST_CASE("GetSupportedCountries") {
StringBuffer * pStringBuffers(nullptr);
size_t numStringBuffers;
CHECK(DateTimeFeaturizer_GetSupportedCountries(&pStringBuffers, &numStringBuffers, &pErrorInfo));
CHECK(DateTimeFeaturizer_GetSupportedCountries(nullptr, &pStringBuffers, &numStringBuffers, &pErrorInfo));
CHECK(pErrorInfo == nullptr);
REQUIRE(pStringBuffers != nullptr);
REQUIRE(numStringBuffers != 0);

Просмотреть файл

@ -9,6 +9,8 @@
#define DLL_EXPORT_COMPILE
#include "SharedLibrary_DateTimeFeaturizerCustom.h"
#include "SharedLibrary_PointerTable.h"
#include "DateTimeFeaturizer.h"
// These method(s) are defined in SharedLibrary_Common.cpp
@ -16,17 +18,25 @@ ErrorInfoHandle * CreateErrorInfo(std::exception const &ex);
extern "C" {
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsValidCountry(/*in*/ char const *countryName, /*out*/ bool *isValid, /*out*/ ErrorInfoHandle **ppErrorInfo) {
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateTransformerFromSavedDataWithDataRoot(/*in*/ unsigned char const *pBuffer, /*in*/ std::size_t cBufferSize, /*in*/ char const *dataRootDir, /*out*/ DateTimeFeaturizer_TransformerHandle **ppTransformerHandle, /*out*/ ErrorInfoHandle **ppErrorInfo) {
if(ppErrorInfo == nullptr)
return false;
try {
*ppErrorInfo = nullptr;
if(countryName == nullptr) throw std::invalid_argument("'countryName' is null");
if(isValid == nullptr) throw std::invalid_argument("'isValid' is null");
if(pBuffer == nullptr) throw std::invalid_argument("'pBuffer' is null");
if(cBufferSize == 0) throw std::invalid_argument("'cBufferSize' is 0");
if(dataRootDir == nullptr) throw std::invalid_argument("'dataRootDir' is null");
*isValid = Microsoft::Featurizer::Featurizers::DateTimeEstimator::IsValidCountry(countryName);
if(ppTransformerHandle == nullptr) throw std::invalid_argument("'ppTransformerHandle' is null");
Microsoft::Featurizer::Archive archive(pBuffer, cBufferSize);
Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType* pTransformer= (std::make_unique<Microsoft::Featurizer::Featurizers::DateTimeEstimator::TransformerType>(archive, std::string(dataRootDir)).release());
size_t index = g_pointerTable.Add(pTransformer);
*ppTransformerHandle = reinterpret_cast<DateTimeFeaturizer_TransformerHandle*>(index);
return true;
}
@ -36,7 +46,27 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsValidCountry(/*in*/ char const
}
}
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_GetSupportedCountries(/*out*/ StringBuffer ** ppStringBuffers, /*out*/ std::size_t * pNumStringBuffers, /*out*/ ErrorInfoHandle **ppErrorInfo) {
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsValidCountry(/*in*/ char const *countryName, /*in*/ char const *optionalDataRootDir, /*out*/ bool *isValid, /*out*/ ErrorInfoHandle **ppErrorInfo) {
if(ppErrorInfo == nullptr)
return false;
try {
*ppErrorInfo = nullptr;
if(countryName == nullptr) throw std::invalid_argument("'countryName' is null");
if(isValid == nullptr) throw std::invalid_argument("'isValid' is null");
*isValid = Microsoft::Featurizer::Featurizers::DateTimeEstimator::IsValidCountry(countryName, optionalDataRootDir ? std::string(optionalDataRootDir) : nonstd::optional<std::string>());
return true;
}
catch(std::exception const &ex) {
*ppErrorInfo = CreateErrorInfo(ex);
return false;
}
}
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_GetSupportedCountries(/*in*/ char const *optionalDataRootDir, /*out*/ StringBuffer ** ppStringBuffers, /*out*/ std::size_t * pNumStringBuffers, /*out*/ ErrorInfoHandle **ppErrorInfo) {
if(ppErrorInfo == nullptr)
return false;
@ -46,7 +76,7 @@ FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_GetSupportedCountries(/*out*/ Str
if(ppStringBuffers == nullptr) throw std::invalid_argument("'ppStringBuffers' is null");
if(pNumStringBuffers == nullptr) throw std::invalid_argument("'pNumStringBuffers' is null");
std::vector<std::string> const countries(Microsoft::Featurizer::Featurizers::DateTimeEstimator::GetSupportedCountries());
std::vector<std::string> const countries(Microsoft::Featurizer::Featurizers::DateTimeEstimator::GetSupportedCountries(optionalDataRootDir ? std::string(optionalDataRootDir) : nonstd::optional<std::string>()));
if(countries.empty()) {
*ppStringBuffers = nullptr;

Просмотреть файл

@ -5,6 +5,7 @@
#pragma once
#include "SharedLibrary_Common.h"
#include "SharedLibrary_DateTimeFeaturizer.h"
extern "C" {
@ -19,8 +20,10 @@ struct StringBuffer {
FEATURIZER_LIBRARY_API_PACK_SUFFIX
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsValidCountry(/*in*/ char const *countryName, /*out*/ bool *isValid, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_GetSupportedCountries(/*out*/ StringBuffer ** ppStringBuffers, /*out*/ std::size_t * pNumStringBuffers, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_CreateTransformerFromSavedDataWithDataRoot(/*in*/ unsigned char const *pBuffer, /*in*/ std::size_t cBufferSize, /*in*/ char const *dataRootDir, /*out*/ DateTimeFeaturizer_TransformerHandle **ppTransformerHandle, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_IsValidCountry(/*in*/ char const *countryName, /*in*/ char const *optionalDataRootDir, /*out*/ bool *isValid, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_GetSupportedCountries(/*in*/ char const *optionalDataRootDir, /*out*/ StringBuffer ** ppStringBuffers, /*out*/ std::size_t * pNumStringBuffers, /*out*/ ErrorInfoHandle **ppErrorInfo);
FEATURIZER_LIBRARY_API bool DateTimeFeaturizer_DestroyStringBuffers(/*in*/ StringBuffer *pStringBuffer, /*in*/ std::size_t numStringBuffers, /*out*/ ErrorInfoHandle **ppErrorInfo);
} // extern "C"

Просмотреть файл

@ -187,7 +187,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_CreateEsti
)
);
size_t index(sg_pointerTable.Add(pMemory.get()));
size_t index(g_pointerTable.Add(pMemory.get()));
*ppHandle = reinterpret_cast<TimeSeriesImputerFeaturizer_BinaryArchive_EstimatorHandle *>(index);
@ -212,9 +212,9 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_DestroyEst
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
size_t index(reinterpret_cast<size_t>(pHandle));
EstimatorMemory * pEstimatorMemory(sg_pointerTable.Get<EstimatorMemory>(index));
EstimatorMemory * pEstimatorMemory(g_pointerTable.Get<EstimatorMemory>(index));
sg_pointerTable.Remove(index);
g_pointerTable.Remove(index);
delete pEstimatorMemory;
return true;
@ -235,7 +235,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_IsTraining
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
if(pIsTrainingComplete == nullptr) throw std::invalid_argument("'pIsTrainingComplete' is null");
EstimatorMemory const & memory(*sg_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
EstimatorMemory const & memory(*g_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
*pIsTrainingComplete = memory.Estimator.is_training_complete();
@ -259,7 +259,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_Fit(/*in*/
if(data.cBuffer == 0) throw std::invalid_argument("'data' buffer size is 0");
if(pFitResult == nullptr) throw std::invalid_argument("'pFitResult' is null");
EstimatorMemory & memory(*sg_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
EstimatorMemory & memory(*g_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
*pFitResult = static_cast<unsigned char>(memory.Estimator.fit(memory.Serializer.Deserialize(data.pBuffer, data.cBuffer)));
@ -287,7 +287,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_FitBuffer(
using InputTuples = std::vector<InputTuple>;
// ----------------------------------------------------------------------
EstimatorMemory & memory(*sg_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
EstimatorMemory & memory(*g_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
InputTuples input;
@ -319,7 +319,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_CompleteTr
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
EstimatorMemory & memory(*sg_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
EstimatorMemory & memory(*g_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pHandle)));
*pFitResult = static_cast<unsigned char>(memory.Estimator.complete_training());
@ -341,7 +341,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_CreateTran
if(pEstimatorHandle == nullptr) throw std::invalid_argument("'pEstimatorHandle' is null");
if(ppTransformerHandle == nullptr) throw std::invalid_argument("'ppTransformerHandle' is null");
EstimatorMemory & estimatorMemory(*sg_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pEstimatorHandle)));
EstimatorMemory & estimatorMemory(*g_pointerTable.Get<EstimatorMemory>(reinterpret_cast<size_t>(pEstimatorHandle)));
std::unique_ptr<TransformerMemory> pTransformerMemory(
std::make_unique<TransformerMemory>(
std::move(estimatorMemory.Serializer),
@ -349,7 +349,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_CreateTran
)
);
size_t index(sg_pointerTable.Add(pTransformerMemory.get()));
size_t index(g_pointerTable.Add(pTransformerMemory.get()));
*ppTransformerHandle = reinterpret_cast<TimeSeriesImputerFeaturizer_BinaryArchive_TransformerHandle *>(index);
@ -377,7 +377,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_CreateTran
Microsoft::Featurizer::Archive archive(pBuffer, cBufferSize);
std::unique_ptr<TransformerMemory> pTransformerMemory(std::make_unique<TransformerMemory>(archive));
size_t index(sg_pointerTable.Add(pTransformerMemory.get()));
size_t index(g_pointerTable.Add(pTransformerMemory.get()));
*ppTransformerHandle = reinterpret_cast<TimeSeriesImputerFeaturizer_BinaryArchive_TransformerHandle *>(index);
@ -402,9 +402,9 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_DestroyTra
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
size_t index(reinterpret_cast<size_t>(pHandle));
TransformerMemory * pTransformerMemory(sg_pointerTable.Get<TransformerMemory>(index));
TransformerMemory * pTransformerMemory(g_pointerTable.Get<TransformerMemory>(index));
sg_pointerTable.Remove(index);
g_pointerTable.Remove(index);
delete pTransformerMemory;
return true;
@ -426,7 +426,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_CreateTran
if(ppBuffer == nullptr) throw std::invalid_argument("'ppBuffer' is null");
if(pBufferSize == nullptr) throw std::invalid_argument("'pBufferSize' is null");
TransformerMemory & memory(*sg_pointerTable.Get<TransformerMemory>(reinterpret_cast<size_t>(pHandle)));
TransformerMemory & memory(*g_pointerTable.Get<TransformerMemory>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Archive archive;
memory.save(archive);
@ -481,7 +481,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_Transform(
if(ppData == nullptr) throw std::invalid_argument("'ppData' is null");
if(pNumDataElements == nullptr) throw std::invalid_argument("'pNumDataElements' is null");
TransformerMemory & memory(*sg_pointerTable.Get<TransformerMemory>(reinterpret_cast<size_t>(pHandle)));
TransformerMemory & memory(*g_pointerTable.Get<TransformerMemory>(reinterpret_cast<size_t>(pHandle)));
TransformedTuples results(memory.Transformer->execute(memory.Serializer.Deserialize(data.pBuffer, data.cBuffer)));
std::tie(*ppData, *pNumDataElements) = memory.Serializer.Serialize(results);
@ -505,7 +505,7 @@ FEATURIZER_LIBRARY_API bool TimeSeriesImputerFeaturizer_BinaryArchive_Flush(/*in
if(ppData == nullptr) throw std::invalid_argument("'ppData' is null");
if(pNumDataElements == nullptr) throw std::invalid_argument("'pNumDataElements' is null");
TransformerMemory & memory(*sg_pointerTable.Get<TransformerMemory>(reinterpret_cast<size_t>(pHandle)));
TransformerMemory & memory(*g_pointerTable.Get<TransformerMemory>(reinterpret_cast<size_t>(pHandle)));
// TODO assert(dynamic_cast<Microsoft::Featurizer::Featurizers::TimeSeriesImputerEstimator::Transformer *>(memory.Transformer.get()));
// TODO Microsoft::Featurizer::Featurizers::TimeSeriesImputerEstimator::Transformer & transformer(static_cast<Microsoft::Featurizer::Featurizers::TimeSeriesImputerEstimator::Transformer &>(*memory.Transformer));

Просмотреть файл

@ -42,6 +42,7 @@ add_library(Featurizers SHARED
${_this_path}/../GeneratedCode/SharedLibrary_DateTimeFeaturizer.h
${_this_path}/../GeneratedCode/SharedLibrary_DateTimeFeaturizer.cpp
${_this_path}/../GeneratedCode/SharedLibrary_PointerTable.h
${_this_path}/../GeneratedCode/SharedLibrary_PointerTable.cpp
${_this_path}/../GeneratedCode/SharedLibrary_StringFeaturizer.h
${_this_path}/../GeneratedCode/SharedLibrary_StringFeaturizer.cpp

Просмотреть файл

@ -35,6 +35,11 @@
"type": "std::string",
"name": "optionalCountryName",
"is_optional": true
},
{
"type": "std::string",
"name": "optionalDataRootDir",
"is_optional": true
}
],
"custom_structs": [

Просмотреть файл

@ -307,12 +307,27 @@ def _GenerateCommonFiles(output_dir, output_stream):
#include "../PointerTable.h"
extern Microsoft::Featurizer::PointerTable g_pointerTable;
""",
),
)
with open(os.path.join(output_dir, "SharedLibrary_PointerTable.cpp"), "w") as f:
f.write(
textwrap.dedent(
"""\
/* ---------------------------------------------------------------------- */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* Licensed under the MIT License */
/* ---------------------------------------------------------------------- */
#include "SharedLibrary_PointerTable.h"
#if (defined __clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
static Microsoft::Featurizer::PointerTable sg_pointerTable;
Microsoft::Featurizer::PointerTable g_pointerTable;
#if (defined __clang__)
# pragma clang diagnostic pop
@ -343,7 +358,7 @@ def _GenerateCommonFiles(output_dir, output_stream):
if(pHandle == nullptr || output_ptr == nullptr || output_items == nullptr)
return false;
std::string const & str(*sg_pointerTable.Get<std::string>(reinterpret_cast<size_t>(pHandle)));
std::string const & str(*g_pointerTable.Get<std::string>(reinterpret_cast<size_t>(pHandle)));
char * string_buffer(new char[str.size() + 1]);
@ -371,9 +386,9 @@ def _GenerateCommonFiles(output_dir, output_stream):
size_t index = reinterpret_cast<size_t>(pHandle);
std::string & str(*sg_pointerTable.Get<std::string>(index));
std::string & str(*g_pointerTable.Get<std::string>(index));
sg_pointerTable.Remove(index);
g_pointerTable.Remove(index);
delete &str;
@ -386,7 +401,7 @@ def _GenerateCommonFiles(output_dir, output_stream):
ErrorInfoHandle * CreateErrorInfo(std::exception const &ex) {
std::unique_ptr<std::string> result(std::make_unique<std::string>(ex.what()));
size_t index = sg_pointerTable.Add(result.release());
size_t index = g_pointerTable.Add(result.release());
return reinterpret_cast<ErrorInfoHandle *>(index);
}
@ -672,7 +687,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
{method_prefix}
{validation}
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}* pEstimator = new Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}({args}std::make_shared<Microsoft::Featurizer::AnnotationMaps>({num_output_columns}));
size_t index(sg_pointerTable.Add(pEstimator));
size_t index(g_pointerTable.Add(pEstimator));
*ppHandle = reinterpret_cast<{name}{suffix}EstimatorHandle*>(index);
@ -704,8 +719,8 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
size_t index = reinterpret_cast<size_t>(pHandle);
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} * pEstimator = sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(index);
sg_pointerTable.Remove(index);
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} * pEstimator = g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(index);
g_pointerTable.Remove(index);
delete pEstimator;
{method_suffix}
@ -724,7 +739,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
if(pIsTrainingComplete == nullptr) throw std::invalid_argument("'pIsTrainingComplete' is null");
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} const & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} const & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
*pIsTrainingComplete = estimator.is_training_complete();
@ -753,7 +768,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
{validation}
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
{statement}
@ -794,7 +809,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
{validation}
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
{statement}
{method_suffix}
@ -826,7 +841,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pHandle)));
*pFitResult = static_cast<unsigned char>(estimator.complete_training());
{method_suffix}
@ -847,12 +862,12 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pEstimatorHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix} & estimator(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}>(reinterpret_cast<size_t>(pEstimatorHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType * pTransformer = reinterpret_cast<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType*>(estimator.create_transformer().release());
size_t index = sg_pointerTable.Add(pTransformer);
size_t index = g_pointerTable.Add(pTransformer);
*ppTransformerHandle = reinterpret_cast<{name}{suffix}TransformerHandle*>(index);
{method_suffix}
}}
@ -875,7 +890,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType* pTransformer= (std::make_unique<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(archive).release());
size_t index = sg_pointerTable.Add(pTransformer);
size_t index = g_pointerTable.Add(pTransformer);
*ppTransformerHandle = reinterpret_cast<{name}{suffix}TransformerHandle*>(index);
{method_suffix}
}}
@ -893,8 +908,8 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
if(pHandle == nullptr) throw std::invalid_argument("'pHandle' is null");
size_t index = reinterpret_cast<size_t>(pHandle);
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType* pTransformer = sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(index);
sg_pointerTable.Remove(index);
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType* pTransformer = g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(index);
g_pointerTable.Remove(index);
delete pTransformer;
@ -915,7 +930,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
if(ppBuffer == nullptr) throw std::invalid_argument("'ppBuffer' is null");
if(pBufferSize == nullptr) throw std::invalid_argument("'pBufferSize' is null");
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType & transformer(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType & transformer(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Archive archive;
transformer.save(archive);
@ -972,7 +987,7 @@ def _GenerateCppFile(output_dir, items, c_data_items, output_stream):
{input_validation}
{output_validation}
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType & transformer(*sg_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(reinterpret_cast<size_t>(pHandle)));
Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType & transformer(*g_pointerTable.Get<Microsoft::Featurizer::Featurizers::{estimator_name}{cpp_template_suffix}::TransformerType>(reinterpret_cast<size_t>(pHandle)));
// Input
{input_statement}