Skip to content

Commit bc1273a

Browse files
committed
restoring some readonly and casts.
Fixing 3 out of 5 analyzer test failures.
1 parent 05a6b0e commit bc1273a

File tree

10 files changed

+32
-29
lines changed

10 files changed

+32
-29
lines changed

src/Microsoft.ML.Core/Utilities/Stats.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static long SampleLong(long rangeSize, Random rand)
4242
return result;
4343
}
4444

45-
private static readonly double _vScale = 2 * Math.Sqrt(2 / Math.E);
45+
private static double _vScale = 2 * Math.Sqrt(2 / Math.E);
4646

4747
/// <summary>
4848
/// Returns a number sampled from a zero-mean, unit variance Gaussian

src/Microsoft.ML.Data/Evaluators/MultiOutputRegressionEvaluator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ private void CheckInputColumnTypes(DataViewSchema schema, out VectorType labelTy
550550
var t = schema[LabelIndex].Type as VectorType;
551551
if (t == null || !t.IsKnownSize || (t.ItemType != NumberDataViewType.Single && t.ItemType != NumberDataViewType.Double))
552552
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "known-size vector of float or double", t.ToString());
553-
labelType = new VectorType(t.ItemType, t.Size);
553+
labelType = new VectorType((PrimitiveDataViewType)t.ItemType, t.Size);
554554
var slotNamesType = new VectorType(TextDataViewType.Instance, t.Size);
555555
var builder = new DataViewSchema.Annotations.Builder();
556556
builder.AddSlotNames(t.Size, CreateSlotNamesGetter(schema, LabelIndex, labelType.Size, "True"));
@@ -559,7 +559,7 @@ private void CheckInputColumnTypes(DataViewSchema schema, out VectorType labelTy
559559
t = schema[ScoreIndex].Type as VectorType;
560560
if (t == null || !t.IsKnownSize || t.ItemType != NumberDataViewType.Single)
561561
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of float", t.ToString());
562-
scoreType = new VectorType(t.ItemType, t.Size);
562+
scoreType = new VectorType((PrimitiveDataViewType)t.ItemType, t.Size);
563563
builder = new DataViewSchema.Annotations.Builder();
564564
builder.AddSlotNames(t.Size, CreateSlotNamesGetter(schema, ScoreIndex, scoreType.Size, "Predicted"));
565565

src/Microsoft.ML.Data/Prediction/Calibrator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private FeatureWeightsCalibratedModelParameters(IHostEnvironment env, ModelLoadC
472472
: base(env, RegistrationName, GetPredictor(env, ctx), GetCalibrator(env, ctx))
473473
{
474474
Host.Check(SubModel is IPredictorWithFeatureWeights<float>, "Predictor does not implement " + nameof(IPredictorWithFeatureWeights<float>));
475-
_featureWeights = SubModel;
475+
_featureWeights = (IPredictorWithFeatureWeights<float>)SubModel;
476476
}
477477

478478
private static FeatureWeightsCalibratedModelParameters<TSubModel, TCalibrator> Create(IHostEnvironment env, ModelLoadContext ctx)
@@ -1635,13 +1635,13 @@ private void SaveCore(ModelSaveContext ctx)
16351635

16361636
if (ctx.InRepository)
16371637
{
1638-
ctx.SaveTextStream("Calibrator.txt", writer =>
1638+
ctx.SaveTextStream("Calibrator.txt", (Action<TextWriter>)(writer =>
16391639
{
16401640
writer.WriteLine("Platt calibrator");
16411641
writer.WriteLine("P(y=1|x) = 1/1+exp(A*x + B)");
1642-
writer.WriteLine("A={0:R}", Slope);
1642+
writer.WriteLine("A={0:R}", (object)Slope);
16431643
writer.WriteLine("B={0:R}", Offset);
1644-
});
1644+
}));
16451645
}
16461646
}
16471647

src/Microsoft.ML.FastTree/TreeEnsembleFeaturizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ private static IDataView AppendFloatMapper<TInput>(IHostEnvironment env, IChanne
696696
return;
697697
}
698698
converter(in src, ref temp);
699-
dst = temp - 1;
699+
dst = (Single)temp - 1;
700700
};
701701
}
702702
else
@@ -712,7 +712,7 @@ private static IDataView AppendFloatMapper<TInput>(IHostEnvironment env, IChanne
712712
return;
713713
}
714714
converter(in src, ref temp);
715-
dst = permutation[(int)(temp - 1)];
715+
dst = (Single)permutation[(int)(temp - 1)];
716716
};
717717
}
718718

src/Microsoft.ML.Parquet/PartitionedFileLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ private sealed class Cursor : RootCursorBase
369369

370370
private readonly bool[] _active;
371371
private readonly bool[] _subActive; // Active columns of the sub-cursor.
372-
private readonly Delegate[] _getters;
373-
private readonly Delegate[] _subGetters; // Cached getters of the sub-cursor.
372+
private Delegate[] _getters;
373+
private Delegate[] _subGetters; // Cached getters of the sub-cursor.
374374

375375
private readonly IEnumerable<DataViewSchema.Column> _columnsNeeded;
376376
private readonly IEnumerable<DataViewSchema.Column> _subActivecolumnsNeeded;

test/Microsoft.ML.CodeAnalyzer.Tests/Resources/TypeIsSchemaShapeClassResource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Data.DataView;
33
using Microsoft.ML;
44
using Microsoft.ML.Data;
5+
using Microsoft.ML.Runtime;
56
using Microsoft.ML.StaticPipe;
67

78
namespace Bubba

