Skip to content

Commit 62ca2bb

Browse files
committed
check param parent in set/get
1 parent 1622349 commit 62ca2bb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mllib/src/main/scala/org/apache/spark/ml/param/params.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,28 @@ trait Params extends Identifiable with Serializable {
131131
m.invoke(this).asInstanceOf[Param[Any]]
132132
}
133133

134-
/** Checks whether a param is explicitly set. */
135-
private[ml] def isSet(param: Param[_]): Boolean = paramMap.contains(param)
136-
137134
/**
138135
* Internal param map.
139136
*/
140137
protected val paramMap: ParamMap = ParamMap.empty
141138

139+
/** Checks whether a param is explicitly set. */
140+
protected def isSet(param: Param[_]): Boolean = paramMap.contains(param)
141+
142142
/**
143143
* Sets a parameter in the own parameter map.
144144
*/
145145
protected def set[T](param: Param[T], value: T): this.type = {
146+
require(param.parent.eq(this))
146147
paramMap.put(param.asInstanceOf[Param[Any]], value)
147148
this
148149
}
149150

151+
/**
152+
* Gets the value of a parameter.
153+
*/
150154
protected def get[T](param: Param[T]): T = {
155+
require(param.parent.eq(this))
151156
paramMap(param)
152157
}
153158
}

0 commit comments

Comments
 (0)