Reputation: 627
I have two functions:
def capPredDouble(rawPred: Double): Double = {
if (label == "1") {
Math.min(1.0, rawPred)
} else {
Math.max(0, rawPred)
}
}
def capPred(rawPred: Float): Float = {
if (label == "1") {
Math.min(1.0f, rawPred)
} else {
Math.max(0, rawPred)
}
}
Is that possible to use polymorphism to make them one function?
Upvotes: 2
Views: 253
Reputation: 51271
This appears to work.
def capPred[N](rawPred :N)(implicit ev :Numeric[N]) :N =
if (<some condition>) ev.min(ev.one, rawPred)
else ev.max(ev.zero, rawPred)
Upvotes: 3