12 #ifndef MLPACK_CORE_DATA_MAP_POLICIES_INCREMENT_POLICY_HPP 13 #define MLPACK_CORE_DATA_MAP_POLICIES_INCREMENT_POLICY_HPP 16 #include <unordered_map> 17 #include <boost/bimap.hpp> 48 template <
typename MapType>
50 const size_t dimension,
52 std::vector<Datatype>& types)
57 if (maps.count(dimension) == 0 ||
58 maps[dimension].first.left.count(
string) == 0)
61 size_t& numMappings = maps[dimension].second;
67 typedef boost::bimap<std::string, MappedType>::value_type PairType;
68 maps[dimension].first.insert(PairType(
string, numMappings));
74 return maps[dimension].first.left.at(
string);
93 template <
typename eT,
typename MapType>
94 void MapTokens(
const std::vector<std::string>& tokens,
96 arma::Mat<eT>& matrix,
98 std::vector<Datatype>& types)
103 std::stringstream token;
109 const bool notNumeric = std::any_of(std::begin(tokens),
110 std::end(tokens), notNumber);
113 for (
size_t i = 0; i != tokens.size(); ++i)
115 const eT val =
static_cast<eT
>(this->
MapString(tokens[i], row, maps,
117 matrix.at(row, i) = val;
122 std::stringstream token;
123 for (
size_t i = 0; i != tokens.size(); ++i)
125 token.str(tokens[i]);
126 token >> matrix.at(row, i);
IncrementPolicy is used as a helper class for DatasetMapper.
MappedType MapString(const std::string &string, const size_t dimension, MapType &maps, std::vector< Datatype > &types)
Given the string and the dimension to which the it belongs, and the maps and types given by the Datas...
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
void MapTokens(const std::vector< std::string > &tokens, size_t &row, arma::Mat< eT > &matrix, MapType &maps, std::vector< Datatype > &types)
MapTokens turns vector of strings into numeric variables and puts them into a given matrix...