@Override protected String toString(Object array, int index) { return ForNonArrayType.FLOAT.toString(Array.getFloat(array, index)); } },
protected String arrayToString(Object o) { int len = Array.getLength(o); Class c = o.getClass().getComponentType(); String res = "[ "; for (int i = 0; i < len; i++) { if ( c == byte.class ) res+=Array.getByte(o,i); if ( c == boolean.class ) res+=Array.getBoolean(o, i); if ( c == char.class ) res+=Array.getChar(o, i); if ( c == short.class ) res+=Array.getShort(o, i); if ( c == int.class ) res+=Array.getInt(o, i); if ( c == long.class ) res+=Array.getLong(o, i); if ( c == float.class ) res+=Array.getFloat(o, i); if ( c == double.class ) res+=Array.getDouble(o, i); if ( i < len-1) res+=","; } res += " ]"; return res; }
if (i != 0) string.append(' '); String s = format.format(Array.getFloat(o, i)); string.append(s.equals("-0") ? "0" : s);
protected String arrayToString(Object o) { int len = Array.getLength(o); Class c = o.getClass().getComponentType(); String res = "[ "; for (int i = 0; i < len; i++) { if ( c == byte.class ) res+=Array.getByte(o,i); if ( c == boolean.class ) res+=Array.getBoolean(o, i); if ( c == char.class ) res+=Array.getChar(o, i); if ( c == short.class ) res+=Array.getShort(o, i); if ( c == int.class ) res+=Array.getInt(o, i); if ( c == long.class ) res+=Array.getLong(o, i); if ( c == float.class ) res+=Array.getFloat(o, i); if ( c == double.class ) res+=Array.getDouble(o, i); if ( i < len-1) res+=","; } res += " ]"; return res; }
out.writeIntPacked(length); for ( int i = 0; i < length; i++ ) { out.writeTag(Array.getFloat(infoOrObject, i));
out.writeIntPacked(length); for ( int i = 0; i < length; i++ ) { out.writeTag(Array.getFloat(infoOrObject, i));
dest[i] = Array.getFloat(array, i);
@Override public Object get(Object array, int index) { return Array.getFloat(array, index); }
public float get(int r, int c) { Object row = Array.get(_matrix, r); if (row == null) { throw new ArrayIndexOutOfBoundsException("index out of bounds: " + r); } return Array.getFloat(row, c); }
private void setChannels(Object value) { Frame i = (Frame) information; channels = i.channels; if (Array.getLength(value) == 0) { information.put(FA_CHANNEL_MAPPING, value); return; } if (i.mode == DUAL_CHANNEL && (Array.getFloat(value, 0) == 1) && (Array.getFloat(value, 1) == 0)) { whichChannels = LEFT_CHANNEL; channels = 2; } else if (i.mode == DUAL_CHANNEL && (Array.getFloat(value, 1) == 0) && (Array.getFloat(value, 0) == 1)) { whichChannels = RIGHT_CHANNEL; channels = 2; } else { whichChannels = STANDARD; if (outputChannels == 1) { value = MONO_ARRAY; } else { value = STANDARD_ARRAY; } } information.put(FA_CHANNEL_MAPPING, value); }
@Override protected String toString(Object array, int index) { return ForNonArrayType.FLOAT.toString(Array.getFloat(array, index)); } },
/** * @param The values Object array reference. * @param The weights Object array reference. * @return Double containing weigted average. */ public static Double weightedAverage (Object values, Object weights) { Double retVal = new Double(0); try { // First sanity check the weights - if they don't add up to 1 // we should probably throw an exception. float wSum = 0f; for (int i=0;i<Array.getLength(weights);i++) wSum+=Array.getFloat(weights,i); // if (wSum != 0) throw Something! for (int i=0;i<Array.getLength(values);i++) { retVal = runningAverage (retVal,Array.get(values,i), i+1, Array.getFloat(weights,i)); } } catch (Exception e) { e.printStackTrace(); } return retVal; }
/** * Byte order reverses an <code>Array</code> of <code>floats</code> * * @param array input array */ private static void swapFloatArray(Object array) { int len = Array.getLength(array); float ftmp; int tmp; int b1, b2, b3, b4; for (int i = 0; i < len; i++) { ftmp = Array.getFloat(array, i); tmp = Float.floatToIntBits(ftmp); b1 = (tmp >> 0) & 0xff; b2 = (tmp >> 8) & 0xff; b3 = (tmp >> 16) & 0xff; b4 = (tmp >> 24) & 0xff; tmp = b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0; ftmp = Float.intBitsToFloat(tmp); Array.setFloat(array, i, ftmp); } }
/** * Returns the value of the indexed component in the specified * array object, as a {@code double}. * * @param array the array * @param index the index * @return the value of the indexed component in the specified array * @exception NullPointerException If the specified object is null * @exception IllegalArgumentException If the specified object is not * an array, or if the indexed element cannot be converted to the * return type by an identity or widening conversion * @exception ArrayIndexOutOfBoundsException If the specified {@code index} * argument is negative, or if it is greater than or equal to the * length of the specified array * @see Array#get */ public static double getDouble(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException { final Class<?> t = array.getClass().getComponentType(); if (MethodImpl.samePrimitive(t, Double.TYPE)) { double[] arr = (double[]) array; return arr[index]; } return getFloat(array, index); }
/** * Returns the value of the indexed component in the specified * array object, as a {@code double}. * * @param array the array * @param index the index * @return the value of the indexed component in the specified array * @exception NullPointerException If the specified object is null * @exception IllegalArgumentException If the specified object is not * an array, or if the indexed element cannot be converted to the * return type by an identity or widening conversion * @exception ArrayIndexOutOfBoundsException If the specified {@code index} * argument is negative, or if it is greater than or equal to the * length of the specified array * @see Array#get */ public static double getDouble(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException { final Class<?> t = array.getClass().getComponentType(); if (MethodImpl.samePrimitive(t, Double.TYPE)) { double[] arr = (double[]) array; return arr[index]; } return getFloat(array, index); }
/** * @throws IOException * @see org.apache.wicket.util.io.ClassStreamHandler.PrimitiveArray#writeArray(Object, * WicketObjectOutputStream) */ public void writeArray(Object object, WicketObjectOutputStream dos) throws IOException { int length = Array.getLength(object); dos.writeInt(length); for (int i = 0; i < length; i++) { dos.writeFloat(Array.getFloat(object, i)); } }
/** * @throws IOException * @see org.apache.wicket.util.io.ClassStreamHandler.PrimitiveArray#writeArray(Object, * WicketObjectOutputStream) */ @Override public void writeArray(Object object, WicketObjectOutputStream dos) throws IOException { int length = Array.getLength(object); dos.writeInt(length); for (int i = 0; i < length; i++) { dos.writeFloat(Array.getFloat(object, i)); } }
public static Object toObject(Object value) { if (!value.getClass().isArray()) return value; Class type = value.getClass().getComponentType(); if (Array.getLength(value) == 0) return null; if (!type.isPrimitive()) return Array.get(value, 0); if (boolean.class.isAssignableFrom(type)) return Array.getBoolean(value, 0); if (char.class.isAssignableFrom(type)) return new Character(Array.getChar(value, 0)); if (byte.class.isAssignableFrom(type)) return new Byte(Array.getByte(value, 0)); if (int.class.isAssignableFrom(type)) return new Integer(Array.getInt(value, 0)); if (long.class.isAssignableFrom(type)) return new Long(Array.getLong(value, 0)); if (short.class.isAssignableFrom(type)) return new Short(Array.getShort(value, 0)); if (double.class.isAssignableFrom(type)) return new Double(Array.getDouble(value, 0)); if (float.class.isAssignableFrom(type)) return new Float(Array.getFloat(value, 0)); return null; }
@JTranscSync public static Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException { Type elementType = getArrayElementType(array.getClass()); if (elementType == Boolean.TYPE) return getBoolean(array, index); if (elementType == Byte.TYPE) return getByte(array, index); if (elementType == Character.TYPE) return getChar(array, index); if (elementType == Short.TYPE) return getShort(array, index); if (elementType == Integer.TYPE) return getInt(array, index); if (elementType == Long.TYPE) return getLong(array, index); if (elementType == Float.TYPE) return getFloat(array, index); if (elementType == Double.TYPE) return getDouble(array, index); return getInstance(array, index); }
private void putArrayElementValues(char elementType, @Nonnull Object array) { int length = Array.getLength(array); putArrayLength(length); for (int i = 0; i < length; i++) { if (elementType == 'J') { long value = Array.getLong(array, i); putLong(value); } else if (elementType == 'F') { float value = Array.getFloat(array, i); putFloat(value); } else if (elementType == 'D') { double value = Array.getDouble(array, i); putDouble(value); } else if (elementType == 'Z') { boolean value = Array.getBoolean(array, i); putBoolean(value); } else { int value = Array.getInt(array, i); putInteger(elementType, value); } } }