类 OrtUtil


  • public final class OrtUtil
    extends java.lang.Object
    用于与 Java 数组交互的工具代码。
    • 方法摘要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 描述
      static long elementCount​(long[] shape)
      计算此形状的张量中存储的元素数量。
      static java.lang.String[] flattenString​(java.lang.Object o)
      将多维 String 数组展平为一维 String 数组,以多维行主序读取。
      static java.lang.Object newBooleanArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 boolean 数组。
      static java.lang.Object newByteArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 byte 数组。
      static java.lang.Object newDoubleArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 double 数组。
      static java.lang.Object newFloatArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 float 数组。
      static java.lang.Object newIntArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 int 数组。
      static java.lang.Object newLongArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 long 数组。
      static java.lang.Object newShortArray​(long[] shape)
      使用提供的形状创建最多 8 维的新原始 short 数组。
      static java.lang.Object newStringArray​(long[] shape)
      使用提供的形状创建最多 8 维的新 String 数组。
      static java.lang.Object reshape​(boolean[] input, long[] shape)
      将 boolean 数组重塑为期望的 n 维数组,假设 boolean 数组按 n 维行主序存储。
      static java.lang.Object reshape​(byte[] input, long[] shape)
      将 byte 数组重塑为期望的 n 维数组,假设 byte 数组按 n 维行主序存储。
      static java.lang.Object reshape​(double[] input, long[] shape)
      将 double 数组重塑为期望的 n 维数组,假设 double 数组按 n 维行主序存储。
      static java.lang.Object reshape​(float[] input, long[] shape)
      将 float 数组重塑为期望的 n 维数组,假设 float 数组按 n 维行主序存储。
      static java.lang.Object reshape​(int[] input, long[] shape)
      将 int 数组重塑为期望的 n 维数组,假设 int 数组按 n 维行主序存储。
      static java.lang.Object reshape​(long[] input, long[] shape)
      将 long 数组重塑为期望的 n 维数组,假设 long 数组按 n 维行主序存储。
      static java.lang.Object reshape​(short[] input, long[] shape)
      将 short 数组重塑为期望的 n 维数组,假设 short 数组按 n 维行主序存储。
      static java.lang.Object reshape​(java.lang.String[] input, long[] shape)
      将 String 数组重塑为期望的 n 维数组,假设 String 数组按 n 维行主序存储。
      static long[] transformShape​(int[] shape)
      将 int 形状转换为 long 形状。
      static int[] transformShape​(long[] shape)
      将 long 形状转换为 int 形状。
      static boolean validateShape​(long[] shape)
      检查形状是否为 Java 数组的有效形状(即
      • 从类 java.lang.Object 继承的方法

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细信息

      • transformShape

        public static int[] transformShape​(long[] shape)
        将 long 形状转换为 int 形状。

        验证形状具有多于 1 个元素、少于 9 个元素,每个元素小于 Integer.MAX_VALUE 且每个条目为非负数。

        参数
        shape - long 形状。
        返回
        int 形状。
      • transformShape

        public static long[] transformShape​(int[] shape)
        将 int 形状转换为 long 形状。

        验证形状具有多于 1 个元素、少于 9 个元素且每个条目为非负数。

        参数
        shape - int 形状。
        返回
        long 形状。
      • newBooleanArray

        public static java.lang.Object newBooleanArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 boolean 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 boolean 数组。
      • newByteArray

        public static java.lang.Object newByteArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 byte 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 byte 数组。
      • newShortArray

        public static java.lang.Object newShortArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 short 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 short 数组。
      • newIntArray

        public static java.lang.Object newIntArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 int 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 int 数组。
      • newLongArray

        public static java.lang.Object newLongArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 long 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 long 数组。
      • newFloatArray

        public static java.lang.Object newFloatArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 float 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 float 数组。
      • newDoubleArray

        public static java.lang.Object newDoubleArray​(long[] shape)
        使用提供的形状创建最多 8 维的新原始 double 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 double 数组。
      • newStringArray

        public static java.lang.Object newStringArray​(long[] shape)
        使用提供的形状创建最多 8 维的新 String 数组。
        参数
        shape - 要创建的数组的形状。
        返回
        一个 double 数组。
      • reshape

        public static java.lang.Object reshape​(boolean[] input,
                                               long[] shape)
        将 boolean 数组重塑为期望的 n 维数组,假设 boolean 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - boolean 数组。
        shape - 期望的形状。
        返回
        一个 n 维 boolean 数组。
      • reshape

        public static java.lang.Object reshape​(byte[] input,
                                               long[] shape)
        将 byte 数组重塑为期望的 n 维数组,假设 byte 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - byte 数组。
        shape - 期望的形状。
        返回
        一个 n 维 byte 数组。
      • reshape

        public static java.lang.Object reshape​(short[] input,
                                               long[] shape)
        将 short 数组重塑为期望的 n 维数组,假设 short 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - short 数组。
        shape - 期望的形状。
        返回
        一个 n 维 short 数组。
      • reshape

        public static java.lang.Object reshape​(int[] input,
                                               long[] shape)
        将 int 数组重塑为期望的 n 维数组,假设 int 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - int 数组。
        shape - 期望的形状。
        返回
        一个 n 维 int 数组。
      • reshape

        public static java.lang.Object reshape​(long[] input,
                                               long[] shape)
        将 long 数组重塑为期望的 n 维数组,假设 long 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - long 数组。
        shape - 期望的形状。
        返回
        一个 n 维 long 数组。
      • reshape

        public static java.lang.Object reshape​(float[] input,
                                               long[] shape)
        将 float 数组重塑为期望的 n 维数组,假设 float 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - float 数组。
        shape - 期望的形状。
        返回
        一个 n 维 float 数组。
      • reshape

        public static java.lang.Object reshape​(double[] input,
                                               long[] shape)
        将 double 数组重塑为期望的 n 维数组,假设 double 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - double 数组。
        shape - 期望的形状。
        返回
        一个 n 维 double 数组。
      • reshape

        public static java.lang.Object reshape​(java.lang.String[] input,
                                               long[] shape)
        将 String 数组重塑为期望的 n 维数组,假设 String 数组按 n 维行主序存储。如果形状与输入之间的元素数量不匹配或形状无效,则抛出 IllegalArgumentException
        参数
        input - double 数组。
        shape - 期望的形状。
        返回
        一个 n 维 String 数组。
      • elementCount

        public static long elementCount​(long[] shape)
        计算此形状的张量中存储的元素数量。

        如果所有元素均为非负数,则将它们相乘;否则抛出 IllegalArgumentException

        参数
        shape - 要使用的形状。
        返回
        元素数量。
      • validateShape

        public static boolean validateShape​(long[] shape)
        检查形状是否为 Java 数组的有效形状(即所有值均为正数且可以由 int 表示)。
        参数
        shape - 要检查的形状。
        返回
        如果形状有效,则为 true。
      • flattenString

        public static java.lang.String[] flattenString​(java.lang.Object o)
        将多维 String 数组展平为一维 String 数组,以多维行主序读取。
        参数
        o - 一个多维 String 数组。
        返回
        一个一维 String 数组。