ONE - On-device Neural Engine
Loading...
Searching...
No Matches
pepper-csv2vec.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "pepper/csv2vec.h"
18
19#include <algorithm>
20#include <sstream>
21#include <cassert>
22
23namespace pepper
24{
25
26template <> std::vector<std::string> csv_to_vector(const std::string &str)
27{
28 std::vector<std::string> ret;
29 std::istringstream is(str);
30 for (std::string item; std::getline(is, item, ',');)
31 {
32 ret.push_back(item);
33 }
34 return ret;
35}
36
37// TODO merge std::string and int32_t type
38
39template <> std::vector<int32_t> csv_to_vector(const std::string &str)
40{
41 std::vector<int32_t> ret;
42 std::istringstream is(str);
43 for (int32_t i; is >> i;)
44 {
45 assert(i != ',');
46 ret.push_back(i);
47 if (is.peek() == ',')
48 is.ignore();
49 }
50 return ret;
51}
52
53template <> bool is_one_of(const std::string &item, const std::vector<std::string> &items)
54{
55 return std::find(items.begin(), items.end(), item) != items.end();
56}
57
58} // namespace pepper
bool is_one_of(const T &item, const std::vector< T > &items)
std::vector< T > csv_to_vector(const std::string &str)