def test_speedup_regressor64_op_version(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) opset = spd.op_version self.assertGreater(self.opset(), opset[''])
def test_speedup_regressor64_onnx(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) expected = spd.predict(X) onx = to_onnx(spd, X[:1]) oinf = OnnxInference(onx) got = oinf.run({'X': X})['variable'] self.assertEqualArray(expected, got)
def test_speedup_regressor32(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset()) spd.fit(X, y) spd.assert_almost_equal(X, decimal=5)
def test_speedup_regressor64(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) spd.assert_almost_equal(X)
def test_speedup_regressor32_weights(self): data = load_iris() X, y = data.data, data.target weights = (y.copy() + 1).astype(X.dtype) spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset()) spd.fit(X, y, weights) spd.assert_almost_equal(X, decimal=5)
def test_speedup_regressor32_numba(self): data = load_iris() X, y = data.data, data.target X = X.astype(numpy.float32) spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset(), runtime="numba") spd.fit(X, y) spd.assert_almost_equal(X, decimal=5) self.assertIn("CPUDispatch", str(spd.onnxrt_.func))
def test_speedup_regressor64_pickle(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupRegressor(LinearRegression(), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) st = BytesIO() pickle.dump(spd, st) st2 = BytesIO(st.getvalue()) spd2 = pickle.load(st2) expected = spd.predict(X) got = spd2.predict(X) self.assertEqualArray(expected, got) expected = spd.raw_predict(X) got = spd2.raw_predict(X) self.assertEqualArray(expected, got)
def test_speedup_gaussian_regressor64_onnx_numpy_python(self): X, y = make_regression( # pylint: disable=W0632 n_features=2, n_samples=100, n_targets=1, random_state=42) model = GaussianProcessRegressor(alpha=1e-5, n_restarts_optimizer=25, normalize_y=True) model.fit(X, y) expected_t = model.predict(X) onx = to_onnx(model, X[:1], target_opset=self.opset(), options={'optim': 'cdist'}) oinf = OnnxInference(onx) got = oinf.run({'X': X})['GPmean'] self.assertEqualArray(expected_t.squeeze(), got.squeeze()) spd = OnnxSpeedupRegressor(model, target_opset=self.opset(), enforce_float32=False, runtime='numpy', nopython=False, conv_options={'optim': 'cdist'}) spd.fit(X, y) expected_r = spd.raw_predict(X) self.assertEqualArray(expected_t.squeeze(), expected_r.squeeze()) oinf = OnnxInference(spd.onnx_) got = oinf.run({'X': X})['GPmean'] self.assertEqualArray(expected_r.squeeze(), got.squeeze()) onx = to_onnx(spd, X[:1]) self.assertIn('CDist', str(onx)) oinf = OnnxInference(onx) got = oinf.run({'X': X})['GPmean'] self.assertEqualArray(expected_r.squeeze(), got.squeeze()) expected = spd.predict(X) self.assertEqualArray(expected_r.squeeze(), expected.squeeze())