From cf32506bb263dfd20b13cda6cd7aeebe2bf7fa5b Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 1 Nov 2018 10:09:50 -0500 Subject: [PATCH] Mark UInt128 and other obvious readonly structs as readonly. --- src/Microsoft.ML.Core/CommandLine/CmdParser.cs | 2 +- .../ComponentModel/ComponentCatalog.cs | 2 +- src/Microsoft.ML.Core/Data/IHostEnvironment.cs | 2 +- src/Microsoft.ML.Core/Data/RoleMappedSchema.cs | 2 +- src/Microsoft.ML.Core/Data/UInt128.cs | 2 +- src/Microsoft.ML.Core/Utilities/BinFinder.cs | 2 +- src/Microsoft.ML.Core/Utilities/Contracts.cs | 2 +- src/Microsoft.ML.Core/Utilities/MinWaiter.cs | 2 +- src/Microsoft.ML.Core/Utilities/OrderedWaiter.cs | 2 +- src/Microsoft.ML.Core/Utilities/Random.cs | 2 +- .../Utilities/SupervisedBinFinder.cs | 2 +- .../Commands/CrossValidationCommand.cs | 2 +- src/Microsoft.ML.Data/Commands/TypeInfoCommand.cs | 2 +- src/Microsoft.ML.Data/Data/DataViewUtils.cs | 2 +- .../DataLoadSave/Binary/BinarySaver.cs | 4 ++-- .../DataLoadSave/Binary/BlockLookup.cs | 2 +- .../DataLoadSave/CompositeDataLoader.cs | 2 +- .../DataLoadSave/Text/TextLoaderCursor.cs | 4 ++-- src/Microsoft.ML.Data/DataView/CacheDataView.cs | 12 ++++++------ src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs | 2 +- .../Evaluators/AnomalyDetectionEvaluator.cs | 2 +- src/Microsoft.ML.Data/Model/Pfa/PfaContext.cs | 6 +++--- src/Microsoft.ML.Data/Prediction/Calibrator.cs | 4 ++-- .../StaticPipe/StaticPipeInternalUtils.cs | 2 +- src/Microsoft.ML.Data/Transforms/InvertHashUtils.cs | 2 +- .../Transforms/ValueToKeyMappingEstimator.cs | 2 +- src/Microsoft.ML.FastTree/Dataset/Dataset.cs | 2 +- src/Microsoft.ML.FastTree/Dataset/FeatureFlock.cs | 2 +- .../SymSgdClassificationTrainer.cs | 2 +- src/Microsoft.ML.Maml/HelpCommand.cs | 2 +- .../ColumnGroupingInference.cs | 2 +- .../ColumnTypeInference.cs | 4 ++-- .../PurposeInference.cs | 4 ++-- .../RecipeInference.cs | 4 ++-- .../TextFileContents.cs | 2 +- .../TransformInference.cs | 6 +++--- .../Optimizer/Optimizer.cs | 2 +- .../Standard/LinearClassificationTrainer.cs | 2 +- .../Standard/ModelStatistics.cs | 2 +- .../CategoricalHashTransform.cs | 2 +- src/Microsoft.ML.Transforms/CategoricalTransform.cs | 2 +- src/Microsoft.ML.Transforms/NAReplaceTransform.cs | 2 +- src/Microsoft.ML.Transforms/RffTransform.cs | 2 +- src/Microsoft.ML.Transforms/UngroupTransform.cs | 2 +- .../Helpers/DiagnosticResult.cs | 2 +- test/Microsoft.ML.TestFramework/BaseTestBaseline.cs | 2 +- 46 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/Microsoft.ML.Core/CommandLine/CmdParser.cs b/src/Microsoft.ML.Core/CommandLine/CmdParser.cs index ba8d92f10c..37fd791358 100644 --- a/src/Microsoft.ML.Core/CommandLine/CmdParser.cs +++ b/src/Microsoft.ML.Core/CommandLine/CmdParser.cs @@ -924,7 +924,7 @@ private IEnumerable> GetSettingPairsCore(IHostEnvir } } - private struct ArgumentHelpStrings + private readonly struct ArgumentHelpStrings { public readonly string Syntax; public readonly string Help; diff --git a/src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs b/src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs index c8b5a87492..d0ab610a60 100644 --- a/src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs +++ b/src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs @@ -45,7 +45,7 @@ public sealed class LoadableClassInfo /// /// Used for dictionary lookup based on signature and name. /// - internal struct Key : IEquatable + internal readonly struct Key : IEquatable { public readonly string Name; public readonly Type Signature; diff --git a/src/Microsoft.ML.Core/Data/IHostEnvironment.cs b/src/Microsoft.ML.Core/Data/IHostEnvironment.cs index eaf33576dc..eaae1b5ca8 100644 --- a/src/Microsoft.ML.Core/Data/IHostEnvironment.cs +++ b/src/Microsoft.ML.Core/Data/IHostEnvironment.cs @@ -176,7 +176,7 @@ public enum MessageSensitivity /// /// A channel message. /// - public struct ChannelMessage + public readonly struct ChannelMessage { public readonly ChannelMessageKind Kind; public readonly MessageSensitivity Sensitivity; diff --git a/src/Microsoft.ML.Core/Data/RoleMappedSchema.cs b/src/Microsoft.ML.Core/Data/RoleMappedSchema.cs index bcf8b1e213..27aae01c0c 100644 --- a/src/Microsoft.ML.Core/Data/RoleMappedSchema.cs +++ b/src/Microsoft.ML.Core/Data/RoleMappedSchema.cs @@ -114,7 +114,7 @@ public sealed class RoleMappedSchema /// be used when possible for consistency reasons. However, practitioners should not be afraid to declare custom /// roles if approppriate for their task. /// - public struct ColumnRole + public readonly struct ColumnRole { /// /// Role for features. Commonly used as the independent variables given to trainers, and scorers. diff --git a/src/Microsoft.ML.Core/Data/UInt128.cs b/src/Microsoft.ML.Core/Data/UInt128.cs index 2c033d58be..017068a65d 100644 --- a/src/Microsoft.ML.Core/Data/UInt128.cs +++ b/src/Microsoft.ML.Core/Data/UInt128.cs @@ -11,7 +11,7 @@ namespace Microsoft.ML.Runtime.Data /// /// A sixteen-byte unsigned integer. /// - public struct UInt128 : IComparable, IEquatable + public readonly struct UInt128 : IComparable, IEquatable { // The low order bits. Corresponds to H1 in the Murmur algorithms. public readonly ulong Lo; diff --git a/src/Microsoft.ML.Core/Utilities/BinFinder.cs b/src/Microsoft.ML.Core/Utilities/BinFinder.cs index 7d348af1a0..5cd7fd2a61 100644 --- a/src/Microsoft.ML.Core/Utilities/BinFinder.cs +++ b/src/Microsoft.ML.Core/Utilities/BinFinder.cs @@ -282,7 +282,7 @@ public sealed class GreedyBinFinder : BinFinderBase { // Potential drop location for another peg, together with its energy improvement. // PlacePegs uses a heap of these. Note that this is a struct so size matters. - private struct Segment + private readonly struct Segment { public readonly int Min; public readonly int Split; diff --git a/src/Microsoft.ML.Core/Utilities/Contracts.cs b/src/Microsoft.ML.Core/Utilities/Contracts.cs index eb371bfff3..671bf41db8 100644 --- a/src/Microsoft.ML.Core/Utilities/Contracts.cs +++ b/src/Microsoft.ML.Core/Utilities/Contracts.cs @@ -167,7 +167,7 @@ public static MessageSensitivity Sensitivity(this Exception ex) /// there will be performance implications. There shouldn't be, since checks rarely happen in /// tight loops. /// - private struct SensitiveExceptionContext : IExceptionContext + private readonly struct SensitiveExceptionContext : IExceptionContext { /// /// We will run this instances first. diff --git a/src/Microsoft.ML.Core/Utilities/MinWaiter.cs b/src/Microsoft.ML.Core/Utilities/MinWaiter.cs index 8c44315ba6..42ddf0c69c 100644 --- a/src/Microsoft.ML.Core/Utilities/MinWaiter.cs +++ b/src/Microsoft.ML.Core/Utilities/MinWaiter.cs @@ -28,7 +28,7 @@ public sealed class MinWaiter /// is the minimum at a point when all waiters have registered, the event /// will be signaled. /// - private struct WaitStats + private readonly struct WaitStats { public readonly long Line; public readonly ManualResetEventSlim Event; diff --git a/src/Microsoft.ML.Core/Utilities/OrderedWaiter.cs b/src/Microsoft.ML.Core/Utilities/OrderedWaiter.cs index 2356ee6640..e3e118d8bf 100644 --- a/src/Microsoft.ML.Core/Utilities/OrderedWaiter.cs +++ b/src/Microsoft.ML.Core/Utilities/OrderedWaiter.cs @@ -23,7 +23,7 @@ public sealed class OrderedWaiter /// This is an event-line pair. The intended usage is, when the line /// is hit by the containing ordered waiter, the thread will be hit. /// - private struct WaitStats + private readonly struct WaitStats { public readonly long Line; public readonly ManualResetEventSlim Event; diff --git a/src/Microsoft.ML.Core/Utilities/Random.cs b/src/Microsoft.ML.Core/Utilities/Random.cs index 7b1b14c974..d5bbf2d4ec 100644 --- a/src/Microsoft.ML.Core/Utilities/Random.cs +++ b/src/Microsoft.ML.Core/Utilities/Random.cs @@ -150,7 +150,7 @@ public int NextSigned() /// public sealed class TauswortheHybrid : IRandom { - public struct State + public readonly struct State { public readonly uint U1; public readonly uint U2; diff --git a/src/Microsoft.ML.Core/Utilities/SupervisedBinFinder.cs b/src/Microsoft.ML.Core/Utilities/SupervisedBinFinder.cs index a87400bd19..bb76952c25 100644 --- a/src/Microsoft.ML.Core/Utilities/SupervisedBinFinder.cs +++ b/src/Microsoft.ML.Core/Utilities/SupervisedBinFinder.cs @@ -22,7 +22,7 @@ namespace Microsoft.ML.Runtime.Internal.Utilities /// public sealed class SupervisedBinFinder { - private struct ValuePair : IComparable> + private readonly struct ValuePair : IComparable> where T : IComparable { public readonly T Value; diff --git a/src/Microsoft.ML.Data/Commands/CrossValidationCommand.cs b/src/Microsoft.ML.Data/Commands/CrossValidationCommand.cs index 48272a85f8..24b84d38c1 100644 --- a/src/Microsoft.ML.Data/Commands/CrossValidationCommand.cs +++ b/src/Microsoft.ML.Data/Commands/CrossValidationCommand.cs @@ -354,7 +354,7 @@ private bool TryGetOverallMetrics(Dictionary[] metrics, out L private sealed class FoldHelper { - public struct FoldResult + public readonly struct FoldResult { public readonly Dictionary Metrics; public readonly Schema ScoreSchema; diff --git a/src/Microsoft.ML.Data/Commands/TypeInfoCommand.cs b/src/Microsoft.ML.Data/Commands/TypeInfoCommand.cs index 3a940b1681..79c3295017 100644 --- a/src/Microsoft.ML.Data/Commands/TypeInfoCommand.cs +++ b/src/Microsoft.ML.Data/Commands/TypeInfoCommand.cs @@ -36,7 +36,7 @@ public TypeInfoCommand(IHostEnvironment env, Arguments args) _host.CheckValue(args, nameof(args)); } - private struct TypeNaInfo + private readonly struct TypeNaInfo { public readonly bool HasNa; public readonly bool DefaultIsNa; diff --git a/src/Microsoft.ML.Data/Data/DataViewUtils.cs b/src/Microsoft.ML.Data/Data/DataViewUtils.cs index 5c5dff3d72..0e33390c7e 100644 --- a/src/Microsoft.ML.Data/Data/DataViewUtils.cs +++ b/src/Microsoft.ML.Data/Data/DataViewUtils.cs @@ -1154,7 +1154,7 @@ internal sealed class SynchronousConsolidatingCursor : RootCursorBase, IRowCurso private IRowCursor _currentCursor; private bool _disposed; - private struct CursorStats + private readonly struct CursorStats { public readonly long Batch; public readonly int CursorIdx; diff --git a/src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs b/src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs index b4854070e5..2b434e8e3c 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/Binary/BinarySaver.cs @@ -63,7 +63,7 @@ public sealed class Arguments /// This is a simple struct to associate a source index with a codec, without having to have /// parallel structures everywhere. /// - private struct ColumnCodec + private readonly struct ColumnCodec { public readonly int SourceIndex; public readonly IValueCodec Codec; @@ -149,7 +149,7 @@ public override MemoryStream EndBlock() /// also have a dual usage if is non-null of indicating /// a source worker threw an exception. /// - private struct Block + private readonly struct Block { /// /// Take one guess. diff --git a/src/Microsoft.ML.Data/DataLoadSave/Binary/BlockLookup.cs b/src/Microsoft.ML.Data/DataLoadSave/Binary/BlockLookup.cs index c4c6159cbb..c5b1571f5a 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/Binary/BlockLookup.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/Binary/BlockLookup.cs @@ -8,7 +8,7 @@ namespace Microsoft.ML.Runtime.Data.IO /// This structure is utilized by both the binary loader and binary saver to hold /// information on the location of blocks written to an .IDV binary file. /// - internal struct BlockLookup + internal readonly struct BlockLookup { /// The offset of the block into the file. public readonly long BlockOffset; diff --git a/src/Microsoft.ML.Data/DataLoadSave/CompositeDataLoader.cs b/src/Microsoft.ML.Data/DataLoadSave/CompositeDataLoader.cs index 21384b4155..0009ad4768 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/CompositeDataLoader.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/CompositeDataLoader.cs @@ -40,7 +40,7 @@ public sealed class Arguments public KeyValuePair>[] Transform; } - private struct TransformEx + private readonly struct TransformEx { public readonly string Tag; public readonly string ArgsString; diff --git a/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs b/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs index 21010dc528..9dbbe0d4d2 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs @@ -347,7 +347,7 @@ private IEnumerable ParseSequential() // abort situations. private const int TimeOut = 100; - private struct LineBatch + private readonly struct LineBatch { public readonly string Path; // Total lines, up to the first line of this batch. @@ -378,7 +378,7 @@ public LineBatch(Exception ex) } } - private struct LineInfo + private readonly struct LineInfo { public readonly long Line; public readonly string Text; diff --git a/src/Microsoft.ML.Data/DataView/CacheDataView.cs b/src/Microsoft.ML.Data/DataView/CacheDataView.cs index 7c725d9869..e3b1bee06a 100644 --- a/src/Microsoft.ML.Data/DataView/CacheDataView.cs +++ b/src/Microsoft.ML.Data/DataView/CacheDataView.cs @@ -653,7 +653,7 @@ public static Wrapper Create(CacheDataView parent) return new Wrapper(new TrivialWaiter(parent)); } - public struct Wrapper : IWaiter + public readonly struct Wrapper : IWaiter { private readonly TrivialWaiter _waiter; @@ -722,7 +722,7 @@ public static Wrapper Create(CacheDataView parent, Func pred) return new Wrapper(new WaiterWaiter(parent, pred)); } - public struct Wrapper : IWaiter + public readonly struct Wrapper : IWaiter { private readonly WaiterWaiter _waiter; @@ -836,7 +836,7 @@ public static Wrapper Create(TWaiter waiter) return new Wrapper(new SequenceIndex(waiter)); } - public struct Wrapper : IIndex + public readonly struct Wrapper : IIndex { private readonly SequenceIndex _index; @@ -927,7 +927,7 @@ public static Wrapper Create(TWaiter waiter, int[] perm) return new Wrapper(new RandomIndex(waiter, perm)); } - public struct Wrapper : IIndex + public readonly struct Wrapper : IIndex { private readonly RandomIndex _index; @@ -1097,7 +1097,7 @@ public static Wrapper Create(TWaiter waiter, JobScheduler scheduler) return new Wrapper(new BlockSequenceIndex(waiter, scheduler)); } - public struct Wrapper : IIndex + public readonly struct Wrapper : IIndex { private readonly BlockSequenceIndex _index; @@ -1205,7 +1205,7 @@ public static Wrapper Create(TWaiter waiter, JobScheduler scheduler, int[] perm) return new Wrapper(new BlockRandomIndex(waiter, scheduler, perm)); } - public struct Wrapper : IIndex + public readonly struct Wrapper : IIndex { private readonly BlockRandomIndex _index; diff --git a/src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs b/src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs index e6e7c999f8..0c8dae6438 100644 --- a/src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs +++ b/src/Microsoft.ML.Data/EntryPoints/InputBuilder.cs @@ -20,7 +20,7 @@ namespace Microsoft.ML.Runtime.EntryPoints.JsonUtils /// public sealed class InputBuilder { - private struct Attributes + private readonly struct Attributes { public readonly ArgumentAttribute Input; public readonly TlcModule.RangeAttribute Range; diff --git a/src/Microsoft.ML.Data/Evaluators/AnomalyDetectionEvaluator.cs b/src/Microsoft.ML.Data/Evaluators/AnomalyDetectionEvaluator.cs index e7448e2b48..128dafc81e 100644 --- a/src/Microsoft.ML.Data/Evaluators/AnomalyDetectionEvaluator.cs +++ b/src/Microsoft.ML.Data/Evaluators/AnomalyDetectionEvaluator.cs @@ -211,7 +211,7 @@ public sealed class Aggregator : AggregatorBase { public abstract class CountersBase { - protected struct Info + protected readonly struct Info { public readonly Single Label; public readonly Single Score; diff --git a/src/Microsoft.ML.Data/Model/Pfa/PfaContext.cs b/src/Microsoft.ML.Data/Model/Pfa/PfaContext.cs index c0996beea1..b21ceaa3f0 100644 --- a/src/Microsoft.ML.Data/Model/Pfa/PfaContext.cs +++ b/src/Microsoft.ML.Data/Model/Pfa/PfaContext.cs @@ -24,7 +24,7 @@ public sealed class PfaContext private readonly HashSet _types; private readonly IHost _host; - private struct VariableBlock + private readonly struct VariableBlock { public readonly string Type; public readonly KeyValuePair[] Locals; @@ -46,7 +46,7 @@ public JToken ToToken() } } - private struct CellBlock + private readonly struct CellBlock { public readonly string Name; public readonly JToken Type; @@ -68,7 +68,7 @@ public JObject ToToken() } } - private struct FuncBlock + private readonly struct FuncBlock { public readonly string Name; public readonly JArray Params; diff --git a/src/Microsoft.ML.Data/Prediction/Calibrator.cs b/src/Microsoft.ML.Data/Prediction/Calibrator.cs index d5f56fa3d2..24a7717e73 100644 --- a/src/Microsoft.ML.Data/Prediction/Calibrator.cs +++ b/src/Microsoft.ML.Data/Prediction/Calibrator.cs @@ -1489,7 +1489,7 @@ public ICalibratorTrainer CreateComponent(IHostEnvironment env) public class PavCalibratorTrainer : CalibratorTrainerBase { // a piece of the piecwise function - private struct Piece + private readonly struct Piece { public readonly Float MinX; // end of interval. public readonly Float MaxX; // beginning of interval. @@ -1743,7 +1743,7 @@ public string GetSummary() public sealed class CalibrationDataStore : IEnumerable { - public struct DataItem + public readonly struct DataItem { // The actual binary label of this example. public readonly bool Target; diff --git a/src/Microsoft.ML.Data/StaticPipe/StaticPipeInternalUtils.cs b/src/Microsoft.ML.Data/StaticPipe/StaticPipeInternalUtils.cs index 0d7c12bcb3..4d67e5523c 100644 --- a/src/Microsoft.ML.Data/StaticPipe/StaticPipeInternalUtils.cs +++ b/src/Microsoft.ML.Data/StaticPipe/StaticPipeInternalUtils.cs @@ -259,7 +259,7 @@ public static bool IsAssignableFromStaticPipeline(this Type to, Type from) /// The base type in the base world. private static class NameUtil { - private struct Info + private readonly struct Info { public readonly Type Type; public readonly object Item; diff --git a/src/Microsoft.ML.Data/Transforms/InvertHashUtils.cs b/src/Microsoft.ML.Data/Transforms/InvertHashUtils.cs index 5d83f0d67e..2a5f0a3fc1 100644 --- a/src/Microsoft.ML.Data/Transforms/InvertHashUtils.cs +++ b/src/Microsoft.ML.Data/Transforms/InvertHashUtils.cs @@ -107,7 +107,7 @@ public sealed class InvertHashCollector /// but also maintain the order in which it was inserted, assuming that /// we're using something like a hashset where order is not preserved. /// - private struct Pair + private readonly struct Pair { public readonly T Value; public readonly int Order; diff --git a/src/Microsoft.ML.Data/Transforms/ValueToKeyMappingEstimator.cs b/src/Microsoft.ML.Data/Transforms/ValueToKeyMappingEstimator.cs index fafa0bb824..96ae753d25 100644 --- a/src/Microsoft.ML.Data/Transforms/ValueToKeyMappingEstimator.cs +++ b/src/Microsoft.ML.Data/Transforms/ValueToKeyMappingEstimator.cs @@ -131,7 +131,7 @@ public static partial class TermStaticExtensions private const KeyValueOrder DefSort = (KeyValueOrder)ValueToKeyMappingEstimator.Defaults.Sort; private const int DefMax = ValueToKeyMappingEstimator.Defaults.MaxNumTerms; - private struct Config + private readonly struct Config { public readonly KeyValueOrder Order; public readonly int Max; diff --git a/src/Microsoft.ML.FastTree/Dataset/Dataset.cs b/src/Microsoft.ML.FastTree/Dataset/Dataset.cs index 42414e4373..68283ca33c 100644 --- a/src/Microsoft.ML.FastTree/Dataset/Dataset.cs +++ b/src/Microsoft.ML.FastTree/Dataset/Dataset.cs @@ -912,7 +912,7 @@ public sealed class RowForwardIndexer private readonly Dataset _dataset; private readonly FeatureFlockBase.FlockForwardIndexerBase[] _flockIndexers; - public struct Row + public readonly struct Row { private readonly RowForwardIndexer _indexer; private readonly int _rowIndex; diff --git a/src/Microsoft.ML.FastTree/Dataset/FeatureFlock.cs b/src/Microsoft.ML.FastTree/Dataset/FeatureFlock.cs index 990e83b735..cb3070d45b 100644 --- a/src/Microsoft.ML.FastTree/Dataset/FeatureFlock.cs +++ b/src/Microsoft.ML.FastTree/Dataset/FeatureFlock.cs @@ -24,7 +24,7 @@ namespace Microsoft.ML.Trainers.FastTree.Internal /// are then used in to find splitting on which bin will yield the /// best least squares solution /// - public struct PerBinStats + public readonly struct PerBinStats { /// Sum of all target values in a partition for the bin. public readonly Double SumTargets; diff --git a/src/Microsoft.ML.HalLearners/SymSgdClassificationTrainer.cs b/src/Microsoft.ML.HalLearners/SymSgdClassificationTrainer.cs index b0ec0608f1..e59583aa4b 100644 --- a/src/Microsoft.ML.HalLearners/SymSgdClassificationTrainer.cs +++ b/src/Microsoft.ML.HalLearners/SymSgdClassificationTrainer.cs @@ -235,7 +235,7 @@ public static CommonOutputs.BinaryClassificationOutput TrainSymSgd(IHostEnvironm /// This struct holds the information about the size, label and isDense of each instance /// to be able to pass it to the native code. /// - private struct InstanceProperties + private readonly struct InstanceProperties { public readonly int FeatureCount; public readonly float Label; diff --git a/src/Microsoft.ML.Maml/HelpCommand.cs b/src/Microsoft.ML.Maml/HelpCommand.cs index 91b5f8f32d..ee2adbb495 100644 --- a/src/Microsoft.ML.Maml/HelpCommand.cs +++ b/src/Microsoft.ML.Maml/HelpCommand.cs @@ -398,7 +398,7 @@ private void AppendFormattedText(StringBuilder builder, string text, string inde } } - public struct Component + public readonly struct Component { public readonly string Kind; public readonly ComponentCatalog.LoadableClassInfo Info; diff --git a/src/Microsoft.ML.PipelineInference/ColumnGroupingInference.cs b/src/Microsoft.ML.PipelineInference/ColumnGroupingInference.cs index 9e83811b25..4847960671 100644 --- a/src/Microsoft.ML.PipelineInference/ColumnGroupingInference.cs +++ b/src/Microsoft.ML.PipelineInference/ColumnGroupingInference.cs @@ -42,7 +42,7 @@ public GroupingColumn(string name, DataKind kind, ColumnPurpose purpose, string } } - public struct InferenceResult + public readonly struct InferenceResult { public readonly GroupingColumn[] Columns; diff --git a/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs b/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs index 3e29205843..844cb3eb56 100644 --- a/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs +++ b/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs @@ -70,7 +70,7 @@ public IntermediateColumn(ReadOnlyMemory[] data, int columnId) public ReadOnlyMemory[] RawData { get { return _data; } } } - public struct Column + public readonly struct Column { public readonly int ColumnIndex; public readonly string SuggestedName; @@ -84,7 +84,7 @@ public Column(int columnIndex, string suggestedName, PrimitiveType itemType) } } - public struct InferenceResult + public readonly struct InferenceResult { public readonly Column[] Columns; public readonly bool HasHeader; diff --git a/src/Microsoft.ML.PipelineInference/PurposeInference.cs b/src/Microsoft.ML.PipelineInference/PurposeInference.cs index 3dac9d9e0e..10e28dfe3f 100644 --- a/src/Microsoft.ML.PipelineInference/PurposeInference.cs +++ b/src/Microsoft.ML.PipelineInference/PurposeInference.cs @@ -27,7 +27,7 @@ public Arguments() } } - public struct Column + public readonly struct Column { public readonly int ColumnIndex; public readonly ColumnPurpose Purpose; @@ -41,7 +41,7 @@ public Column(int columnIndex, ColumnPurpose purpose, DataKind itemKind) } } - public struct InferenceResult + public readonly struct InferenceResult { public readonly Column[] Columns; diff --git a/src/Microsoft.ML.PipelineInference/RecipeInference.cs b/src/Microsoft.ML.PipelineInference/RecipeInference.cs index fe8b8029ed..f3b560da5f 100644 --- a/src/Microsoft.ML.PipelineInference/RecipeInference.cs +++ b/src/Microsoft.ML.PipelineInference/RecipeInference.cs @@ -21,7 +21,7 @@ namespace Microsoft.ML.Runtime.PipelineInference { public static class RecipeInference { - public struct SuggestedRecipe + public readonly struct SuggestedRecipe { public readonly string Description; public readonly TransformInference.SuggestedTransform[] Transforms; @@ -121,7 +121,7 @@ public AutoInference.EntryPointGraphDef ToEntryPointGraph(IHostEnvironment env) public override string ToString() => Description; } - public struct InferenceResult + public readonly struct InferenceResult { public readonly SuggestedRecipe[] SuggestedRecipes; public InferenceResult(SuggestedRecipe[] suggestedRecipes) diff --git a/src/Microsoft.ML.PipelineInference/TextFileContents.cs b/src/Microsoft.ML.PipelineInference/TextFileContents.cs index c02cb70219..f3f45cc8b9 100644 --- a/src/Microsoft.ML.PipelineInference/TextFileContents.cs +++ b/src/Microsoft.ML.PipelineInference/TextFileContents.cs @@ -17,7 +17,7 @@ namespace Microsoft.ML.Runtime.PipelineInference /// public static class TextFileContents { - public struct ColumnSplitResult + public readonly struct ColumnSplitResult { public readonly bool IsSuccess; public readonly string Separator; diff --git a/src/Microsoft.ML.PipelineInference/TransformInference.cs b/src/Microsoft.ML.PipelineInference/TransformInference.cs index 6868b2b726..3255a850b6 100644 --- a/src/Microsoft.ML.PipelineInference/TransformInference.cs +++ b/src/Microsoft.ML.PipelineInference/TransformInference.cs @@ -93,7 +93,7 @@ public SuggestedTransform Clone() public override string ToString() => ExpertType.Name; } - public struct TransformString : IEquatable + public readonly struct TransformString : IEquatable { public readonly string Kind; public readonly string Settings; @@ -121,7 +121,7 @@ public override string ToString() } } - public struct InferenceResult + public readonly struct InferenceResult { public readonly SuggestedTransform[] SuggestedTransforms; @@ -131,7 +131,7 @@ public InferenceResult(SuggestedTransform[] suggestedTransforms) } } - public struct Column + public readonly struct Column { public readonly Data.ColumnType Type; public readonly string Name; diff --git a/src/Microsoft.ML.StandardLearners/Optimizer/Optimizer.cs b/src/Microsoft.ML.StandardLearners/Optimizer/Optimizer.cs index 4b8c1e2cc4..4ec56d0eaa 100644 --- a/src/Microsoft.ML.StandardLearners/Optimizer/Optimizer.cs +++ b/src/Microsoft.ML.StandardLearners/Optimizer/Optimizer.cs @@ -547,7 +547,7 @@ private static Float CubicInterp(PointValueDeriv p0, PointValueDeriv p1) return (Float)(p1.A - (p1.A - p0.A) * num / denom); } - private struct PointValueDeriv + private readonly struct PointValueDeriv { public readonly Float A; public readonly Float V; diff --git a/src/Microsoft.ML.StandardLearners/Standard/LinearClassificationTrainer.cs b/src/Microsoft.ML.StandardLearners/Standard/LinearClassificationTrainer.cs index 5805629230..7964d06cdb 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/LinearClassificationTrainer.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/LinearClassificationTrainer.cs @@ -1134,7 +1134,7 @@ protected Func GetIndexFromIdAndRowGetter(IdToIdxLookup idT protected sealed class IdToIdxLookup { // Utilizing this struct gives better cache behavior than using parallel arrays. - private struct Entry + private readonly struct Entry { public readonly long ItNext; public readonly UInt128 Value; diff --git a/src/Microsoft.ML.StandardLearners/Standard/ModelStatistics.cs b/src/Microsoft.ML.StandardLearners/Standard/ModelStatistics.cs index 5f8d096c81..b687d088be 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/ModelStatistics.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/ModelStatistics.cs @@ -24,7 +24,7 @@ namespace Microsoft.ML.Runtime.Learners /// /// Represents a coefficient statistics object. /// - public struct CoefficientStatistics + public readonly struct CoefficientStatistics { public readonly string Name; public readonly Single Estimate; diff --git a/src/Microsoft.ML.Transforms/CategoricalHashTransform.cs b/src/Microsoft.ML.Transforms/CategoricalHashTransform.cs index 86db39259c..24a800024c 100644 --- a/src/Microsoft.ML.Transforms/CategoricalHashTransform.cs +++ b/src/Microsoft.ML.Transforms/CategoricalHashTransform.cs @@ -342,7 +342,7 @@ public enum OneHotHashScalarOutputKind : byte private const bool DefOrdered = OneHotHashEncodingEstimator.Defaults.Ordered; private const int DefInvertHash = OneHotHashEncodingEstimator.Defaults.InvertHash; - private struct Config + private readonly struct Config { public readonly int HashBits; public readonly uint Seed; diff --git a/src/Microsoft.ML.Transforms/CategoricalTransform.cs b/src/Microsoft.ML.Transforms/CategoricalTransform.cs index 8d81541120..addd2e54a3 100644 --- a/src/Microsoft.ML.Transforms/CategoricalTransform.cs +++ b/src/Microsoft.ML.Transforms/CategoricalTransform.cs @@ -368,7 +368,7 @@ public enum OneHotScalarOutputKind : byte private const int DefMax = ValueToKeyMappingEstimator.Defaults.MaxNumTerms; private const OneHotVectorOutputKind DefOut = (OneHotVectorOutputKind)OneHotEncodingEstimator.Defaults.OutKind; - private struct Config + private readonly struct Config { public readonly KeyValueOrder Order; public readonly int Max; diff --git a/src/Microsoft.ML.Transforms/NAReplaceTransform.cs b/src/Microsoft.ML.Transforms/NAReplaceTransform.cs index c11bb5792a..b0c9df8406 100644 --- a/src/Microsoft.ML.Transforms/NAReplaceTransform.cs +++ b/src/Microsoft.ML.Transforms/NAReplaceTransform.cs @@ -999,7 +999,7 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema) /// public static class NAReplacerExtensions { - private struct Config + private readonly struct Config { public readonly bool ImputeBySlot; public readonly NAReplaceTransform.ColumnInfo.ReplacementMode ReplacementMode; diff --git a/src/Microsoft.ML.Transforms/RffTransform.cs b/src/Microsoft.ML.Transforms/RffTransform.cs index b97429bbc5..c6d5d6a262 100644 --- a/src/Microsoft.ML.Transforms/RffTransform.cs +++ b/src/Microsoft.ML.Transforms/RffTransform.cs @@ -693,7 +693,7 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema) public static class RffExtenensions { - private struct Config + private readonly struct Config { public readonly int NewDim; public readonly bool UseSin; diff --git a/src/Microsoft.ML.Transforms/UngroupTransform.cs b/src/Microsoft.ML.Transforms/UngroupTransform.cs index 5601ce0ee9..230138151d 100644 --- a/src/Microsoft.ML.Transforms/UngroupTransform.cs +++ b/src/Microsoft.ML.Transforms/UngroupTransform.cs @@ -213,7 +213,7 @@ private static bool ShouldPreserveMetadata(string kind) } } - public struct PivotColumnInfo + public readonly struct PivotColumnInfo { public readonly string Name; public readonly int Index; diff --git a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/DiagnosticResult.cs b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/DiagnosticResult.cs index d915ab7cc3..dee2ae7fdb 100644 --- a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/DiagnosticResult.cs +++ b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/DiagnosticResult.cs @@ -10,7 +10,7 @@ namespace Microsoft.ML.CodeAnalyzer.Tests.Helpers /// /// Location where the diagnostic appears, as determined by path, line number, and column number. /// - public struct DiagnosticResultLocation + public readonly struct DiagnosticResultLocation { public string Path { get; } public int Line { get; } diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index 5613765e77..6e62b96a4f 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -306,7 +306,7 @@ protected void Normalize(string path) /// When hardware dependent baseline values should be tolerated, scope the code /// that does the comparisons with an instance of this disposable struct. /// - protected struct MismatchContext : IDisposable + protected readonly struct MismatchContext : IDisposable { // The test class instance. private readonly BaseTestBaseline _host;