@Test public void testToUnsignedInteger() { float[] da = {0.2f, -0.4f, 0.6f}; int[] ia = FloatArrays.toUnsignedInteger(da, 6); Assert.assertEquals((int) (0.2f * 3.0f), ia[0]); Assert.assertEquals((int) (-0.4f * 3.0f), ia[1]); }
public static int[] toUnsignedInteger(float[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] arr = new int[input.length]; float divider = (float) ((double) max / 2.0); for (int i = 0; i < input.length; i++) { float d = input[i]; if (d < -1.0 || d > 1.0) { throw new IllegalArgumentException( "Array value should be between -1.0 and 1.0. But it is: " + d); } arr[i] = (int) (input[i] * divider); } return arr; }
FloatArrays { public static int[] toUnsignedInteger(float[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] arr = new int[input.length]; float divider = (float) ((double) max / 2.0); for (int i = 0; i < input.length; i++) { float d = input[i]; if (d < -1.0 || d > 1.0) { throw new IllegalArgumentException( "Array value should be between -1.0 and 1.0. But it is: " + d); } arr[i] = (int) (input[i] * divider); } return arr; } }
FloatArrays { public static int[] toUnsignedInteger(float[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] arr = new int[input.length]; float divider = (float) ((double) max / 2.0); for (int i = 0; i < input.length; i++) { float d = input[i]; if (d < -1.0 || d > 1.0) { throw new IllegalArgumentException( "Array value should be between -1.0 and 1.0. But it is: " + d); } arr[i] = (int) (input[i] * divider); } return arr; } private  FloatArrays(); }
FloatArrays { public static int[] toUnsignedInteger(float[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] arr = new int[input.length]; float divider = (float) ((double) max / 2.0); for (int i = 0; i < input.length; i++) { float d = input[i]; if (d < -1.0 || d > 1.0) { throw new IllegalArgumentException( "Array value should be between -1.0 and 1.0. But it is: " + d); } arr[i] = (int) (input[i] * divider); } return arr; } private  FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input); static float[][] convert(int[][] input); static float[] convert(double[] input); static boolean arrayEqualsInRange(float[] d1, float[] d2, float range); static boolean arrayEquals(float[] d1, float[] d2); static float[] appendZeros(float[] darray, int zeroAmountToAppend); static float[] normalize16bitLittleEndian(byte[] bytez); static float[] normalize16bitLittleEndian(byte[] bytez, int amount); static byte[] denormalize16BitLittleEndian(float[] input); static int[] toUnsignedInteger(float[] input, int max); static int[] toInteger(float[] input, int min, int max); static float max(float... input); static void trimValues(float[] input, float minVal, float maxVal); static float absMax(float... input); static String format(float... input); static String format(int fractionDigits, float... input); static String format(int fractionDigits, String delimiter, float... input); static String format(int rightPad, int fractionDigits, String delimiter, float... input); static float min(float... input); static float absMin(float... input); static void validateArray(float... input); static int maxIndex(float... input); static int minIndex(float... input); static float sum(float... input); static float[] sum(float[] a1, float[] a2); static void addToFirst(float[] first, float[] second); static void addToAll(float[] data, float valueToAdd); static void addToFirstScaled(float[] first, float[] second, float scale); static float[] square(float... input); static void squareInPlace(float... input); static float[] subtract(float[] a1, float[] a2); static void subtractFromFirst(float[] first, float[] second); static float[] multiply(float[] a1, float[] a2); static float dotProduct(float[] a1, float[] a2); static void multiplyToFirst(float[] first, float[] second); static float[] scale(float[] a1, float b); static void scaleInPlace(float[] a1, float b); static float mean(float... input); static float absoluteSumOfDifferences(float[] a, float[] b); static float[] absoluteDifference(float[] a, float[] b); static void validateArrays(float[] a1, float[] a2); static float squaredSum(float[] array); static float squaredSumOfDifferences(float[] a, float[] b); static float variance(float[] input); static float standardDeviation(float[] a); static boolean containsNaN(float[] a); static boolean containsNanOrInfinite(float[] a); static void floorInPlace(float[] var, float minValue); static void nonZeroFloorInPlace(float[] data, float floor); static void normalizeInPlace(float[] data); static float[] fromString(String str, String delimiter); static void serialize(DataOutputStream dos, float[] data); static void serializeRaw(DataOutputStream dos, float[] data); static void serialize(DataOutputStream dos, float[][] data); static void serializeRaw(DataOutputStream dos, float[][] data); static float[] deserialize(DataInputStream dis); static float[] deserializeRaw(DataInputStream dis, int amount); static void deserializeRaw(DataInputStream dis, float[] result); static float[][] deserialize2d(DataInputStream dis); static void deserialize2DRaw(DataInputStream dis, float[][] result); static float[][] clone2D(float[][] result); static float[] to1D(float[][] matrix); static float[][] toMatrix(float[] vector, int dimension); static float[][] loadFromText(File input); }
FloatArrays { public static int[] toUnsignedInteger(float[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] arr = new int[input.length]; float divider = (float) ((double) max / 2.0); for (int i = 0; i < input.length; i++) { float d = input[i]; if (d < -1.0 || d > 1.0) { throw new IllegalArgumentException( "Array value should be between -1.0 and 1.0. But it is: " + d); } arr[i] = (int) (input[i] * divider); } return arr; } private  FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input); static float[][] convert(int[][] input); static float[] convert(double[] input); static boolean arrayEqualsInRange(float[] d1, float[] d2, float range); static boolean arrayEquals(float[] d1, float[] d2); static float[] appendZeros(float[] darray, int zeroAmountToAppend); static float[] normalize16bitLittleEndian(byte[] bytez); static float[] normalize16bitLittleEndian(byte[] bytez, int amount); static byte[] denormalize16BitLittleEndian(float[] input); static int[] toUnsignedInteger(float[] input, int max); static int[] toInteger(float[] input, int min, int max); static float max(float... input); static void trimValues(float[] input, float minVal, float maxVal); static float absMax(float... input); static String format(float... input); static String format(int fractionDigits, float... input); static String format(int fractionDigits, String delimiter, float... input); static String format(int rightPad, int fractionDigits, String delimiter, float... input); static float min(float... input); static float absMin(float... input); static void validateArray(float... input); static int maxIndex(float... input); static int minIndex(float... input); static float sum(float... input); static float[] sum(float[] a1, float[] a2); static void addToFirst(float[] first, float[] second); static void addToAll(float[] data, float valueToAdd); static void addToFirstScaled(float[] first, float[] second, float scale); static float[] square(float... input); static void squareInPlace(float... input); static float[] subtract(float[] a1, float[] a2); static void subtractFromFirst(float[] first, float[] second); static float[] multiply(float[] a1, float[] a2); static float dotProduct(float[] a1, float[] a2); static void multiplyToFirst(float[] first, float[] second); static float[] scale(float[] a1, float b); static void scaleInPlace(float[] a1, float b); static float mean(float... input); static float absoluteSumOfDifferences(float[] a, float[] b); static float[] absoluteDifference(float[] a, float[] b); static void validateArrays(float[] a1, float[] a2); static float squaredSum(float[] array); static float squaredSumOfDifferences(float[] a, float[] b); static float variance(float[] input); static float standardDeviation(float[] a); static boolean containsNaN(float[] a); static boolean containsNanOrInfinite(float[] a); static void floorInPlace(float[] var, float minValue); static void nonZeroFloorInPlace(float[] data, float floor); static void normalizeInPlace(float[] data); static float[] fromString(String str, String delimiter); static void serialize(DataOutputStream dos, float[] data); static void serializeRaw(DataOutputStream dos, float[] data); static void serialize(DataOutputStream dos, float[][] data); static void serializeRaw(DataOutputStream dos, float[][] data); static float[] deserialize(DataInputStream dis); static float[] deserializeRaw(DataInputStream dis, int amount); static void deserializeRaw(DataInputStream dis, float[] result); static float[][] deserialize2d(DataInputStream dis); static void deserialize2DRaw(DataInputStream dis, float[][] result); static float[][] clone2D(float[][] result); static float[] to1D(float[][] matrix); static float[][] toMatrix(float[] vector, int dimension); static float[][] loadFromText(File input); static final float[] ZERO_LENGTH_ARRAY; static final float[][] ZERO_LENGTH_MATRIX; static final Pattern FEATURE_LINES_PATTERN; }