@@ -31,6 +31,7 @@ import org.json4s.jackson.JsonMethods._
3131import org .apache .spark .SparkException
3232import org .apache .spark .annotation .{DeveloperApi , Since }
3333import org .apache .spark .ml .linalg .{JsonMatrixConverter , JsonVectorConverter , Matrix , Vector }
34+ import org .apache .spark .ml .param .shared ._
3435import org .apache .spark .ml .util .Identifiable
3536
3637/**
@@ -249,6 +250,29 @@ object ParamValidators {
249250 def arrayLengthGt [T ](lowerBound : Double ): Array [T ] => Boolean = { (value : Array [T ]) =>
250251 value.length > lowerBound
251252 }
253+
254+ /**
255+ * Checks that either inputCols and outputCols are set or inputCol and outputCol are set. If
256+ * this is not true, an `IllegalArgumentException` is raised.
257+ * @param model
258+ */
259+ def assertColOrCols (model : Params ): Unit = {
260+ model match {
261+ case m : HasInputCols with HasInputCol if m.isSet(m.inputCols) && m.isSet(m.inputCol) =>
262+ raiseIncompatibleParamsException(" inputCols" , " inputCol" )
263+ case m : HasOutputCols with HasInputCol if m.isSet(m.outputCols) && m.isSet(m.inputCol) =>
264+ raiseIncompatibleParamsException(" outputCols" , " inputCol" )
265+ case m : HasInputCols with HasOutputCol if m.isSet(m.inputCols) && m.isSet(m.outputCol) =>
266+ raiseIncompatibleParamsException(" inputCols" , " outputCol" )
267+ case m : HasOutputCols with HasOutputCol if m.isSet(m.outputCols) && m.isSet(m.outputCol) =>
268+ raiseIncompatibleParamsException(" outputCols" , " outputCol" )
269+ case _ =>
270+ }
271+ }
272+
273+ def raiseIncompatibleParamsException (paramName1 : String , paramName2 : String ): Unit = {
274+ throw new IllegalArgumentException (s " Both ` $paramName1` and ` $paramName2` are set. " )
275+ }
252276}
253277
254278// specialize primitive-typed params because Java doesn't recognize scala.Double, scala.Int, ...
@@ -834,14 +858,6 @@ trait Params extends Identifiable with Serializable {
834858 }
835859 to
836860 }
837-
838- protected def raiseIncompatibleParamsException (paramName1 : String , paramName2 : String ): Unit = {
839- throw new IllegalArgumentException (
840- s """
841- |Both ` $paramName1` and ` $paramName2` are set, ` ${this .getClass.getName}` only supports
842- |setting either ` $paramName1` or ` $paramName2`.
843- """ .stripMargin)
844- }
845861}
846862
847863/**
0 commit comments