33// See the LICENSE file in the project root for more information.
44
55using System ;
6- using System . Reflection ;
76using Microsoft . Spark . Interop ;
87using Microsoft . Spark . Interop . Ipc ;
98using Microsoft . Spark . Sql ;
9+ using Microsoft . Spark . Utils ;
10+ using System . Collections . Generic ;
1011
1112namespace Microsoft . Spark . ML . Feature
1213{
@@ -26,12 +27,12 @@ public class Pipeline :
2627 IJavaMLWritable ,
2728 IJavaMLReadable < Pipeline >
2829 {
29- private static readonly string s_pipelineClassName = "org.apache.spark.ml.Pipeline" ;
30+ private static readonly string s_className = "org.apache.spark.ml.Pipeline" ;
3031
3132 /// <summary>
3233 /// Creates a <see cref="Pipeline"/> without any parameters.
3334 /// </summary>
34- public Pipeline ( ) : base ( s_pipelineClassName )
35+ public Pipeline ( ) : base ( s_className )
3536 {
3637 }
3738
@@ -40,7 +41,7 @@ public Pipeline() : base(s_pipelineClassName)
4041 /// <see cref="Pipeline"/> a unique ID.
4142 /// </summary>
4243 /// <param name="uid">An immutable unique ID for the object and its derivatives.</param>
43- public Pipeline ( string uid ) : base ( s_pipelineClassName , uid )
44+ public Pipeline ( string uid ) : base ( s_className , uid )
4445 {
4546 }
4647
@@ -57,24 +58,34 @@ internal Pipeline(JvmObjectReference jvmObject) : base(jvmObject)
5758 /// <returns><see cref="Pipeline"/> object</returns>
5859 public Pipeline SetStages ( JavaPipelineStage [ ] value ) =>
5960 WrapAsPipeline ( ( JvmObjectReference ) SparkEnvironment . JvmBridge . CallStaticJavaMethod (
60- "org.apache.spark.mllib.api.dotnet.MLUtils" , "setPipelineStages" ,
61- Reference , value . ToJavaArrayList ( ) ) ) ;
61+ "org.apache.spark.mllib.api.dotnet.MLUtils" ,
62+ "setPipelineStages" ,
63+ Reference ,
64+ value . ToJavaArrayList ( ) ) ) ;
6265
6366 /// <summary>
6467 /// Get the stages of pipeline instance.
6568 /// </summary>
6669 /// <returns>A sequence of <see cref="JavaPipelineStage"/> stages</returns>
6770 public JavaPipelineStage [ ] GetStages ( )
6871 {
69- JvmObjectReference [ ] jvmObjects = ( JvmObjectReference [ ] ) Reference . Invoke ( "getStages" ) ;
70- JavaPipelineStage [ ] result = new JavaPipelineStage [ jvmObjects . Length ] ;
72+ var jvmObjects = ( JvmObjectReference [ ] ) Reference . Invoke ( "getStages" ) ;
73+ var result = new JavaPipelineStage [ jvmObjects . Length ] ;
74+ Dictionary < string , Type > classMapping = JvmObjectUtils . ConstructJavaClassMapping (
75+ typeof ( JavaPipelineStage ) ,
76+ "s_className" ) ;
77+
7178 for ( int i = 0 ; i < jvmObjects . Length ; i ++ )
7279 {
73- ( string constructorClass , string methodName ) = DotnetUtils . GetUnderlyingType ( jvmObjects [ i ] ) ;
74- Type type = Type . GetType ( constructorClass ) ;
75- MethodInfo method = type . GetMethod ( methodName , BindingFlags . NonPublic | BindingFlags . Static ) ;
76- result [ i ] = ( JavaPipelineStage ) method . Invoke ( null , new object [ ] { jvmObjects [ i ] } ) ;
80+ if ( JvmObjectUtils . TryConstructInstanceFromJvmObject (
81+ jvmObjects [ i ] ,
82+ classMapping ,
83+ out JavaPipelineStage instance ) )
84+ {
85+ result [ i ] = instance ;
86+ }
7787 }
88+
7889 return result ;
7990 }
8091
@@ -91,7 +102,7 @@ override public PipelineModel Fit(DataFrame dataset) =>
91102 /// <param name="path">The path the previous <see cref="Pipeline"/> was saved to</param>
92103 /// <returns>New <see cref="Pipeline"/> object, loaded from path.</returns>
93104 public static Pipeline Load ( string path ) => WrapAsPipeline (
94- SparkEnvironment . JvmBridge . CallStaticJavaMethod ( s_pipelineClassName , "load" , path ) ) ;
105+ SparkEnvironment . JvmBridge . CallStaticJavaMethod ( s_className , "load" , path ) ) ;
95106
96107 /// <summary>
97108 /// Saves the object so that it can be loaded later using Load. Note that these objects
0 commit comments