def test_custom_runtome_ops(self): update_registered_converter( LiveDecorrelateTransformer, "SklearnLiveDecorrelateTransformer", live_decorrelate_transformer_shape_calculator, live_decorrelate_transformer_converter) data = load_iris() X = data.data dec = LiveDecorrelateTransformer() dec.fit(X) onx = to_onnx(dec, X.astype(numpy.float32)) self.assertRaise(lambda: OnnxInference(onx), RuntimeError) register_operator(OpEig, name='Eig', overwrite=False) oinf = OnnxInference(onx, runtime='python_compiled') oinf = OnnxInference(onx) exp = dec.transform(X.astype(numpy.float32)) got = oinf.run({'X': X.astype(numpy.float32)})['variable'] self.assertEqualArray(exp, got)
live_decorrelate_transformer_shape_calculator, live_decorrelate_transformer_converter) ####################################### # Final example # +++++++++++++ data = load_iris() X = data.data dec = LiveDecorrelateTransformer() dec.fit(X) onx = to_onnx(dec, X.astype(numpy.float32)) register_operator(OpEig, name='Eig', overwrite=False) oinf = OnnxInference(onx) exp = dec.transform(X.astype(numpy.float32)) got = oinf.run({'X': X.astype(numpy.float32)})['variable'] def diff(p1, p2): p1 = p1.ravel() p2 = p2.ravel() d = numpy.abs(p2 - p1) return d.max(), (d / numpy.abs(p1)).max() print(diff(exp, got))