Skip to content

Commit

Permalink
Remove unused jinja templates (#199)
Browse files Browse the repository at this point in the history
* Remove outdated jinja templates

Signed-off-by: neNasko1 <nasko119@gmail.com>

* Remove even more code

Signed-off-by: neNasko1 <nasko119@gmail.com>

* Fix license

* Update license

* Fix license

* Revert change on category mapper and tree ensemble

* Fix generation

Signed-off-by: Atanas Dimitrov <nasko119@gmail.com>

---------

Signed-off-by: neNasko1 <nasko119@gmail.com>
Signed-off-by: Atanas Dimitrov <nasko119@gmail.com>
Co-authored-by: Aditya Goel <48102515+adityagoel4512@users.noreply.github.com>
  • Loading branch information
neNasko1 and adityagoel4512 authored Jan 6, 2025
1 parent 0741557 commit 386bccb
Showing 13 changed files with 9 additions and 257 deletions.
17 changes: 0 additions & 17 deletions src/spox/opset/ai/onnx/ml/v3.py
Original file line number Diff line number Diff line change
@@ -76,9 +76,6 @@ class Inputs(BaseInputs):
class Outputs(BaseOutputs):
Y: _VarInfo

def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]:
return {"Y": self.inputs.X.type} if self.inputs.X.type is not None else {}

op_type = OpType("Binarizer", "ai.onnx.ml", 1)

attrs: Attributes
@@ -375,20 +372,6 @@ class Inputs(BaseInputs):
class Outputs(BaseOutputs):
Y: _VarInfo

def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]:
if not self.inputs.fully_typed:
return {}
if self.attrs.cats_int64s:
n_encodings = len(self.attrs.cats_int64s.value)
elif self.attrs.cats_strings:
n_encodings = len(self.attrs.cats_strings.value)
else:
raise InferenceError(
"Either `cats_int64s` or `cats_strings` attributes must be set."
)
shape = (*self.inputs.X.unwrap_tensor().shape, n_encodings) # type: ignore
return {"Y": Tensor(dtype=np.float32, shape=shape)}

op_type = OpType("OneHotEncoder", "ai.onnx.ml", 1)

attrs: Attributes
28 changes: 1 addition & 27 deletions src/spox/opset/ai/onnx/v17.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._graph import Graph, subgraph
from spox._node import OpType
from spox._standard import InferenceError, StandardNode
from spox._standard import StandardNode
from spox._type_inference_utils import loop_erase_shape_info
from spox._type_system import Sequence as SpoxSequence
from spox._type_system import Tensor, Type
@@ -500,32 +500,6 @@ class Inputs(BaseInputs):
class Outputs(BaseOutputs):
output: _VarInfo

def infer_output_types(self, input_prop_values: PropDict) -> dict[str, Type]:
self.infer_output_types_onnx(input_prop_values)
inp, cond = (
self.inputs.input.unwrap_tensor(),
self.inputs.condition.unwrap_tensor(),
)
if not inp.shape:
return {"output": Tensor(inp.dtype, None)}
if cond.dtype != np.dtype(bool):
raise InferenceError("Compress input 'condition' must be a boolean dtype.")
if cond.shape and len(cond.shape) != 1:
raise InferenceError(
"Compress input 'condition' must be a vector (of rank 1)."
)
if self.attrs.axis is not None:
shape = list(inp.shape)
axis = self.attrs.axis.value
if not (-len(shape) <= axis < len(shape)):
raise InferenceError(
f"Compress attribute 'axis' must in range [-rank, rank-1] (rank={len(shape)})."
)
shape[axis] = None
else:
shape = [None]
return {"output": Tensor(inp.dtype, tuple(shape))}

op_type = OpType("Compress", "", 11)

attrs: Attributes
6 changes: 3 additions & 3 deletions tests/type_inference/test_tree_ensemble_classifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) QuantCo 2023-2024
# Copyright (c) QuantCo 2023-2025
# SPDX-License-Identifier: BSD-3-Clause

import numpy as np
@@ -11,7 +11,7 @@
def test_tree_ensemble_regressor_inference_str():
(x,) = arguments(x=Tensor(np.float32, ("N", 5)))
y, z = op_ml.tree_ensemble_classifier(
x, classlabels_strings=["a", "b"], class_ids=[1, 2, 3]
x, classlabels_strings=["a", "b", "c"], class_ids=[1, 2, 3]
)
assert y.type == Tensor(np.str_, ("N",))
assert z.type == Tensor(np.float32, ("N", 3))
@@ -20,7 +20,7 @@ def test_tree_ensemble_regressor_inference_str():
def test_tree_ensemble_regressor_inference_int():
(x,) = arguments(x=Tensor(np.float32, ("N", 5)))
y, z = op_ml.tree_ensemble_classifier(
x, classlabels_int64s=[1, 2], class_ids=[1, 2, 3]
x, classlabels_int64s=[1, 2, 3], class_ids=[1, 2, 3]
)
assert y.type == Tensor(np.int64, ("N",))
assert z.type == Tensor(np.float32, ("N", 3))
14 changes: 5 additions & 9 deletions tools/generate_opset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) QuantCo 2023-2024
# Copyright (c) QuantCo 2023-2025
# SPDX-License-Identifier: BSD-3-Clause

