-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make SchemaShape.Column a struct instead of a class #1822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
/// This documents that the parameter can not legally be null because it is struct. | ||
/// </summary> | ||
[Conditional("INVARIANT_CHECKS")] | ||
public static void CheckValueOrDefault<T>(T val) where T : struct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckValueOrDefault [](start = 27, length = 19)
Given that we're now doing this through other means, should probably revert these changes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Note that in TrainerEstimatorBase.cs
we now do
private protected TrainerEstimatorBase(IHost host,
SchemaShape.Column feature,
SchemaShape.Column label,
SchemaShape.Column weight = default)
{
Contracts.CheckValue(host, nameof(host));
Host = host;
Host.Check(feature.IsValid, nameof(feature));
Host.Check(label.IsValid, nameof(label));
FeatureColumn = feature;
LabelColumn = label;
WeightColumn = weight;
}
after removing CheckValueOrDefault(weight, nameof(weight))
and CheckValueOrDefault(label, nameof(label))
.
In reply to: 238870053 [](ancestors = 238870053)
@@ -367,7 +367,7 @@ public static bool IsNormalized(this Schema schema, int col) | |||
/// of a scalar <see cref="BoolType"/> type, which we assume, if set, should be <c>true</c>.</returns> | |||
public static bool IsNormalized(this SchemaShape.Column col) | |||
{ | |||
Contracts.CheckValue(col, nameof(col)); | |||
Contracts.Check(col.IsValid, nameof(col)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check [](start = 22, length = 5)
This would be CheckParam
. Also you will want to provide some sort of message. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. We will use Contracts.CheckParam(col.IsValid, nameof(col), "struct not initialized");
I will do the same for other public functions.
In reply to: 238870227 [](ancestors = 238870227)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an urgent note about Schema.
@@ -16,13 +17,17 @@ namespace Microsoft.ML.Core.Data | |||
/// This is more relaxed than the proper <see cref="ISchema"/>, since it's only a subset of the columns, | |||
/// and also since it doesn't specify exact <see cref="ColumnType"/>'s for vectors and keys. | |||
/// </summary> | |||
public sealed class SchemaShape | |||
public sealed class SchemaShape : IReadOnlyList<SchemaShape.Column> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: IReadOnlyList<SchemaShape.Column> [](start = 36, length = 35)
This is not right! You can make this a ReadOnlyList
with proper indexers and so forth. Or you could expose this Columns
thing as you do below. You CANNOT DO BOTH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right. Thanks a lot for pointing this out.
In reply to: 239226291 [](ancestors = 239226291)
@@ -163,7 +163,7 @@ protected override void CheckLabels(RoleMappedData data) | |||
|
|||
protected override void CheckLabelCompatible(SchemaShape.Column labelCol) | |||
{ | |||
Contracts.AssertValue(labelCol); | |||
Contracts.Assert(labelCol.IsValid, nameof(labelCol)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, nameof(labelCol) [](start = 45, length = 18)
This is an assert. It doesn't need or benefit from a message. Also this message, being just the parameter name, might not be the most helpful. (Again not suggesting that it needs a message, just pointing out that if it needed one this would not necessarily be helpful. But please don't add one.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #1706.