minor GCC break fixes in cn.cpp;

changed wsprintf() in ComputationNode.h to sprintf()
This commit is contained in:
Frank Seide 2014-11-04 14:14:45 -08:00
Родитель ba4a881916
Коммит 4ab6c1e766
6 изменённых файлов: 50 добавлений и 48 удалений

Просмотреть файл

@ -548,7 +548,9 @@ static inline const char *strerror_(int e)
if (msgs.find(e) == msgs.end()) { char msg[1024]; strerror_s (msg, e); msgs[e] = msg; }
return msgs[e].c_str();
}
#endif
#ifdef __unix__
extern int fileno(FILE*); // somehow got deprecated in C++11
#endif
// ----------------------------------------------------------------------------

Просмотреть файл

@ -160,10 +160,6 @@ FILE * fopenOrDie (const wstring & pathname, const wchar_t * mode)
// set mode to binary or text (pass 'b' or 't')
// ----------------------------------------------------------------------------
#ifdef __unix__
extern int fileno(FILE*); // somehow got deprecated in C++11
#endif
void fsetmode(FILE * f, char type)
{
if (type != 'b' && type != 't')

Просмотреть файл

@ -176,9 +176,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
virtual void DumpNodeInfo(const bool /*printValues*/, File& fstream) const
{
wchar_t str[4096];
wsprintf(str, L"\n%ws=%ws", NodeName().c_str(), OperationName().c_str());
fstream << wstring(str);
fstream << NodeName() + L"=" + OperationName();
if (!IsLeaf())
{
@ -187,8 +185,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
{
if (i > 0)
fstream << wstring(L",");
wsprintf(str, L"%ws", Inputs(i)?Inputs(i)->NodeName().c_str():L"NULL");
fstream << wstring(str);
fstream << (Inputs(i) ? Inputs(i)->NodeName().c_str() : L"NULL");
}
fstream << wstring(L")");
}
@ -960,11 +957,11 @@ protected: \
{
ComputationNode<ElemType>::DumpNodeInfo(printValues, fstream);
wchar_t str[4096];
wsprintf(str, L"[%lu,%lu] ", FunctionValues().GetNumRows(), FunctionValues().GetNumCols());
fstream << wstring(str);
wsprintf(str, L"NeedGradient=%ws", NeedGradient()? L"true" : L"false");
fstream << wstring(str);
char str[4096];
sprintf(str, "[%lu,%lu] ", FunctionValues().GetNumRows(), FunctionValues().GetNumCols());
fstream << string(str);
sprintf(str, "NeedGradient=%s", NeedGradient()? "true" : "false");
fstream << string(str);
PrintNodeValuesToFile(printValues, fstream);
}
@ -1123,9 +1120,9 @@ protected: \
{
ComputationNode<ElemType>::DumpNodeInfo(printValues, fstream);
wchar_t str[4096];
wsprintf(str, L"[%lu,%lu]", FunctionValues().GetNumRows(), FunctionValues().GetNumCols());
fstream << wstring(str);
char str[4096];
sprintf(str, "[%lu,%lu]", FunctionValues().GetNumRows(), FunctionValues().GetNumCols());
fstream << string(str);
}
// copy constructor
@ -1250,9 +1247,9 @@ protected: \
{
ComputationNode<ElemType>::DumpNodeInfo(printValues, fstream);
wchar_t str[4096];
wsprintf(str, L"[%lu,%lu]", FunctionValues().GetNumRows(), FunctionValues().GetNumCols());
fstream << wstring(str);
char str[4096];
sprintf(str, "[%lu,%lu]", FunctionValues().GetNumRows(), FunctionValues().GetNumCols());
fstream << string(str);
}
// copy constructor

Просмотреть файл

@ -7,6 +7,7 @@
#include "ComputationNetwork.h"
#include "ComputationNetworkHelper.h"
#include "SimpleEvaluator.h"
#include "DataReader.h"
#include <vector>
#include <string>
@ -555,21 +556,21 @@ namespace Microsoft { namespace MSR { namespace CNTK {
auto t_end_epoch = clock();
ElemType epochTime = ElemType(1.0)*(t_end_epoch-t_start_epoch)/(CLOCKS_PER_SEC);
fprintf(stderr,"Finished Epoch[%lu]: [Training Set] Train Loss Per Sample = %.8g ", i+1, epochCriterion);
if (epochEvalErrors.size()==1)
{
fprintf(stderr,"EvalErr Per Sample = %.8g Ave Learn Rate Per Sample = %.10g Epoch Time=%.8g\n", epochEvalErrors[0], learnRatePerSample, epochTime);
}
else
{
fprintf(stderr,"EvalErr Per Sample ");
for (size_t j=0; j<epochEvalErrors.size(); j++)
fprintf(stderr,"[%lu]=%.8g ", j, epochEvalErrors[j]);
fprintf(stderr,"Ave Learn Rate Per Sample = %.10g Epoch Time=%.8g\n",learnRatePerSample, epochTime);
fprintf(stderr,"Finished Epoch[%lu]: Criterion Node [%ws] Per Sample = %.8g\n",i+1,criterionNodes[0]->NodeName().c_str() ,epochCriterion);
for (size_t j=0; j<epochEvalErrors.size(); j++)
fprintf(stderr,"Finished Epoch[%lu]: Evaluation Node [%ws] Per Sample = %.8g\n",i+1,evalNodeNames[j].c_str(),epochEvalErrors[j]);
}
fprintf(stderr, "Finished Epoch[%lu]: [Training Set] Train Loss Per Sample = %.8g ", i + 1, epochCriterion);
if (epochEvalErrors.size() == 1)
{
fprintf(stderr, "EvalErr Per Sample = %.8g Ave Learn Rate Per Sample = %.10g Epoch Time=%.8g\n", epochEvalErrors[0], learnRatePerSample, epochTime);
}
else
{
fprintf(stderr, "EvalErr Per Sample ");
for (size_t j = 0; j < epochEvalErrors.size(); j++)
fprintf(stderr, "[%lu]=%.8g ", j, epochEvalErrors[j]);
fprintf(stderr, "Ave Learn Rate Per Sample = %.10g Epoch Time=%.8g\n", learnRatePerSample, epochTime);
fprintf(stderr, "Finished Epoch[%lu]: Criterion Node [%ws] Per Sample = %.8g\n", i + 1, criterionNodes[0]->NodeName().c_str(), epochCriterion);
for (size_t j = 0; j < epochEvalErrors.size(); j++)
fprintf(stderr, "Finished Epoch[%lu]: Evaluation Node [%ws] Per Sample = %.8g\n", i + 1, evalNodeNames[j].c_str(), epochEvalErrors[j]);
}
if (validationSetDataReader != trainSetDataReader && validationSetDataReader != nullptr)
{
@ -579,8 +580,8 @@ namespace Microsoft { namespace MSR { namespace CNTK {
cvSetTrainAndEvalNodes.push_back(evaluationNodes[0]->NodeName());
vector<ElemType> vScore = evalforvalidation.Evaluate(*validationSetDataReader, cvSetTrainAndEvalNodes, m_mbSize[i]);
fprintf(stderr,"Finished Epoch[%lu]: [Validation Set] Train Loss Per Sample = %.8g EvalErr Per Sample = %.8g\n",
i+1, vScore[0], vScore[1]);
fprintf(stderr, "Finished Epoch[%lu]: [Validation Set] Train Loss Per Sample = %.8g EvalErr Per Sample = %.8g\n",
i + 1, vScore[0], vScore[1]);
epochCriterion = vScore[0]; //the first one is the training criterion.
}

Просмотреть файл

@ -237,7 +237,11 @@ namespace Microsoft { namespace MSR { namespace CNTK {
ofstream outputStream;
if (output)
{
#ifdef _MSC_VER
outputStream.open(output);
#else
outputStream.open(charpath(output)); // GCC does not implement wide-char pathnames here
#endif
}
size_t numMBsRun = 0;

Просмотреть файл

@ -6,6 +6,8 @@
// cn.cpp : Defines the entry point for the console application.
//
#define _CRT_NONSTDC_NO_DEPRECATE // make VS accept POSIX functions without _
#include "stdafx.h"
#include "ComputationNetwork.h"
#include "ComputationNode.h"
@ -42,11 +44,19 @@ void RedirectStdErr(wstring logpath)
fprintf (stderr, "Redirecting stderr to file %S\n", logpath.c_str());
msra::files::make_intermediate_dirs (logpath);
auto_file_ptr f (logpath.c_str(), "wb");
if (_dup2 (_fileno (f), 2) == -1)
if (dup2 (fileno (f), 2) == -1)
RuntimeError ("unexpected failure to redirect stderr to log file");
setvbuf (stderr, NULL, _IONBF, 16384); // unbuffer it
}
std::string WCharToString(const wchar_t* wst)
{
std::wstring ws(wst);
std::string s(ws.begin(), ws.end());
s.assign(ws.begin(), ws.end());
return s;
}
template <typename ElemType>
void DumpNodeInfo(const ConfigParameters& config)
{
@ -549,14 +559,6 @@ std::string TimeDateStamp()
return s;
}
std::string WCharToString(const wchar_t* wst)
{
std::wstring ws(wst);
std::string s(ws.begin(), ws.end());
s.assign(ws.begin(), ws.end());
return s;
}
int wmain(int argc, wchar_t* argv[])
{
try
@ -573,7 +575,7 @@ int wmain(int argc, wchar_t* argv[])
for (int i=0; i < command.size(); i++)
{
logpath += L"_";
logpath += command[i];
logpath += (wstring)command[i];
}
logpath += L".log";
RedirectStdErr(logpath);