from __future__ import annotations
@@ -668,7 +668,7 @@ def main(
"ai.onnx",
17,
extras=["const"],
type_inference={"Compress": "compress11", "Loop": "loop16-fix"},
type_inference={"Loop": "loop16-fix"},
value_propagation={"Constant": "constant13"},
out_variadic_solutions=V16_OUT_VARIADIC_SOLUTIONS,
subgraphs_solutions=V16_SUBGRAPH_SOLUTIONS,
@@ -680,7 +680,7 @@ def main(
"ai.onnx",
18,
extras=["const"],
type_inference={"Compress": "compress11"},
type_inference={},
value_propagation={"Constant": "constant13"},
out_variadic_solutions=V18_OUT_VARIADIC_SOLUTIONS,
subgraphs_solutions=V16_SUBGRAPH_SOLUTIONS,
@@ -692,7 +692,7 @@ def main(
"ai.onnx",
19,
extras=["const"],
type_inference={"Compress": "compress11", "Loop": "loop16-fix"},
type_inference={"Loop": "loop16-fix"},
value_propagation={"Constant": "constant13"},
out_variadic_solutions=V18_OUT_VARIADIC_SOLUTIONS,
subgraphs_solutions=V16_SUBGRAPH_SOLUTIONS,
@@ -715,7 +715,7 @@ def main(
"ai.onnx",
21,
extras=["const"],
type_inference={"Compress": "compress11", "Loop": "loop16-fix"},
type_inference={"Loop": "loop16-fix"},
value_propagation={"Constant": "constant13"},
out_variadic_solutions=V18_OUT_VARIADIC_SOLUTIONS,
subgraphs_solutions=V16_SUBGRAPH_SOLUTIONS,
@@ -729,12 +729,10 @@ def main(
attr_type_overrides=[(None, "dtype", ("npt.DTypeLike", "AttrDtype"))],
type_inference={
"ArrayFeatureExtractor": "arrayfeatureextractor1",
"Binarizer": "binarizer1",
"CategoryMapper": "categorymapper1",
"Imputer": "imputer1",
"LinearRegressor": "linearregressor1",
"Normalizer": "normalizer1",
"OneHotEncoder": "onehotencoder1",
"Scaler": "scaler1",
"TreeEnsembleClassifier": "treeensembleclassifier3",
"TreeEnsembleRegressor": "treeensembleregressor3",
@@ -746,7 +744,6 @@ def main(
4,
attr_type_overrides=[(None, "dtype", ("npt.DTypeLike", "AttrDtype"))],
type_inference={
"Binarizer": "binarizer1",
"Imputer": "imputer1",
"LinearRegressor": "linearregressor1",
"Normalizer": "normalizer1",
@@ -760,7 +757,6 @@ def main(
5,
attr_type_overrides=[(None, "dtype", ("npt.DTypeLike", "AttrDtype"))],
type_inference={
"Binarizer": "binarizer1",
"Imputer": "imputer1",
"LinearRegressor": "linearregressor1",
"Normalizer": "normalizer1",
25 changes: 0 additions & 25 deletions tools/templates/extras/promote.jinja2

This file was deleted.

25 changes: 0 additions & 25 deletions tools/templates/extras/xif.jinja2

This file was deleted.

33 changes: 0 additions & 33 deletions tools/templates/extras/xloop.jinja2

This file was deleted.

1 change: 0 additions & 1 deletion tools/templates/type_inference/binarizer1.jinja2

This file was deleted.

17 changes: 0 additions & 17 deletions tools/templates/type_inference/compress11.jinja2

This file was deleted.

16 changes: 0 additions & 16 deletions tools/templates/type_inference/if16.jinja2

This file was deleted.

49 changes: 0 additions & 49 deletions tools/templates/type_inference/loop16.jinja2

This file was deleted.

21 changes: 0 additions & 21 deletions tools/templates/type_inference/onehot11.jinja2

This file was deleted.

14 changes: 0 additions & 14 deletions tools/templates/type_inference/onehotencoder1.jinja2

This file was deleted.

0 comments on commit 386bccb

Please sign in to comment.