/usr/include/mlpack/core/util/save_restore_utility_impl.hpp is in libmlpack-dev 1.0.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | /**
* @file save_restore_utility_impl.hpp
* @author Neil Slagle
*
* The SaveRestoreUtility provides helper functions in saving and
* restoring models. The current output file type is XML.
*
* This file is part of MLPACK 1.0.10.
*
* MLPACK is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details (LICENSE.txt).
*
* You should have received a copy of the GNU General Public License along with
* MLPACK. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLPACK_CORE_UTIL_SAVE_RESTORE_UTILITY_IMPL_HPP
#define __MLPACK_CORE_UTIL_SAVE_RESTORE_UTILITY_IMPL_HPP
// In case it hasn't been included already.
#include "save_restore_utility.hpp"
#include "log.hpp"
namespace mlpack {
namespace util {
template<typename T>
T& SaveRestoreUtility::LoadParameter(T& t, const std::string& name)
{
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
{
std::string value = (*it).second;
std::istringstream input (value);
input >> t;
return t;
}
else
{
Log::Fatal << "LoadParameter(): node '" << name << "' not found.\n";
}
return t;
}
template<typename T>
std::vector<T>& SaveRestoreUtility::LoadParameter(std::vector<T>& v,
const std::string& name)
{
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
{
v.clear();
std::string value = (*it).second;
boost::char_separator<char> sep (",");
boost::tokenizer<boost::char_separator<char> > tok (value, sep);
std::list<std::list<double> > rows;
for (boost::tokenizer<boost::char_separator<char> >::iterator
tokIt = tok.begin();
tokIt != tok.end();
++tokIt)
{
T t;
std::istringstream iss (*tokIt);
iss >> t;
v.push_back(t);
}
}
else
{
Log::Fatal << "LoadParameter(): node '" << name << "' not found.\n";
}
return v;
}
template<typename T>
void SaveRestoreUtility::SaveParameter(const T& t, const std::string& name)
{
std::ostringstream output;
// Manually increase precision to solve #313 for now, until we have a way to
// store this as an actual binary number.
output << std::setprecision(15) << t;
parameters[name] = output.str();
}
template<typename T>
void SaveRestoreUtility::SaveParameter(const std::vector<T>& t,
const std::string& name)
{
std::ostringstream output;
for (size_t index = 0; index < t.size(); ++index)
{
output << t[index] << ",";
}
std::string vectorAsStr = output.str();
vectorAsStr.erase(vectorAsStr.length() - 1);
parameters[name] = vectorAsStr;
}
}; // namespace util
}; // namespace mlpack
#endif
|