def test_speedup_kmeans64_op_version(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupCluster(KMeans(n_clusters=3), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) opset = spd.op_version self.assertGreater(self.opset(), opset[''])
def test_speedup_kmeans32(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupCluster(KMeans(n_clusters=3), target_opset=self.opset()) spd.fit(X, y) spd.assert_almost_equal(X, decimal=4)
def test_speedup_kmeans64(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupCluster(KMeans(n_clusters=3), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) spd.assert_almost_equal(X)
def test_speedup_kmeans32_weight(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupCluster(KMeans(n_clusters=3), target_opset=self.opset()) w = numpy.ones(y.shape, dtype=X.dtype) spd.fit(X, y, w) spd.assert_almost_equal(X, decimal=4)
def test_speedup_kmeans32_numba(self): data = load_iris() X, y = data.data, data.target X = X.astype(numpy.float32) spd = OnnxSpeedupCluster(KMeans(n_clusters=3), target_opset=self.opset(), runtime="numba", nopython=False) spd.fit(X, y) spd.assert_almost_equal(X, decimal=4) self.assertIn("CPUDispatch", str(spd.onnxrt_.func))
def test_speedup_kmeans64_onnx(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupCluster(KMeans(n_clusters=3), target_opset=self.opset(), enforce_float32=False) spd.fit(X, y) expected_label = spd.predict(X) expected_score = spd.transform(X) onx = to_onnx(spd, X[:1]) oinf = OnnxInference(onx) got = oinf.run({'X': X}) self.assertEqualArray(expected_score, got['scores']) self.assertEqualArray(expected_label, got['label'])
def test_speedup_kmeans64_pickle(self): data = load_iris() X, y = data.data, data.target spd = OnnxSpeedupCluster(KMeans(n_clusters=3), 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)