| 12 | using namespace CoreML; |
| 13 | |
| 14 | int testOneHotEncoderBasic() { |
| 15 | OneHotEncoder ohe; |
| 16 | |
| 17 | /* Asserts that the type provided is allowed as a feature type by a new |
| 18 | one hot encoder appended to a model asset named "a". */ |
| 19 | ohe = OneHotEncoder(); |
| 20 | ML_ASSERT_GOOD(ohe.addInput("Int64", FeatureType::Int64())); |
| 21 | |
| 22 | ohe = OneHotEncoder(); |
| 23 | ML_ASSERT_GOOD(ohe.addInput("String", FeatureType::String())); |
| 24 | |
| 25 | /* Asserts that the type provided is not allowed as a feature type by a new |
| 26 | one hot encoder. */ |
| 27 | ohe = OneHotEncoder(); |
| 28 | |
| 29 | /* |
| 30 | Result r; |
| 31 | ML_ASSERT_GOOD(r = ohe.addInput("Double", FeatureType::Double())); |
| 32 | ML_ASSERT_EQ(r.type(), ResultType::FEATURE_TYPE_INVARIANT_VIOLATION); |
| 33 | |
| 34 | r = ohe.addInput("Image", FeatureType::Image()); |
| 35 | ML_ASSERT_EQ(r.type(), ResultType::FEATURE_TYPE_INVARIANT_VIOLATION); |
| 36 | |
| 37 | r = ohe.addInput("Array", FeatureType::Array({2,3})); |
| 38 | ML_ASSERT_EQ(r.type(), ResultType::FEATURE_TYPE_INVARIANT_VIOLATION); |
| 39 | |
| 40 | r = ohe.addInput("Dictionary", FeatureType::Dictionary(MLTypeInt64)); |
| 41 | ML_ASSERT_EQ(r.type(), ResultType::FEATURE_TYPE_INVARIANT_VIOLATION); |
| 42 | */ |
| 43 | |
| 44 | /* Asserts that the TYPE provided is generally allowed as a feature type by a |
| 45 | new one hot encoder, but has a type mismatch if that one hot encoder is added |
| 46 | to the existing model asset "a". */ |
| 47 | /* |
| 48 | ohe = OneHotEncoder(); |
| 49 | ML_ASSERT_GOOD(ohe.addInput("String", FeatureType::String())); |
| 50 | */ |
| 51 | |
| 52 | /* however, this one should still work, since it doesn't modify the type |
| 53 | * (since the underlying data is already in one-hot encoding, it's probably |
| 54 | * a no-op, but that's a decision for the execution engine and not the model |
| 55 | * serialization -- at this point in time, it's moot, as long as the types |
| 56 | * match). */ |
| 57 | /* |
| 58 | ohe = OneHotEncoder(); |
| 59 | ML_ASSERT_GOOD(ohe.addInput("Int64", FeatureType::Int64())); |
| 60 | */ |
| 61 | |
| 62 | return 0; |
| 63 | } |
nothing calls this directly
no test coverage detected