Skip to content

Commit d23efdb

Browse files
committed
Invariant culture parsing
Eliminates problems with parsing on localization-specific OSs
1 parent 0e866fa commit d23efdb

File tree

2 files changed

+262
-18
lines changed

2 files changed

+262
-18
lines changed

.gitignore

+243
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.userosscache
8+
*.sln.docstates
9+
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
13+
# Build results
14+
[Dd]ebug/
15+
[Dd]ebugPublic/
16+
[Rr]elease/
17+
[Rr]eleases/
18+
x64/
19+
x86/
20+
bld/
21+
[Bb]in/
22+
[Oo]bj/
23+
[Ll]og/
24+
25+
# Visual Studio 2015 cache/options directory
26+
.vs/
27+
# Uncomment if you have tasks that create the project's static files in wwwroot
28+
#wwwroot/
29+
30+
# MSTest test Results
31+
[Tt]est[Rr]esult*/
32+
[Bb]uild[Ll]og.*
33+
34+
# NUNIT
35+
*.VisualState.xml
36+
TestResult.xml
37+
38+
# Build Results of an ATL Project
39+
[Dd]ebugPS/
40+
[Rr]eleasePS/
41+
dlldata.c
42+
43+
# DNX
44+
project.lock.json
45+
artifacts/
46+
47+
*_i.c
48+
*_p.c
49+
*_i.h
50+
*.ilk
51+
*.meta
52+
*.obj
53+
*.pch
54+
*.pdb
55+
*.pgc
56+
*.pgd
57+
*.rsp
58+
*.sbr
59+
*.tlb
60+
*.tli
61+
*.tlh
62+
*.tmp
63+
*.tmp_proj
64+
*.log
65+
*.vspscc
66+
*.vssscc
67+
.builds
68+
*.pidb
69+
*.svclog
70+
*.scc
71+
72+
# Chutzpah Test files
73+
_Chutzpah*
74+
75+
# Visual C++ cache files
76+
ipch/
77+
*.aps
78+
*.ncb
79+
*.opendb
80+
*.opensdf
81+
*.sdf
82+
*.cachefile
83+
84+
# Visual Studio profiler
85+
*.psess
86+
*.vsp
87+
*.vspx
88+
*.sap
89+
90+
# TFS 2012 Local Workspace
91+
$tf/
92+
93+
# Guidance Automation Toolkit
94+
*.gpState
95+
96+
# ReSharper is a .NET coding add-in
97+
_ReSharper*/
98+
*.[Rr]e[Ss]harper
99+
*.DotSettings.user
100+
101+
# JustCode is a .NET coding add-in
102+
.JustCode
103+
104+
# TeamCity is a build add-in
105+
_TeamCity*
106+
107+
# DotCover is a Code Coverage Tool
108+
*.dotCover
109+
110+
# NCrunch
111+
_NCrunch_*
112+
.*crunch*.local.xml
113+
nCrunchTemp_*
114+
115+
# MightyMoose
116+
*.mm.*
117+
AutoTest.Net/
118+
119+
# Web workbench (sass)
120+
.sass-cache/
121+
122+
# Installshield output folder
123+
[Ee]xpress/
124+
125+
# DocProject is a documentation generator add-in
126+
DocProject/buildhelp/
127+
DocProject/Help/*.HxT
128+
DocProject/Help/*.HxC
129+
DocProject/Help/*.hhc
130+
DocProject/Help/*.hhk
131+
DocProject/Help/*.hhp
132+
DocProject/Help/Html2
133+
DocProject/Help/html
134+
135+
# Click-Once directory
136+
publish/
137+
138+
# Publish Web Output
139+
*.[Pp]ublish.xml
140+
*.azurePubxml
141+
# TODO: Comment the next line if you want to checkin your web deploy settings
142+
# but database connection strings (with potential passwords) will be unencrypted
143+
*.pubxml
144+
*.publishproj
145+
146+
# NuGet Packages
147+
*.nupkg
148+
# The packages folder can be ignored because of Package Restore
149+
**/packages/*
150+
# except build/, which is used as an MSBuild target.
151+
!**/packages/build/
152+
# Uncomment if necessary however generally it will be regenerated when needed
153+
#!**/packages/repositories.config
154+
# NuGet v3's project.json files produces more ignoreable files
155+
*.nuget.props
156+
*.nuget.targets
157+
158+
# Microsoft Azure Build Output
159+
csx/
160+
*.build.csdef
161+
162+
# Microsoft Azure Emulator
163+
ecf/
164+
rcf/
165+
166+
# Microsoft Azure ApplicationInsights config file
167+
ApplicationInsights.config
168+
169+
# Windows Store app package directories and files
170+
AppPackages/
171+
BundleArtifacts/
172+
Package.StoreAssociation.xml
173+
_pkginfo.txt
174+
175+
# Visual Studio cache files
176+
# files ending in .cache can be ignored
177+
*.[Cc]ache
178+
# but keep track of directories ending in .cache
179+
!*.[Cc]ache/
180+
181+
# Others
182+
ClientBin/
183+
~$*
184+
*~
185+
*.dbmdl
186+
*.dbproj.schemaview
187+
*.pfx
188+
*.publishsettings
189+
node_modules/
190+
orleans.codegen.cs
191+
192+
# RIA/Silverlight projects
193+
Generated_Code/
194+
195+
# Backup & report files from converting an old project file
196+
# to a newer Visual Studio version. Backup files are not needed,
197+
# because we have git ;-)
198+
_UpgradeReport_Files/
199+
Backup*/
200+
UpgradeLog*.XML
201+
UpgradeLog*.htm
202+
203+
# SQL Server files
204+
*.mdf
205+
*.ldf
206+
207+
# Business Intelligence projects
208+
*.rdl.data
209+
*.bim.layout
210+
*.bim_*.settings
211+
212+
# Microsoft Fakes
213+
FakesAssemblies/
214+
215+
# GhostDoc plugin setting file
216+
*.GhostDoc.xml
217+
218+
# Node.js Tools for Visual Studio
219+
.ntvs_analysis.dat
220+
221+
# Visual Studio 6 build log
222+
*.plg
223+
224+
# Visual Studio 6 workspace options file
225+
*.opt
226+
227+
# Visual Studio LightSwitch build output
228+
**/*.HTMLClient/GeneratedArtifacts
229+
**/*.DesktopClient/GeneratedArtifacts
230+
**/*.DesktopClient/ModelManifest.xml
231+
**/*.Server/GeneratedArtifacts
232+
**/*.Server/ModelManifest.xml
233+
_Pvt_Extensions
234+
235+
# Paket dependency manager
236+
.paket/paket.exe
237+
238+
# FAKE - F# Make
239+
.fake/
240+
241+
# JetBrains Rider
242+
.idea/
243+
*.sln.iml

RNNSharpConsole/Program.cs

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Text;
45
using System.IO;
56
using RNNSharp;
67
using AdvUtils;
78

8-
/// <summary>
9-
/// RNNSharp written by Zhongkai Fu ([email protected])
10-
/// </summary>
119
namespace RNNSharpConsole
1210
{
11+
/// <summary>
12+
/// RNNSharp written by Zhongkai Fu ([email protected])
13+
/// </summary>
1314
class Program
1415
{
1516
static string strModelFile = "";
@@ -149,43 +150,43 @@ static void InitParameters(string[] args)
149150
string[] layers = args[i + 1].Split(',');
150151
foreach (string layer in layers)
151152
{
152-
layersize.Add(int.Parse(layer));
153+
layersize.Add(int.Parse(layer, CultureInfo.InvariantCulture));
153154
}
154155
}
155156
else
156157
{
157158
layersize.Add(200);
158159
}
159160

160-
if ((i = ArgPos("-modeltype", args)) >= 0) modelType = int.Parse(args[i + 1]);
161-
if ((i = ArgPos("-crf", args)) >= 0) iCRF = int.Parse(args[i + 1]);
162-
if ((i = ArgPos("-maxiter", args)) >= 0) maxIter = int.Parse(args[i + 1]);
163-
if ((i = ArgPos("-alpha", args)) >= 0) alpha = float.Parse(args[i + 1]);
164-
if ((i = ArgPos("-dropout", args)) >= 0) dropout = float.Parse(args[i + 1]);
165-
if ((i = ArgPos("-bptt", args)) >= 0) bptt = int.Parse(args[i + 1]);
166-
if ((i = ArgPos("-nbest", args)) >= 0) nBest = int.Parse(args[i + 1]);
167-
if ((i = ArgPos("-dir", args)) >= 0) iDir = int.Parse(args[i + 1]);
168-
if ((i = ArgPos("-vq", args)) >= 0) iVQ = int.Parse(args[i + 1]);
169-
if ((i = ArgPos("-grad", args)) >= 0) gradientCutoff = float.Parse(args[i + 1]);
161+
if ((i = ArgPos("-modeltype", args)) >= 0) modelType = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
162+
if ((i = ArgPos("-crf", args)) >= 0) iCRF = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
163+
if ((i = ArgPos("-maxiter", args)) >= 0) maxIter = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
164+
if ((i = ArgPos("-alpha", args)) >= 0) alpha = float.Parse(args[i + 1], CultureInfo.InvariantCulture);
165+
if ((i = ArgPos("-dropout", args)) >= 0) dropout = float.Parse(args[i + 1], CultureInfo.InvariantCulture);
166+
if ((i = ArgPos("-bptt", args)) >= 0) bptt = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
167+
if ((i = ArgPos("-nbest", args)) >= 0) nBest = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
168+
if ((i = ArgPos("-dir", args)) >= 0) iDir = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
169+
if ((i = ArgPos("-vq", args)) >= 0) iVQ = int.Parse(args[i + 1], CultureInfo.InvariantCulture);
170+
if ((i = ArgPos("-grad", args)) >= 0) gradientCutoff = float.Parse(args[i + 1], CultureInfo.InvariantCulture);
170171

171172
if ((i = ArgPos("-savestep", args)) >= 0)
172173
{
173174
string str = args[i + 1].ToLower();
174175
if (str.EndsWith("k") == true)
175176
{
176-
savestep = long.Parse(str.Substring(0, str.Length - 1)) * 1024;
177+
savestep = long.Parse(str.Substring(0, str.Length - 1), CultureInfo.InvariantCulture) * 1024;
177178
}
178179
else if (str.EndsWith("m") == true)
179180
{
180-
savestep = long.Parse(str.Substring(0, str.Length - 1)) * 1024 * 1024;
181+
savestep = long.Parse(str.Substring(0, str.Length - 1), CultureInfo.InvariantCulture) * 1024 * 1024;
181182
}
182183
else if (str.EndsWith("g") == true)
183184
{
184-
savestep = long.Parse(str.Substring(0, str.Length - 1)) * 1024 * 1024 * 1024;
185+
savestep = long.Parse(str.Substring(0, str.Length - 1), CultureInfo.InvariantCulture) * 1024 * 1024 * 1024;
185186
}
186187
else
187188
{
188-
savestep = long.Parse(str);
189+
savestep = long.Parse(str, CultureInfo.InvariantCulture);
189190
}
190191
}
191192

0 commit comments

Comments
 (0)