1 /*
2 * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package oracle.code.onnx;
27
28 import java.io.Serializable;
29 import java.util.List;
30
31 // https://onnx.ai/onnx/api/defs.html#class-opschema
32 public record OpSchema(
33 String file,
34 int line,
35 SupportLevel support_level,
36 String doc,
37 int since_version,
38 boolean deprecated,
39 String domain,
40 String name,
41 int min_input,
42 int max_input,
43 int min_output,
44 int max_output,
45 List<Attribute> attributes,
46 List<FormalParameter> inputs,
47 List<FormalParameter> outputs,
48 List<TypeConstraintParam> type_constraints,
49 boolean has_function,
50 boolean has_context_dependent_function,
51 boolean has_data_propagation_function,
52 boolean has_type_and_shape_inference_function
53 ) implements Serializable {
54 public enum SupportLevel implements Serializable {
55 COMMON,
56 EXPERIMENTAL
57 }
58
59 public enum AttributeType implements Serializable {
60 FLOAT(float.class),
61 INT(long.class),
62 STRING(String.class),
63 // @@@ proto
64 TENSOR(Tensor.class),
65 // proto
66 GRAPH(byte[].class),
67 SPARSE_TENSOR(byte[].class),
68 // @@@ Map<K, V>, Opaque, Optional<T>, Sequence<T>, SparseTensor<T>, Tensor<T>
69 // OnnxTypeElement?
70 TYPE_PROTO(Object.class),
71 FLOATS(float[].class),
72 INTS(long[].class),
73 STRINGS(String[].class),
74 // @@@ proto
75 TENSORS(Tensor[].class),
76 // @@@ proto
77 GRAPHS(byte[][].class),
78 // @@@ proto
79 SPARSE_TENSORS(byte[][].class),
80 TYPE_PROTOS(Object[].class)
81 ;
82
83 final Class<?> type;
84
85 AttributeType(Class<?> type) {
86 this.type = type;
87 }
88
89 public Class<?> type() {
90 return type;
91 }
92 }
93
94 public record Attribute(
95 String name,
96 String description,
97 AttributeType type,
98 Object default_value,
99 boolean required
100 ) implements Serializable {
101 }
102
103 public enum FormalParameterOption implements Serializable {
104 Single,
105 Optional,
106 Variadic
107 }
108
109 public enum DifferentiationCategory implements Serializable {
110 Unknown,
111 Differentiable,
112 NonDifferentiable
113 }
114
115 public record FormalParameter(
116 String name,
117 // @@@ List<String>
118 String types,
119 String type_str,
120 String description,
121 FormalParameterOption option,
122 boolean is_homogeneous,
123 int min_arity,
124 DifferentiationCategory differentiation_category
125 ) implements Serializable {
126 }
127
128 public record TypeConstraintParam(
129 String type_param_str,
130 String description,
131 List<String> allowed_type_strs
132 ) implements Serializable {
133 }
134 }