2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System ;
5
6
using System . Collections . Generic ;
6
7
using System . Linq ;
7
8
using System . Reflection ;
8
9
using System . Runtime . CompilerServices ;
10
+ using Microsoft . ML . Core . Data ;
9
11
using Microsoft . ML . Data . StaticPipe . Runtime ;
10
12
using Microsoft . ML . Runtime ;
11
- using System ;
12
13
using Microsoft . ML . Runtime . Internal . Utilities ;
13
- using Microsoft . ML . Core . Data ;
14
14
15
15
namespace Microsoft . ML . Data . StaticPipe
16
16
{
17
17
internal static class PipelineColumnAnalyzer
18
18
{
19
- public static void Analyze < TIn , TOut > ( Func < TIn , TOut > func )
20
- {
21
- bool singletonIn = typeof ( PipelineColumn ) . IsAssignableFrom ( typeof ( TIn ) ) ;
22
- bool singletonOut = typeof ( PipelineColumn ) . IsAssignableFrom ( typeof ( TOut ) ) ;
23
-
24
- var analysis = CreateAnalysisInstance < TIn > ( out var reconciler ) ;
25
- var analysisOut = func ( analysis ) ;
26
-
27
- var inNames = GetNames < TIn , PipelineColumn > ( analysis , func . Method . GetParameters ( ) [ 0 ] ) ;
28
- var outNames = GetNames < TOut , PipelineColumn > ( analysisOut , func . Method . ReturnParameter ) ;
29
- }
30
-
31
- public interface IIsAnalysisColumn { }
19
+ private interface IIsAnalysisColumn { }
32
20
33
21
/// <summary>
34
22
/// Given a type which is a <see cref="ValueTuple"/> tree with <see cref="PipelineColumn"/> leaves, return an instance of that
@@ -40,11 +28,11 @@ public interface IIsAnalysisColumn { }
40
28
/// (e.g., <see cref="Scalar{T}"/>, <see cref="Vector{T}"/>, etc.)</typeparam>
41
29
/// <returns>An instance of <typeparamref name="T"/> where all <see cref="PipelineColumn"/> fields have instances implementing
42
30
/// <see cref="IIsAnalysisColumn"/> filled in</returns>
43
- public static T CreateAnalysisInstance < T > ( out ReaderReconciler < int > fakeReconciler )
31
+ public static T MakeAnalysisInstance < T > ( out ReaderReconciler < int > fakeReconciler )
44
32
{
45
33
var rec = new AnalyzeUtil . Rec ( ) ;
46
34
fakeReconciler = rec ;
47
- return ( T ) AnalyzeUtil . CreateAnalysisInstanceCore < T > ( rec ) ;
35
+ return ( T ) AnalyzeUtil . MakeAnalysisInstanceCore < T > ( rec ) ;
48
36
}
49
37
50
38
private static class AnalyzeUtil
@@ -72,12 +60,12 @@ private sealed class AKey<T> : Key<T>, IIsAnalysisColumn { public AKey(Rec rec)
72
60
private sealed class AKey < T , TV > : Key < T , TV > , IIsAnalysisColumn { public AKey ( Rec rec ) : base ( rec , null ) { } }
73
61
private sealed class AVarKey < T > : VarKey < T > , IIsAnalysisColumn { public AVarKey ( Rec rec ) : base ( rec , null ) { } }
74
62
75
- private static PipelineColumn CreateScalar < T > ( Rec rec ) => new AScalar < T > ( rec ) ;
76
- private static PipelineColumn CreateVector < T > ( Rec rec ) => new AVector < T > ( rec ) ;
77
- private static PipelineColumn CreateVarVector < T > ( Rec rec ) => new AVarVector < T > ( rec ) ;
78
- private static PipelineColumn CreateKey < T > ( Rec rec ) => new AKey < T > ( rec ) ;
79
- private static Key < T , TV > CreateKey < T , TV > ( Rec rec ) => new AKey < T , TV > ( rec ) ;
80
- private static PipelineColumn CreateVarKey < T > ( Rec rec ) => new AVarKey < T > ( rec ) ;
63
+ private static PipelineColumn MakeScalar < T > ( Rec rec ) => new AScalar < T > ( rec ) ;
64
+ private static PipelineColumn MakeVector < T > ( Rec rec ) => new AVector < T > ( rec ) ;
65
+ private static PipelineColumn MakeVarVector < T > ( Rec rec ) => new AVarVector < T > ( rec ) ;
66
+ private static PipelineColumn MakeKey < T > ( Rec rec ) => new AKey < T > ( rec ) ;
67
+ private static Key < T , TV > MakeKey < T , TV > ( Rec rec ) => new AKey < T , TV > ( rec ) ;
68
+ private static PipelineColumn MakeVarKey < T > ( Rec rec ) => new AVarKey < T > ( rec ) ;
81
69
82
70
private static MethodInfo [ ] _valueTupleCreateMethod = InitValueTupleCreateMethods ( ) ;
83
71
@@ -105,7 +93,7 @@ public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>
105
93
return new ValueTuple < T1 , T2 , T3 , T4 , T5 , T6 , T7 , TRest > ( v1 , v2 , v3 , v4 , v5 , v6 , v7 , restTuple ) ;
106
94
}
107
95
108
- public static object CreateAnalysisInstanceCore < T > ( Rec rec )
96
+ public static object MakeAnalysisInstanceCore < T > ( Rec rec )
109
97
{
110
98
var t = typeof ( T ) ;
111
99
if ( typeof ( PipelineColumn ) . IsAssignableFrom ( t ) )
@@ -116,20 +104,20 @@ public static object CreateAnalysisInstanceCore<T>(Rec rec)
116
104
var genT = t . GetGenericTypeDefinition ( ) ;
117
105
118
106
if ( genT == typeof ( Scalar < > ) )
119
- return Utils . MarshalInvoke ( CreateScalar < int > , genP [ 0 ] , rec ) ;
107
+ return Utils . MarshalInvoke ( MakeScalar < int > , genP [ 0 ] , rec ) ;
120
108
if ( genT == typeof ( Vector < > ) )
121
- return Utils . MarshalInvoke ( CreateVector < int > , genP [ 0 ] , rec ) ;
109
+ return Utils . MarshalInvoke ( MakeVector < int > , genP [ 0 ] , rec ) ;
122
110
if ( genT == typeof ( VarVector < > ) )
123
- return Utils . MarshalInvoke ( CreateVarVector < int > , genP [ 0 ] , rec ) ;
111
+ return Utils . MarshalInvoke ( MakeVarVector < int > , genP [ 0 ] , rec ) ;
124
112
if ( genT == typeof ( Key < > ) )
125
- return Utils . MarshalInvoke ( CreateKey < uint > , genP [ 0 ] , rec ) ;
113
+ return Utils . MarshalInvoke ( MakeKey < uint > , genP [ 0 ] , rec ) ;
126
114
if ( genT == typeof ( Key < , > ) )
127
115
{
128
- Func < Rec , PipelineColumn > f = CreateKey < uint , int > ;
116
+ Func < Rec , PipelineColumn > f = MakeKey < uint , int > ;
129
117
return f . Method . GetGenericMethodDefinition ( ) . MakeGenericMethod ( genP ) . Invoke ( null , new object [ ] { rec } ) ;
130
118
}
131
119
if ( genT == typeof ( VarKey < > ) )
132
- return Utils . MarshalInvoke ( CreateVector < int > , genP [ 0 ] , rec ) ;
120
+ return Utils . MarshalInvoke ( MakeVector < int > , genP [ 0 ] , rec ) ;
133
121
}
134
122
throw Contracts . Except ( $ "Type { t } is a { nameof ( PipelineColumn ) } yet does not appear to be directly one of " +
135
123
$ "the official types. This is commonly due to a mistake by the component author and can be addressed by " +
@@ -144,7 +132,7 @@ public static object CreateAnalysisInstanceCore<T>(Rec rec)
144
132
if ( 1 <= genP . Length && genP . Length <= 8 )
145
133
{
146
134
// First recursively create the sub-analysis objects.
147
- object [ ] subArgs = genP . Select ( subType => Utils . MarshalInvoke ( CreateAnalysisInstanceCore < int > , subType , rec ) ) . ToArray ( ) ;
135
+ object [ ] subArgs = genP . Select ( subType => Utils . MarshalInvoke ( MakeAnalysisInstanceCore < int > , subType , rec ) ) . ToArray ( ) ;
148
136
// Next create the tuple.
149
137
return _valueTupleCreateMethod [ subArgs . Length - 1 ] . MakeGenericMethod ( genP ) . Invoke ( null , subArgs ) ;
150
138
}
0 commit comments