Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Onnxruntime OnnxJavaType

From Leeroopedia
Revision as of 10:46, 27 September 2026 by Agent (talk | contribs) (Sync from local file)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources Description
Source File java/src/main/java/ai/onnxruntime/OnnxJavaType.java
Repository Microsoft/onnxruntime

Domains

  • Machine Learning Runtime
  • Type System
  • JNI Type Mapping

Overview

OnnxJavaType is a public enum representing the Java primitive types (and String) supported by the ONNX Runtime Java binding. Each enum constant carries a native integer value, a Java Class object, and a byte size. The enum provides bidirectional mapping between Java classes, native integer identifiers, and OnnxTensorType enum values.

Description

The enum defines the following types:

  • FLOAT (value=1, float.class, 4 bytes)
  • DOUBLE (value=2, double.class, 8 bytes)
  • INT8 (value=3, byte.class, 1 byte)
  • INT16 (value=4, short.class, 2 bytes)
  • INT32 (value=5, int.class, 4 bytes)
  • INT64 (value=6, long.class, 8 bytes)
  • BOOL (value=7, boolean.class, 1 byte)
  • STRING (value=8, String.class, 4 bytes)
  • UINT8 (value=9, byte.class, 1 byte)
  • FLOAT16 (value=10, short.class, 2 bytes)
  • BFLOAT16 (value=11, short.class, 2 bytes)
  • UNKNOWN (value=0, Object.class, 0 bytes)

Static methods:

  • mapFromInt(int) converts native integer to enum
  • mapFromOnnxTensorType(OnnxTensorType) converts from native ONNX tensor type
  • mapFromClass(Class) converts from Java class (both primitive and boxed)

Code Reference

Source Location

// File: java/src/main/java/ai/onnxruntime/OnnxJavaType.java
// Package: ai.onnxruntime

Signature

public enum OnnxJavaType {
    FLOAT(1, float.class, 4), DOUBLE(2, double.class, 8),
    INT8(3, byte.class, 1), INT16(4, short.class, 2),
    INT32(5, int.class, 4), INT64(6, long.class, 8),
    BOOL(7, boolean.class, 1), STRING(8, String.class, 4),
    UINT8(9, byte.class, 1), FLOAT16(10, short.class, 2),
    BFLOAT16(11, short.class, 2), UNKNOWN(0, Object.class, 0);

    public final int value;
    public final Class<?> clazz;
    public final int size;

    public static OnnxJavaType mapFromInt(int value);
    public static OnnxJavaType mapFromOnnxTensorType(OnnxTensorType onnxValue);
    public static OnnxJavaType mapFromClass(Class<?> clazz);
}

Import

import ai.onnxruntime.OnnxJavaType;

I/O Contract

Inputs

Name Type Description
value int Native integer identifier to map to an OnnxJavaType
onnxValue OnnxTensorType Native ONNX tensor type to convert
clazz Class<?> Java class to map (supports both primitive and boxed types)

Outputs

Name Type Description
OnnxJavaType OnnxJavaType The corresponding enum constant (UNKNOWN if unmapped)

Usage Examples

import ai.onnxruntime.OnnxJavaType;
import ai.onnxruntime.TensorInfo.OnnxTensorType;

// Map from a Java class
OnnxJavaType floatType = OnnxJavaType.mapFromClass(float.class); // FLOAT
OnnxJavaType intType = OnnxJavaType.mapFromClass(Integer.class);  // INT32

// Map from native tensor type
OnnxJavaType fromNative = OnnxJavaType.mapFromOnnxTensorType(
    OnnxTensorType.ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16); // FLOAT16

// Access type properties
System.out.println("Type: " + floatType);         // FLOAT
System.out.println("Size: " + floatType.size);     // 4
System.out.println("Class: " + floatType.clazz);   // float

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment