Github user imatiach-msft commented on a diff in the pull request: https://github.com/apache/spark/pull/20168#discussion_r160258674 --- Diff: mllib/src/main/scala/org/apache/spark/ml/image/ImageSchema.scala --- @@ -37,20 +37,51 @@ import org.apache.spark.sql.types._ @Since("2.3.0") object ImageSchema { - val undefinedImageType = "Undefined" - /** - * (Scala-specific) OpenCV type mapping supported + * OpenCv type representation + * @param mode ordinal for the type + * @param dataType open cv data type + * @param nChannels number of color channels */ - val ocvTypes: Map[String, Int] = Map( - undefinedImageType -> -1, - "CV_8U" -> 0, "CV_8UC1" -> 0, "CV_8UC3" -> 16, "CV_8UC4" -> 24 - ) + case class OpenCvType(mode: Int, dataType: String, nChannels: Int) { + def name: String = "CV_" + dataType + "C" + nChannels + override def toString: String = "OpenCvType(mode = " + mode + ", name = " + name + ")" + } + + object OpenCvType { + def get(name: String): OpenCvType = { + ocvTypes.find(x => x.name == name).getOrElse( + throw new IllegalArgumentException("Unknown open cv type " + name)) + } + def get(mode: Int): OpenCvType = { + ocvTypes.find(x => x.mode == mode).getOrElse( + throw new IllegalArgumentException("Unknown open cv mode " + mode)) + } + val undefinedType = OpenCvType(-1, "N/A", -1) --- End diff -- if I understand correctly the name for undefinedType will then be: def name: String = "CV_" + dataType + "C" + nChannels which is "CV_-1C-1"? But below in the tests you are checking for the name to be "Undefined"? If this is correct, can it be fixed by overriding the name to check if datatype is N/A or something similar and in that case using a name of Undefined?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org