From cd92de1ba3ad29d681b58b833dea3717e8ffefb1 Mon Sep 17 00:00:00 2001 From: Taku Kudo Date: Wed, 3 Aug 2022 15:45:09 +0900 Subject: [PATCH] remove unused ifdef SWIG macro Signed-off-by: Kentaro Hayashi Gbp-Pq: Name 0015-remove-unused-ifdef-SWIG-macro.patch --- python/src/sentencepiece/sentencepiece.i | 5 +++ src/sentencepiece_processor.h | 42 ++++++++++++++---------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/python/src/sentencepiece/sentencepiece.i b/python/src/sentencepiece/sentencepiece.i index f3a4f30..75f62c8 100644 --- a/python/src/sentencepiece/sentencepiece.i +++ b/python/src/sentencepiece/sentencepiece.i @@ -326,6 +326,8 @@ inline void InitNumThreads(const std::vector &ins, int *num_threads) { %ignore sentencepiece::SentencePieceProcessor::model_proto; %ignore sentencepiece::SentencePieceProcessor::Load; %ignore sentencepiece::SentencePieceProcessor::LoadOrDie; +%ignore sentencepiece::SentencePieceProcessor::SetModel; +%ignore sentencepiece::SentencePieceProcessor::SetNormalizer; %ignore sentencepiece::pretokenizer::PretokenizerForTrainingInterface; %ignore sentencepiece::SentenceIterator; %ignore sentencepiece::ConvertToUnicodeSpans; @@ -339,6 +341,9 @@ inline void InitNumThreads(const std::vector &ins, int *num_threads) { %ignore sentencepiece::SentencePieceTrainer::SetPretokenizerForTraining; %ignore sentencepiece::SentencePieceTrainer::GetPretokenizerForTraining; +%ignore sentencepiece::io::LoadModelProto; +%ignore sentencepiece::io::SaveModelProto; + %extend sentencepiece::SentencePieceProcessor { sentencepiece::util::Status LoadFromFile(absl::string_view arg) { return $self->Load(arg); diff --git a/src/sentencepiece_processor.h b/src/sentencepiece_processor.h index d107a2a..be9449e 100644 --- a/src/sentencepiece_processor.h +++ b/src/sentencepiece_processor.h @@ -26,7 +26,7 @@ namespace absl { using std::string_view; } // namespace absl -#endif +#endif // SWIG namespace sentencepiece { namespace util { @@ -420,36 +420,46 @@ class SentencePieceProcessor { virtual util::Status Decode(const std::vector &ids, SentencePieceText *spt) const; -#ifdef SWIGPYTHON -#define CONVERT_TO_UNICODE_SPAN output.ConvertToUnicodeSpans(); -#define SPP_SWIG_CHECK_AND_THROW \ - if (!status.ok()) throw status; +#ifndef SWIGPYTHON + +#define DEFINE_SPP_DIRECT_FUNC_IMPL(FuncName, OutType, ...) \ + OutType output; \ + const auto status = FuncName(__VA_ARGS__, &output); \ + return output; + +#define DEFINE_SPP_SERIALIZED_PROTO_IMPL(FuncName, OutType, ...) \ + OutType output; \ + const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \ + return output.SerializeAsString(); + +#define DEFINE_SPP_IMMUTABLE_PROTO_IMPL(FuncName, OutType, ...) \ + OutType output; \ + const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \ + return output; + #else -#define CONVERT_TO_UNICODE_SPAN -#define SPP_SWIG_CHECK_AND_THROW \ - if (!status.ok()) { \ - } -#endif // SWIGPYTHON #define DEFINE_SPP_DIRECT_FUNC_IMPL(FuncName, OutType, ...) \ OutType output; \ const auto status = FuncName(__VA_ARGS__, &output); \ - SPP_SWIG_CHECK_AND_THROW; \ + if (!status.ok()) throw status; \ return output; #define DEFINE_SPP_SERIALIZED_PROTO_IMPL(FuncName, OutType, ...) \ OutType output; \ const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \ - SPP_SWIG_CHECK_AND_THROW; \ + if (!status.ok()) throw status; \ return output.SerializeAsString(); #define DEFINE_SPP_IMMUTABLE_PROTO_IMPL(FuncName, OutType, ...) \ OutType output; \ const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \ - CONVERT_TO_UNICODE_SPAN; \ - SPP_SWIG_CHECK_AND_THROW; \ + if (!status.ok()) throw status; \ + output.ConvertToUnicodeSpans(); \ return output; +#endif // SWIGPYTHON + ////////////////////////////////////////////////////////////// // Handy methods that return the result directly. // These functions ignore internal errors. @@ -664,7 +674,6 @@ class SentencePieceProcessor { // Returns PAD () id. virtual int pad_id() const; -#ifndef SWIG ////////////////////////////////////////////////////////////// // Model management. // @@ -673,7 +682,6 @@ class SentencePieceProcessor { // Allows injection of a normalizer instance. `normalizer` is moved. void SetNormalizer(std::unique_ptr &&normalizer); -#endif // SWIG // Returns immutable model proto. Useful to obtain extended // or experimental parameters encoded in model_proto. @@ -715,7 +723,6 @@ class SentencePieceProcessor { // std::random_device. void SetRandomGeneratorSeed(unsigned int seed); -#ifndef SWIG // IO related functions to absorb model formats. namespace io { // Loads `model_proto` from `filename`. @@ -730,6 +737,5 @@ util::Status LoadModelProto(absl::string_view, ModelProto *model_proto); // Saves `model_proto` as `filename`. util::Status SaveModelProto(absl::string_view, const ModelProto &model_proto); } // namespace io -#endif // SWIG } // namespace sentencepiece #endif // SENTENCEPIECE_PROCESSOR_H_ -- 2.30.2