test/Microsoft.ML.CodeAnalyzer.Tests/Resources/TypeIsSchemaShapeResource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.ML;
33
using Microsoft.ML.CommandLine;
44
using Microsoft.ML.Data;
5+
using Microsoft.ML.Runtime;
56
using Microsoft.ML.StaticPipe;
67

78
namespace Bubba

test/Microsoft.ML.CodeAnalyzer.Tests/Resources/TypeIsSchemaShapeResourceChained.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.ML;
44
using Microsoft.ML.CommandLine;
55
using Microsoft.ML.Data;
6+
using Microsoft.ML.Runtime;
67
using Microsoft.ML.StaticPipe;
78

89
namespace Bubba

test/Microsoft.ML.CodeAnalyzer.Tests/TypeIsSchemaShapeTest.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public sealed class TypeIsSchemaShapeTest
2222
public async Task ReturnTypeIsSchemaShape()
2323
{
2424
var expected = new DiagnosticResult[] {
25-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(23, 13).WithArguments(""),
26-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(24, 13).WithArguments(" of item bad"),
27-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(30, 13).WithArguments(" of item c.Item2"),
28-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(40, 13).WithArguments(" of item listen"),
25+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(24, 13).WithArguments(""),
26+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(25, 13).WithArguments(" of item bad"),
27+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(31, 13).WithArguments(" of item c.Item2"),
28+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(41, 13).WithArguments(" of item listen"),
2929
};
3030

3131
var test = new VerifyCS.Test { TestCode = Source };
@@ -45,10 +45,10 @@ public async Task ReturnTypeIsSchemaShapeChained()
4545
// function where the shape type is a generic type parameter. In this case, we would ideally like the analysis to get
4646
// chained out of their function.
4747
var expected = new DiagnosticResult[] {
48-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeParameterDiagnostic.Rule).WithLocation(18, 24).WithArguments("T"),
49-
new DiagnosticResult("CS8205", DiagnosticSeverity.Error).WithLocation(21, 52).WithMessage("Attributes are not allowed on local function parameters or type parameters"),
50-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeParameterDiagnostic.Rule).WithLocation(41, 24).WithArguments("T"),
51-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(55, 26).WithArguments(" of item text"),
48+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeParameterDiagnostic.Rule).WithLocation(19, 24).WithArguments("T"),
49+
new DiagnosticResult("CS8205", DiagnosticSeverity.Error).WithLocation(22, 52).WithMessage("Attributes are not allowed on local function parameters or type parameters"),
50+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeParameterDiagnostic.Rule).WithLocation(42, 24).WithArguments("T"),
51+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeDiagnostic.Rule).WithLocation(56, 26).WithArguments(" of item text"),
5252
};
5353

5454
var test = new VerifyCS.Test { TestCode = SourceChained };
@@ -68,17 +68,17 @@ public async Task ReturnTypeIsSchemaShapeClass()
6868
// function where the shape type is a generic type parameter. In this case, we would ideally like the analysis to get
6969
// chained out of their function.
7070
var expected = new DiagnosticResult[] {
71-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticField.Rule).WithLocation(33, 13).WithArguments("Class4", "F1"),
72-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticConstructor.Rule).WithLocation(34, 13).WithArguments("Class5"),
73-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticConstructor.Rule).WithLocation(35, 13).WithArguments("Class6"),
71+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticField.Rule).WithLocation(34, 13).WithArguments("Class4", "F1"),
72+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticConstructor.Rule).WithLocation(35, 13).WithArguments("Class5"),
73+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticConstructor.Rule).WithLocation(36, 13).WithArguments("Class6"),
7474

75-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticNoArgsSettable.Rule).WithLocation(36, 13).WithArguments("Class7", "F1"),
76-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticArgsSettable.Rule).WithLocation(37, 13).WithArguments("Class8", "F2"),
77-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticGettable.Rule).WithLocation(38, 13).WithArguments("Class9", "F2"),
78-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticCorrespondence.Rule).WithLocation(39, 13).WithArguments("Class10"),
79-
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticCorrespondence.Rule).WithLocation(40, 13).WithArguments("Class11"),
75+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticNoArgsSettable.Rule).WithLocation(37, 13).WithArguments("Class7", "F1"),
76+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticArgsSettable.Rule).WithLocation(38, 13).WithArguments("Class8", "F2"),
77+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticGettable.Rule).WithLocation(39, 13).WithArguments("Class9", "F2"),
78+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticCorrespondence.Rule).WithLocation(40, 13).WithArguments("Class10"),
79+
VerifyCS.Diagnostic(TypeIsSchemaShapeAnalyzer.ShapeClassDiagnosticCorrespondence.Rule).WithLocation(41, 13).WithArguments("Class11"),
8080

81-
new DiagnosticResult("CS0246", DiagnosticSeverity.Error).WithLocation(44, 71).WithMessage("The type or namespace name 'MissingClass' could not be found (are you missing a using directive or an assembly reference?)"),
81+
new DiagnosticResult("CS0246", DiagnosticSeverity.Error).WithLocation(45, 71).WithMessage("The type or namespace name 'MissingClass' could not be found (are you missing a using directive or an assembly reference?)"),
8282
};
8383

8484
var test = new VerifyCS.Test { TestCode = SourceClass };

tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context)
198198
// but for some reason cannot reference MLCore.
199199
// Contract functions defined Microsoft.ML.Internal.CpuMath.Core are introduced for breaking the dependencies
200200
// from CpuMath project to Microsoft.ML.Core.
201-
if (containingSymbolName != "Microsoft.ML.Contracts" &&
201+
if (containingSymbolName != "Microsoft.ML.Runtime.Contracts" &&
202202
containingSymbolName != "Microsoft.ML.Internal.CpuMath.Core.Contracts")
203203
{
204204
return;

0 commit comments

Comments
 (0)