Skip to content

Commit 0ca805e

Browse files
committed
More code style tweaks
1 parent 4a8ad63 commit 0ca805e

21 files changed

+83
-83
lines changed

NeuralNetwork.NET/APIs/DatasetLoader.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public static class DatasetLoader
6363
[PublicAPI]
6464
[Pure, NotNull]
6565
[CollectionAccess(CollectionAccessType.Read)]
66-
public static ITrainingDataset Training<TPixel>([NotNull] IEnumerable<(String X, float[] Y)> data, int size, ImageNormalizationMode normalization, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
66+
public static ITrainingDataset Training<TPixel>([NotNull] IEnumerable<(string X, float[] Y)> data, int size, ImageNormalizationMode normalization, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
6767
where TPixel : struct, IPixel<TPixel>
6868
{
6969
return BatchesCollection.From(modifiers.Length > 0
7070
? data.SelectMany(xy => modifiers.Select<Action<IImageProcessingContext<TPixel>>, Func<(float[], float[])>>(f => () => (ImageLoader.Load(xy.X, normalization, f), xy.Y)))
71-
: data.Select<(String X, float[] Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y)), size);
71+
: data.Select<(string X, float[] Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y)), size);
7272
}
7373

7474
/// <summary>
@@ -83,12 +83,12 @@ public static ITrainingDataset Training<TPixel>([NotNull] IEnumerable<(String X,
8383
[PublicAPI]
8484
[Pure, NotNull]
8585
[CollectionAccess(CollectionAccessType.Read)]
86-
public static ITrainingDataset Training<TPixel>([NotNull] IEnumerable<(String X, Func<float[]> Y)> data, int size, ImageNormalizationMode normalization, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
86+
public static ITrainingDataset Training<TPixel>([NotNull] IEnumerable<(string X, Func<float[]> Y)> data, int size, ImageNormalizationMode normalization, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
8787
where TPixel : struct, IPixel<TPixel>
8888
{
8989
return BatchesCollection.From(modifiers.Length > 0
9090
? data.SelectMany(xy => modifiers.Select<Action<IImageProcessingContext<TPixel>>, Func<(float[], float[])>>(f => () => (ImageLoader.Load(xy.X, normalization, f), xy.Y())))
91-
: data.Select<(String X, Func<float[]> Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y())), size);
91+
: data.Select<(string X, Func<float[]> Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y())), size);
9292
}
9393

9494
#endregion
@@ -144,13 +144,13 @@ public static IValidationDataset Validation([NotNull, ItemNotNull] IEnumerable<F
144144
[Pure, NotNull]
145145
[CollectionAccess(CollectionAccessType.Read)]
146146
public static IValidationDataset Validation<TPixel>(
147-
[NotNull] IEnumerable<(String X, float[] Y)> data, float tolerance = 1e-2f, int epochs = 5,
147+
[NotNull] IEnumerable<(string X, float[] Y)> data, float tolerance = 1e-2f, int epochs = 5,
148148
ImageNormalizationMode normalization = ImageNormalizationMode.Sigmoid, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
149149
where TPixel : struct, IPixel<TPixel>
150150
{
151151
return Validation((modifiers.Length > 0
152152
? data.SelectMany(xy => modifiers.Select<Action<IImageProcessingContext<TPixel>>, Func<(float[], float[])>>(f => () => (ImageLoader.Load(xy.X, normalization, f), xy.Y)))
153-
: data.Select<(String X, float[] Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y))).AsParallel(), tolerance, epochs);
153+
: data.Select<(string X, float[] Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y))).AsParallel(), tolerance, epochs);
154154
}
155155

