Skip to content

Commit 5566d2a

Browse files
authored
Reduce public surface area of ColumnType and family. (#1543)
* Reduce public surface area of ColumnType and family. * Introduce internals-visible-to on core, and [BestFriend] attributes on key members of ColumnType so internally the implementation can use the old conveniences. * Make type-specific data available only on the relevant type, for example, Size on VectorType, which replaces all of VectorSize, ValueCount, IsKnownSizeVectorType. * All `IsX` and `AsX` should be replaced with `is XType` or `as XType`. * Also in the spirit of the above, hide other redundant conveniences. * De-emphasize rather entirely DataKind as having anything to do with ColumnType, at least publicly. * Validate new public surface by having the tests use it instead of the old way.
1 parent 5393bbd commit 5566d2a

File tree

31 files changed

+551
-567
lines changed

31 files changed

+551
-567
lines changed

src/Microsoft.ML.Api/CodeGenerationUtils.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public static void AppendFieldDeclaration(CSharpCodeProvider codeProvider, Strin
7575
target.Append(indent);
7676
target.AppendFormat("public {0} {1}", generatedCsTypeName, fieldName);
7777

78-
if (appendInitializer && colType.IsKnownSizeVector && !useVBuffer)
78+
if (appendInitializer && colType is VectorType vecColType && vecColType.Size > 0 && !useVBuffer)
7979
{
8080
Contracts.Assert(generatedCsTypeName.EndsWith("[]"));
8181
var csItemType = generatedCsTypeName.Substring(0, generatedCsTypeName.Length - 2);
82-
target.AppendFormat(" = new {0}[{1}]", csItemType, colType.VectorSize);
82+
target.AppendFormat(" = new {0}[{1}]", csItemType, vecColType.Size);
8383
}
8484
target.AppendLine(";");
8585
}
@@ -109,17 +109,13 @@ private static string GetBackingTypeName(ColumnType colType, bool useVBuffer, Li
109109
{
110110
Contracts.AssertValue(colType);
111111
Contracts.AssertValue(attributes);
112-
if (colType.IsVector)
112+
if (colType is VectorType vecColType)
113113
{
114-
if (colType.IsKnownSizeVector)
114+
if (vecColType.Size > 0)
115115
{
116116
// By default, arrays are assumed variable length, unless a [VectorType(dim1, dim2, ...)]
117117
// attribute is applied to the fields.
118-
var vectorType = colType.AsVector;
119-
var dimensions = new int[vectorType.DimCount];
120-
for (int i = 0; i < dimensions.Length; i++)
121-
dimensions[i] = vectorType.GetDim(i);
122-
attributes.Add(string.Format("[VectorType({0})]", string.Join(", ", dimensions)));
118+
attributes.Add(string.Format("[VectorType({0})]", string.Join(", ", vecColType.Dimensions)));
123119
}
124120

125121
var itemType = GetBackingTypeName(colType.ItemType, false, attributes);

0 commit comments

Comments
 (0)