Skip to content

Reduce public surface area of ColumnType and family. #1543

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

Merged
merged 3 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Microsoft.ML.Api/CodeGenerationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public static void AppendFieldDeclaration(CSharpCodeProvider codeProvider, Strin
target.Append(indent);
target.AppendFormat("public {0} {1}", generatedCsTypeName, fieldName);

if (appendInitializer && colType.IsKnownSizeVector && !useVBuffer)
if (appendInitializer && colType is VectorType vecColType && vecColType.Size > 0 && !useVBuffer)
{
Contracts.Assert(generatedCsTypeName.EndsWith("[]"));
var csItemType = generatedCsTypeName.Substring(0, generatedCsTypeName.Length - 2);
target.AppendFormat(" = new {0}[{1}]", csItemType, colType.VectorSize);
target.AppendFormat(" = new {0}[{1}]", csItemType, vecColType.Size);
}
target.AppendLine(";");
}
Expand Down Expand Up @@ -109,17 +109,13 @@ private static string GetBackingTypeName(ColumnType colType, bool useVBuffer, Li
{
Contracts.AssertValue(colType);
Contracts.AssertValue(attributes);
if (colType.IsVector)
if (colType is VectorType vecColType)
{
if (colType.IsKnownSizeVector)
if (vecColType.Size > 0)
{
// By default, arrays are assumed variable length, unless a [VectorType(dim1, dim2, ...)]
// attribute is applied to the fields.
var vectorType = colType.AsVector;
var dimensions = new int[vectorType.DimCount];
for (int i = 0; i < dimensions.Length; i++)
dimensions[i] = vectorType.GetDim(i);
attributes.Add(string.Format("[VectorType({0})]", string.Join(", ", dimensions)));
attributes.Add(string.Format("[VectorType({0})]", string.Join(", ", vecColType.Dimensions)));
}

var itemType = GetBackingTypeName(colType.ItemType, false, attributes);
Expand Down
Loading