156156
/// <summary>
@@ -167,13 +167,13 @@ public static IValidationDataset Validation<TPixel>(
167167
[Pure, NotNull]
168168
[CollectionAccess(CollectionAccessType.Read)]
169169
public static IValidationDataset Validation<TPixel>(
170-
[NotNull] IEnumerable<(String X, Func<float[]> Y)> data, float tolerance = 1e-2f, int epochs = 5,
170+
[NotNull] IEnumerable<(string X, Func<float[]> Y)> data, float tolerance = 1e-2f, int epochs = 5,
171171
ImageNormalizationMode normalization = ImageNormalizationMode.Sigmoid, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
172172
where TPixel : struct, IPixel<TPixel>
173173
{
174174
return Validation((modifiers.Length > 0
175175
? data.SelectMany(xy => modifiers.Select<Action<IImageProcessingContext<TPixel>>, Func<(float[], float[])>>(f => () => (ImageLoader.Load(xy.X, normalization, f), xy.Y())))
176-
: data.Select<(String X, Func<float[]> Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y()))).AsParallel(), tolerance, epochs);
176+
: data.Select<(string X, Func<float[]> Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y()))).AsParallel(), tolerance, epochs);
177177
}
178178

179179
#endregion
@@ -225,13 +225,13 @@ public static ITestDataset Test([NotNull, ItemNotNull] IEnumerable<Func<(float[]
225225
[Pure, NotNull]
226226
[CollectionAccess(CollectionAccessType.Read)]
227227
public static ITestDataset Test<TPixel>(
228-
[NotNull] IEnumerable<(String X, float[] Y)> data, [CanBeNull] Action<TrainingProgressEventArgs> progress = null
228+
[NotNull] IEnumerable<(string X, float[] Y)> data, [CanBeNull] Action<TrainingProgressEventArgs> progress = null
229229
, ImageNormalizationMode normalization = ImageNormalizationMode.Sigmoid, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
230230
where TPixel : struct, IPixel<TPixel>
231231
{
232232
return Test((modifiers.Length > 0
233233
? data.SelectMany(xy => modifiers.Select<Action<IImageProcessingContext<TPixel>>, Func<(float[], float[])>>(f => () => (ImageLoader.Load(xy.X, normalization, f), xy.Y)))
234-
: data.Select<(String X, float[] Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y))).AsParallel(), progress);
234+
: data.Select<(string X, float[] Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y))).AsParallel(), progress);
235235
}
236236

237237
/// <summary>
@@ -247,13 +247,13 @@ public static ITestDataset Test<TPixel>(
247247
[Pure, NotNull]
248248
[CollectionAccess(CollectionAccessType.Read)]
249249
public static ITestDataset Test<TPixel>(
250-
[NotNull] IEnumerable<(String X, Func<float[]> Y)> data, [CanBeNull] Action<TrainingProgressEventArgs> progress = null,
250+
[NotNull] IEnumerable<(string X, Func<float[]> Y)> data, [CanBeNull] Action<TrainingProgressEventArgs> progress = null,
251251
ImageNormalizationMode normalization = ImageNormalizationMode.Sigmoid, [NotNull, ItemNotNull] params Action<IImageProcessingContext<TPixel>>[] modifiers)
252252
where TPixel : struct, IPixel<TPixel>
253253
{
254254
return Test((modifiers.Length > 0
255255
? data.SelectMany(xy => modifiers.Select<Action<IImageProcessingContext<TPixel>>, Func<(float[], float[])>>(f => () => (ImageLoader.Load(xy.X, normalization, f), xy.Y())))
256-
: data.Select<(String X, Func<float[]> Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y()))).AsParallel(), progress);
256+
: data.Select<(string X, Func<float[]> Y), Func<(float[], float[])>>(xy => () => (ImageLoader.Load<TPixel>(xy.X, normalization, null), xy.Y()))).AsParallel(), progress);
257257
}
258258

259259
#endregion

NeuralNetwork.NET/APIs/Datasets/Cifar10.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public static class Cifar10
3131
// A single 32*32 image
3232
private const int ImageSize = 1024;
3333

34-
private const String DatasetURL = "https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz";
34+
private const string DatasetURL = "https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz";
3535

3636
[NotNull, ItemNotNull]
37-
private static readonly IReadOnlyList<String> TrainingBinFilenames = Enumerable.Range(1, 5).Select(i => $"data_batch_{i}.bin").ToArray();
37+
private static readonly IReadOnlyList<string> TrainingBinFilenames = Enumerable.Range(1, 5).Select(i => $"data_batch_{i}.bin").ToArray();
3838

