[mlpack-git] master: Open .bin models in binary mode on Windows. (4ce2fc6)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Tue Nov 24 13:54:04 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/0dc380de64b6b087d025c63618b8d6f00abe7545...4f97fdfb7e158025283c2652084af670bc6e2d76
>---------------------------------------------------------------
commit 4ce2fc6557b8f05b871826d5aaf34013af6f2f8c
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Nov 24 13:44:51 2015 -0500
Open .bin models in binary mode on Windows.
>---------------------------------------------------------------
4ce2fc6557b8f05b871826d5aaf34013af6f2f8c
src/mlpack/core/data/load_impl.hpp | 13 +++++++++++--
src/mlpack/core/data/save_impl.hpp | 15 ++++++++++++---
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index 6c6b553..0fbe956 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -61,7 +61,7 @@ bool Load(const std::string& filename,
// Catch nonexistent files by opening the stream ourselves.
std::fstream stream;
-#ifdef _WIN32
+#ifdef _WIN32 // Always open in binary mode on Windows.
stream.open(filename.c_str(), std::fstream::in | std::fstream::binary);
#else
stream.open(filename.c_str(), std::fstream::in);
@@ -318,7 +318,16 @@ bool Load(const std::string& filename,
}
// Now load the given format.
- std::ifstream ifs(filename);
+ std::ifstream ifs;
+#ifdef _WIN32 // Open non-text in binary mode on Windows.
+ if (f == format::binary)
+ ifs.open(filename, std::ifstream::in | std::ifstream::binary);
+ else
+ ifs.open(filename, std::ifstream::in);
+#else
+ ifs.open(filename, std::ifstream::in);
+#endif
+
if (!ifs.is_open())
{
if (fatal)
diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp
index e84bda5..81ac0aa 100644
--- a/src/mlpack/core/data/save_impl.hpp
+++ b/src/mlpack/core/data/save_impl.hpp
@@ -46,8 +46,8 @@ bool Save(const std::string& filename,
// Catch errors opening the file.
std::fstream stream;
-#ifdef _WIN32
- stream.open(filename.c_str(), std::fstream::out| std::fstream::binary);
+#ifdef _WIN32 // Always open in binary mode on Windows.
+ stream.open(filename.c_str(), std::fstream::out | std::fstream::binary);
#else
stream.open(filename.c_str(), std::fstream::out);
#endif
@@ -201,7 +201,16 @@ bool Save(const std::string& filename,
}
// Open the file to save to.
- std::ofstream ofs(filename);
+ std::ofstream ofs;
+#ifdef _WIN32
+ if (f == format::binary) // Open non-text types in binary mode on Windows.
+ ofs.open(filename, std::ofstream::out | std::ofstream::binary);
+ else
+ ofs.open(filename, std::ofstream::out);
+#else
+ ofs.open(filename, std::ofstream::out);
+#endif
+
if (!ofs.is_open())
{
if (fatal)
More information about the mlpack-git
mailing list