Skip to content

Commit 1fc3069

Browse files
authored
fix namespace issue in CSharpGenerator and some refactoring (#339)
fix namespace issue and refactoring
1 parent 45ced36 commit 1fc3069

File tree

12 files changed

+978
-1011
lines changed

12 files changed

+978
-1011
lines changed

src/Microsoft.ML.Data/DataLoadSave/PartitionedPathParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class Arguments : IPartitionedPathParserFactory
7676
{
7777
[Argument(ArgumentType.Multiple, HelpText = "Column definitions used to override the Partitioned Path Parser. Expected with the format name:type:numeric-source, e.g. col=MyFeature:R4:1",
7878
ShortName = "col", SortOrder = 1)]
79-
public Microsoft.ML.Runtime.Data.PartitionedFileLoader.Column[] Columns;
79+
public PartitionedFileLoader.Column[] Columns;
8080

8181
[Argument(ArgumentType.AtMostOnce, HelpText = "Data type of each column.")]
8282
public DataKind Type = DataKind.Text;

src/Microsoft.ML.PipelineInference/TransformInference.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using System.Text;
9-
using Microsoft.ML;
109
using Microsoft.ML.Runtime.CommandLine;
1110
using Microsoft.ML.Runtime.Data;
1211
using Microsoft.ML.Runtime.EntryPoints;
@@ -712,7 +711,7 @@ public override IEnumerable<SuggestedTransform> Apply(IntermediateColumn[] colum
712711
{
713712
Name = columnNameQuoted.ToString(),
714713
Source = columnNameQuoted.ToString(),
715-
ResultType = ML.Transforms.DataKind.R4
714+
ResultType = ML.Data.DataKind.R4
716715
});
717716
}
718717

@@ -721,7 +720,7 @@ public override IEnumerable<SuggestedTransform> Apply(IntermediateColumn[] colum
721720
ch.Info("Suggested conversion to numeric for boolean features.");
722721
var args = new SubComponent<IDataTransform, SignatureDataTransform>("Convert",
723722
new[] { $"{columnArgument}type=R4" });
724-
var epInput = new ML.Transforms.ColumnTypeConverter { Column = epColumns.ToArray(), ResultType = ML.Transforms.DataKind.R4 };
723+
var epInput = new ML.Transforms.ColumnTypeConverter { Column = epColumns.ToArray(), ResultType = ML.Data.DataKind.R4 };
725724
ColumnRoutingStructure.AnnotatedName[] columnsSource =
726725
epColumns.Select(c => new ColumnRoutingStructure.AnnotatedName { IsNumeric = false, Name = c.Name }).ToArray();
727726
ColumnRoutingStructure.AnnotatedName[] columnsDest =

src/Microsoft.ML/CSharpApi.cs

+177-186
Large diffs are not rendered by default.

src/Microsoft.ML/Runtime/EntryPoints/JsonUtils/JsonManifestUtils.cs

+3-15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Reflection;
99
using Microsoft.ML.Runtime.CommandLine;
10+
using Microsoft.ML.Runtime.Internal.Tools;
1011
using Microsoft.ML.Runtime.Internal.Utilities;
1112
using Newtonsoft.Json.Linq;
1213

@@ -67,13 +68,7 @@ public static JObject BuildAllManifests(IExceptionContext ectx, ModuleCatalog ca
6768
{
6869
var jField = new JObject();
6970
jField[FieldNames.Name] = fieldInfo.Name;
70-
var type = fieldInfo.PropertyType;
71-
// Dive inside Optional.
72-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Optional<>))
73-
type = type.GetGenericArguments()[0];
74-
// Dive inside Nullable.
75-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
76-
type = type.GetGenericArguments()[0];
71+
var type = CSharpGeneratorUtils.ExtractOptionalOrNullableType(fieldInfo.PropertyType);
7772
// Dive inside Var.
7873
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Var<>))
7974
type = type.GetGenericArguments()[0];
@@ -308,14 +303,7 @@ private static JToken BuildTypeToken(IExceptionContext ectx, FieldInfo fieldInfo
308303
jo[FieldNames.ItemType] = typeString;
309304
return jo;
310305
}
311-
312-
// Dive inside Optional.
313-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Optional<>))
314-
type = type.GetGenericArguments()[0];
315-
316-
// Dive inside Nullable.
317-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
318-
type = type.GetGenericArguments()[0];
306+
type = CSharpGeneratorUtils.ExtractOptionalOrNullableType(type);
319307

320308
// Dive inside Var.
321309
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Var<>))

0 commit comments

Comments
 (0)