39-
private const String TestBinFilename = "test_batch.bin";
39+
private const string TestBinFilename = "test_batch.bin";
4040

4141
#endregion
4242

@@ -50,7 +50,7 @@ public static class Cifar10
5050
[Pure, ItemCanBeNull]
5151
public static async Task<ITrainingDataset> GetTrainingDatasetAsync(int size, [CanBeNull] IProgress<HttpProgress> callback = null, CancellationToken token = default)
5252
{
53-
IReadOnlyDictionary<String, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
53+
IReadOnlyDictionary<string, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
5454
if (map == null) return null;
5555
IReadOnlyList<(float[], float[])>[] data = new IReadOnlyList<(float[], float[])>[TrainingBinFilenames.Count];
5656
Parallel.For(0, TrainingBinFilenames.Count, i => data[i] = ParseSamples(map[TrainingBinFilenames[i]], TrainingSamplesInBinFiles)).AssertCompleted();
@@ -67,7 +67,7 @@ public static async Task<ITrainingDataset> GetTrainingDatasetAsync(int size, [Ca
6767
[Pure, ItemCanBeNull]
6868
public static async Task<ITestDataset> GetTestDatasetAsync([CanBeNull] Action<TrainingProgressEventArgs> progress = null, [CanBeNull] IProgress<HttpProgress> callback = null, CancellationToken token = default)
6969
{
70-
IReadOnlyDictionary<String, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
70+
IReadOnlyDictionary<string, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
7171
if (map == null) return null;
7272
IReadOnlyList<(float[], float[])> data = ParseSamples(map[TestBinFilename], TrainingSamplesInBinFiles);
7373
return DatasetLoader.Test(data, progress);
@@ -81,7 +81,7 @@ public static async Task<ITestDataset> GetTestDatasetAsync([CanBeNull] Action<Tr
8181
[PublicAPI]
8282
public static async Task<bool> ExportDatasetAsync([NotNull] DirectoryInfo directory, CancellationToken token = default)
8383
{
84-
IReadOnlyDictionary<String, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, null, token);
84+
IReadOnlyDictionary<string, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, null, token);
8585
if (map == null) return false;
8686
if (!directory.Exists) directory.Create();
8787
ParallelLoopResult result = Parallel.ForEach(TrainingBinFilenames.Concat(new[] { TestBinFilename }), (name, state) =>
@@ -137,7 +137,7 @@ public static async Task<bool> ExportDatasetAsync([NotNull] DirectoryInfo direct
137137
/// <param name="source">The source filename and a <see cref="Func{TResult}"/> that returns the <see cref="Stream"/> to read</param>
138138
/// <param name="count">The number of samples to parse</param>
139139
/// <param name="token">A token for the operation</param>
140-
private static unsafe void ExportSamples([NotNull] DirectoryInfo folder, (String Name, Func<Stream> Factory) source, int count, CancellationToken token)
140+
private static unsafe void ExportSamples([NotNull] DirectoryInfo folder, (string Name, Func<Stream> Factory) source, int count, CancellationToken token)
141141
{
142142
using (Stream stream = source.Factory())
143143
{

NeuralNetwork.NET/APIs/Datasets/Cifar100.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public static class Cifar100
3737

3838
private const int FineLabels = 100;
3939

40-
private const String DatasetURL = "https://www.cs.toronto.edu/~kriz/cifar-100-binary.tar.gz";
40+
private const string DatasetURL = "https://www.cs.toronto.edu/~kriz/cifar-100-binary.tar.gz";
4141

42-
private const String TrainingBinFilename = "train.bin";
42+
private const string TrainingBinFilename = "train.bin";
4343

44-
private const String TestBinFilename = "test.bin";
44+
private const string TestBinFilename = "test.bin";
4545

4646
#endregion
4747

@@ -56,7 +56,7 @@ public static class Cifar100
5656
[Pure, ItemCanBeNull]
5757
public static async Task<ITrainingDataset> GetTrainingDatasetAsync(int size, Cifar100ClassificationMode mode = Cifar100ClassificationMode.Fine, [CanBeNull] IProgress<HttpProgress> callback = null, CancellationToken token = default)
5858
{
59-
IReadOnlyDictionary<String, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
59+
IReadOnlyDictionary<string, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
6060
if (map == null) return null;
6161
IReadOnlyList<(float[], float[])> data = ParseSamples(map[TrainingBinFilename], TrainingSamplesInBinFile, mode);
6262
return DatasetLoader.Training(data, size);
@@ -75,7 +75,7 @@ public static async Task<ITestDataset> GetTestDatasetAsync(
7575
[CanBeNull] Action<TrainingProgressEventArgs> progress = null, Cifar100ClassificationMode mode = Cifar100ClassificationMode.Fine,
7676
[CanBeNull] IProgress<HttpProgress> callback = null, CancellationToken token = default)
7777
{
78-
IReadOnlyDictionary<String, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
78+
IReadOnlyDictionary<string, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, callback, token);
7979
if (map == null) return null;
8080
IReadOnlyList<(float[], float[])> data = ParseSamples(map[TestBinFilename], TestSamplesInBinFile, mode);
8181
return DatasetLoader.Test(data, progress);
@@ -89,10 +89,10 @@ public static async Task<ITestDataset> GetTestDatasetAsync(
8989
[PublicAPI]
9090
public static async Task<bool> ExportDatasetAsync([NotNull] DirectoryInfo directory, CancellationToken token = default)
9191
{
92-
IReadOnlyDictionary<String, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, null, token);
92+
IReadOnlyDictionary<string, Func<Stream>> map = await DatasetsDownloader.GetArchiveAsync(DatasetURL, null, token);
9393
if (map == null) return false;
9494
if (!directory.Exists) directory.Create();
95-
ParallelLoopResult result = Parallel.ForEach(new (String Name, int Count)[]
95+
ParallelLoopResult result = Parallel.ForEach(new (string Name, int Count)[]
9696
{
9797
(TrainingBinFilename, TrainingSamplesInBinFile),
9898
(TestBinFilename, TestSamplesInBinFile)
@@ -173,7 +173,7 @@ public static async Task<bool> ExportDatasetAsync([NotNull] DirectoryInfo direct
173173
/// <param name="source">The source filename and a <see cref="Func{TResult}"/> that returns the <see cref="Stream"/> to read</param>
174174
/// <param name="count">The number of samples to parse</param>
175175
/// <param name="token">A token for the operation</param>
176-
private static unsafe void ExportSamples([NotNull] DirectoryInfo folder, (String Name, Func<Stream> Factory) source, int count, CancellationToken token)
176+
private static unsafe void ExportSamples([NotNull] DirectoryInfo folder, (string Name, Func<Stream> Factory) source, int count, CancellationToken token)
177177
{
178178
using (Stream stream = source.Factory())
179179
{

NeuralNetwork.NET/APIs/Datasets/Mnist.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public static class Mnist
2929

3030
private const int SampleSize = 784;
3131

32-
private const String MnistHttpRootPath = "http://yann.lecun.com/exdb/mnist/";
32+
private const string MnistHttpRootPath = "http://yann.lecun.com/exdb/mnist/";
3333

34-
private const String TrainingSetValuesFilename = "train-images-idx3-ubyte.gz";
34+
private const string TrainingSetValuesFilename = "train-images-idx3-ubyte.gz";
3535

36-
private const String TrainingSetLabelsFilename = "train-labels-idx1-ubyte.gz";
36+
private const string TrainingSetLabelsFilename = "train-labels-idx1-ubyte.gz";
3737

38-
private const String TestSetValuesFilename = "t10k-images-idx3-ubyte.gz";
38+
private const string TestSetValuesFilename = "t10k-images-idx3-ubyte.gz";
3939

40-
private const String TestSetLabelsFilename = "t10k-labels-idx1-ubyte.gz";
40+
private const string TestSetLabelsFilename = "t10k-labels-idx1-ubyte.gz";
4141

4242
#endregion
4343

@@ -94,7 +94,7 @@ public static async Task<bool> ExportDatasetAsync([NotNull] DirectoryInfo direct
9494
DatasetsDownloader.GetFileAsync($"{MnistHttpRootPath}{TestSetLabelsFilename}", null, token));
9595
if (factories.Any(s => s == null) || token.IsCancellationRequested) return false;
9696
if (!directory.Exists) directory.Create();
97-
ParallelLoopResult result = Parallel.ForEach(new (String Name, Func<Stream> X, Func<Stream> Y, int Count)[]
97+
ParallelLoopResult result = Parallel.ForEach(new (string Name, Func<Stream> X, Func<Stream> Y, int Count)[]
9898
{
9999
(TrainingSetValuesFilename, factories[0], factories[1], TrainingSamples),
100100
(TestSetValuesFilename, factories[2], factories[3], TestSamples)
@@ -153,7 +153,7 @@ private static unsafe (float[,], float[,]) ParseSamples((Func<Stream> X, Func<St
153153
/// <param name="source">A pair of factories for the input <see cref="Stream"/> instances to read</param>
154154
/// <param name="count">The number of samples to parse</param>
155155
/// <param name="token">A token for the operation</param>
156-
private static unsafe void ExportSamples([NotNull] DirectoryInfo folder, (String Name, Func<Stream> X, Func<Stream> Y) source, int count, CancellationToken token)
156+
private static unsafe void ExportSamples([NotNull] DirectoryInfo folder, (string Name, Func<Stream> X, Func<Stream> Y) source, int count, CancellationToken token)
157157
{
158158
using (Stream inputs = source.X(), labels = source.Y())
159159
using (GZipStream

NeuralNetwork.NET/APIs/Interfaces/INeuralNetwork.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public interface INeuralNetwork : IEquatable<INeuralNetwork>, IClonable<INeuralN
122122
/// Serializes the network metadata as a JSON string
123123
/// </summary>
124124
[Pure, NotNull]
125-
String SerializeMetadataAsJson();
125+
string SerializeMetadataAsJson();
126126

127127
/// <summary>
128128
/// Saves the network to the target file

NeuralNetwork.NET/APIs/Results/TrainingSessionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public sealed class TrainingSessionResult
4444
/// Serializes the current instance as a JSON string with all the current training info
4545
/// </summary>
4646
[Pure, NotNull]
47-
public String SerializeAsJson() => JsonConvert.SerializeObject(this, Formatting.Indented, new StringEnumConverter());
47+
public string SerializeAsJson() => JsonConvert.SerializeObject(this, Formatting.Indented, new StringEnumConverter());
4848

4949
// Internal constructor
5050
internal TrainingSessionResult(

NeuralNetwork.NET/Exceptions/ComputationGraphBuildException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace NeuralNetworkNET.Exceptions
88
/// </summary>
99
public sealed class ComputationGraphBuildException : ArgumentException
1010
{
11-
internal ComputationGraphBuildException([NotNull] String message) : base(message) { }
11+
internal ComputationGraphBuildException([NotNull] string message) : base(message) { }
1212
}
1313
}

NeuralNetwork.NET/Exceptions/NetworkBuildException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace NeuralNetworkNET.Exceptions
88
/// </summary>
99
public sealed class NetworkBuildException : ArgumentException
1010
{
11-
internal NetworkBuildException([NotNull] String message) : base(message) { }
11+
internal NetworkBuildException([NotNull] string message) : base(message) { }
1212

13-
internal NetworkBuildException([NotNull] String message, [NotNull] String param) : base(message, param) { }
13+
internal NetworkBuildException([NotNull] string message, [NotNull] string param) : base(message, param) { }
1414
}
1515
}

0 commit comments

Comments
 (0)