Remove SplitAndParseAsFloats from tensorflow::strings API.
The function is very specific, and has limited use. PiperOrigin-RevId: 262782380
This commit is contained in:
parent
24c5f4741e
commit
6e7facf58c
@ -20,6 +20,7 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/core/lib/core/status_test_util.h"
|
||||
#include "tensorflow/core/lib/io/path.h"
|
||||
#include "tensorflow/core/lib/strings/numbers.h"
|
||||
#include "tensorflow/core/lib/strings/str_util.h"
|
||||
#include "tensorflow/core/lib/wav/wav_io.h"
|
||||
#include "tensorflow/core/platform/env.h"
|
||||
@ -162,7 +163,12 @@ void ReadCSVFileToArrayOrDie(const string& filename,
|
||||
std::vector<float> values;
|
||||
for (int l = 0; l < lines.size(); ++l) {
|
||||
values.clear();
|
||||
CHECK(str_util::SplitAndParseAsFloats(lines[l], ',', &values));
|
||||
std::vector<string> split_line = str_util::Split(lines[l], ",");
|
||||
for (const string& token : split_line) {
|
||||
float tmp;
|
||||
CHECK(strings::safe_strtof(token, &tmp));
|
||||
values.push_back(tmp);
|
||||
}
|
||||
array->push_back(values);
|
||||
}
|
||||
}
|
||||
|
@ -228,16 +228,6 @@ bool SplitAndParseAsInts(StringPiece text, char delim,
|
||||
return SplitAndParseAsInts<int64>(text, delim, strings::safe_strto64, result);
|
||||
}
|
||||
|
||||
bool SplitAndParseAsFloats(StringPiece text, char delim,
|
||||
std::vector<float>* result) {
|
||||
return SplitAndParseAsInts<float>(
|
||||
text, delim,
|
||||
[](StringPiece str, float* value) {
|
||||
return strings::safe_strtof(str, value);
|
||||
},
|
||||
result);
|
||||
}
|
||||
|
||||
size_t Strnlen(const char* str, const size_t string_max_len) {
|
||||
size_t len = 0;
|
||||
while (len < string_max_len && str[len] != '\0') {
|
||||
|
@ -154,8 +154,6 @@ bool SplitAndParseAsInts(StringPiece text, char delim,
|
||||
std::vector<int32>* result);
|
||||
bool SplitAndParseAsInts(StringPiece text, char delim,
|
||||
std::vector<int64>* result);
|
||||
bool SplitAndParseAsFloats(StringPiece text, char delim,
|
||||
std::vector<float>* result);
|
||||
|
||||
// StartsWith()
|
||||
//
|
||||
|
@ -314,31 +314,6 @@ TEST(SplitAndParseAsInts, Int64) {
|
||||
EXPECT_FALSE(str_util::SplitAndParseAsInts("13,abc,5", ',', &nums));
|
||||
}
|
||||
|
||||
TEST(SplitAndParseAsFloats, Float) {
|
||||
std::vector<float> nums;
|
||||
EXPECT_TRUE(str_util::SplitAndParseAsFloats("", ',', &nums));
|
||||
EXPECT_EQ(nums.size(), 0);
|
||||
|
||||
EXPECT_TRUE(str_util::SplitAndParseAsFloats("134.2323", ',', &nums));
|
||||
ASSERT_EQ(nums.size(), 1);
|
||||
EXPECT_NEAR(nums[0], 134.2323f, 1e-5f);
|
||||
|
||||
EXPECT_TRUE(str_util::SplitAndParseAsFloats("134.9,2.123,13.0000,-5.999,1e6",
|
||||
',', &nums));
|
||||
ASSERT_EQ(nums.size(), 5);
|
||||
EXPECT_NEAR(nums[0], 134.9f, 1e-5f);
|
||||
EXPECT_NEAR(nums[1], 2.123f, 1e-5f);
|
||||
EXPECT_NEAR(nums[2], 13.0f, 1e-5f);
|
||||
EXPECT_NEAR(nums[3], -5.999f, 1e-5f);
|
||||
EXPECT_NEAR(nums[4], 1e6f, 1e1f);
|
||||
|
||||
EXPECT_FALSE(str_util::SplitAndParseAsFloats("abc", ',', &nums));
|
||||
|
||||
EXPECT_FALSE(str_util::SplitAndParseAsFloats("-13.0,abc", ',', &nums));
|
||||
|
||||
EXPECT_FALSE(str_util::SplitAndParseAsFloats("13.0,abc,-5.999", ',', &nums));
|
||||
}
|
||||
|
||||
TEST(Lowercase, Basic) {
|
||||
EXPECT_EQ("", str_util::Lowercase(""));
|
||||
EXPECT_EQ("hello", str_util::Lowercase("hello"));
|
||||
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
@ -31,6 +32,7 @@ limitations under the License.
|
||||
#include "tensorflow/core/lib/core/stringpiece.h"
|
||||
#include "tensorflow/core/lib/core/threadpool.h"
|
||||
#include "tensorflow/core/lib/io/path.h"
|
||||
#include "tensorflow/core/lib/strings/numbers.h"
|
||||
#include "tensorflow/core/lib/strings/str_util.h"
|
||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
||||
#include "tensorflow/core/platform/init_main.h"
|
||||
@ -59,9 +61,11 @@ Status ReadLocationsFile(const string& file_name, std::vector<float>* result,
|
||||
result->clear();
|
||||
string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::vector<float> tokens;
|
||||
CHECK(tensorflow::str_util::SplitAndParseAsFloats(line, ',', &tokens));
|
||||
for (auto number : tokens) {
|
||||
std::vector<string> string_tokens = tensorflow::str_util::Split(line, ',');
|
||||
result->reserve(string_tokens.size());
|
||||
for (const string& string_token : string_tokens) {
|
||||
float number;
|
||||
CHECK(tensorflow::strings::safe_strtof(string_token, &number));
|
||||
result->push_back(number);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ limitations under the License.
|
||||
#include "tensorflow/core/graph/algorithm.h"
|
||||
#include "tensorflow/core/graph/graph.h"
|
||||
#include "tensorflow/core/graph/graph_constructor.h"
|
||||
#include "tensorflow/core/lib/strings/numbers.h"
|
||||
#include "tensorflow/core/lib/strings/str_util.h"
|
||||
#include "tensorflow/core/lib/strings/strcat.h"
|
||||
#include "tensorflow/core/platform/env.h"
|
||||
@ -546,10 +547,17 @@ int Main(int argc, char** argv) {
|
||||
}
|
||||
input.name = input_layers[n];
|
||||
if (n < input_layer_values.size()) {
|
||||
CHECK(str_util::SplitAndParseAsFloats(input_layer_values[n], ',',
|
||||
&input.initialization_values))
|
||||
std::vector<string> string_tokens =
|
||||
str_util::Split(input_layer_values[n], ',');
|
||||
input.initialization_values.clear();
|
||||
input.initialization_values.reserve(string_tokens.size());
|
||||
for (const string& str_val : string_tokens) {
|
||||
float val;
|
||||
CHECK(strings::safe_strtof(str_val, &val))
|
||||
<< "Incorrect initialization values string specified: "
|
||||
<< input_layer_values[n];
|
||||
input.initialization_values.push_back(val);
|
||||
}
|
||||
}
|
||||
inputs.push_back(input);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user