Example usage for com.google.common.primitives Floats asList

List of usage examples for com.google.common.primitives Floats asList

Introduction

In this page you can find the example usage for com.google.common.primitives Floats asList.

Prototype

public static List<Float> asList(float... backingArray) 

Source Link

Document

Returns a fixed-size list backed by the specified array, similar to Arrays#asList(Object[]) .

Usage

From source file:demo.project.model.StackedRankColumnSpec.java

@Override
public void save(ARankColumnModel model) {
    StackedRankColumnModel m = (StackedRankColumnModel) model;
    this.alignment = m.getAlignment();
    this.compressed = m.isCompressed();
    this.singleAlignment = m.getSingleAlignment();
    weights = Floats.asList(m.getWeights());
    super.save(model);
}

From source file:org.truth0.subjects.PrimitiveFloatArraySubject.java

@Override
protected List<Float> listRepresentation() {
    return Floats.asList(getSubject());
}

From source file:org.trustedanalytics.scoringengine.ATKScoringEngine.java

private String convertToCommaSeparated(float[] data) {

    return Floats.asList(data).stream().map(i -> String.format("%.4f", i)).collect(Collectors.joining(","));
}

From source file:org.trustedanalytics.process.DataConsumer.java

@Override
public void processMessage(float[] message) {
    LOG.debug("message: {}", message);

    // minimal requirement is a class and one characteristics value
    if (message.length < 2) {
        LOG.warn("Bad input data format: we're looking for at least 2 array elements, but got only {}",
                message.length);//from  ww  w.  ja v  a2s . c o  m
        return;
    }

    float score = message[0];
    float[] featureVector = Arrays.copyOfRange(message, 1, message.length);

    LOG.debug("score: {}", score);
    LOG.debug("featureVector: {}", featureVector);

    try {
        boolean isNormal = scoringEngine.apply(featureVector);
        if (!isNormal) {
            LOG.debug("Anomaly detected - store info in Influx");
            scoringStore.accept((double) score);
        } else {
            LOG.debug("No anomaly detected");
        }

        double[] prefix = { isNormal ? 0d : 1d };
        double[] row = ArrayUtils.addAll(prefix, Doubles.toArray(Floats.asList(message)));

        featuresStore.accept(ArrayUtils.toObject(row));
    } catch (Exception ex) {
        LOG.error("Procesing feature vector failed", ex);
    }
}

From source file:com.example.basic.PublicMethodInvoker.java

public String invokeAllPublicArrayMethods(AllAccessMethods allAccessMethods) {
    StringBuilder result = new StringBuilder();
    result.append(Joiner.on(':').join(allAccessMethods.publicStringArrayMethod(new String[] { "invoker" })));
    result.append('-');
    result.append(Joiner.on(':').join(Ints.asList(allAccessMethods.publicIntArrayMethod(new int[] { 5 }))));
    result.append('-');
    result.append(Joiner.on(':').join(Longs.asList(allAccessMethods.publicLongArrayMethod(new long[] { 3 }))));
    result.append('-');
    result.append(//  www .j av a 2  s  . co  m
            Joiner.on(':').join(Chars.asList(allAccessMethods.publicCharArrayMethod(new char[] { 'a' }))));
    result.append('-');
    result.append(Joiner.on(':')
            .join(Booleans.asList(allAccessMethods.publicBooleanArrayMethod(new boolean[] { false }))));
    result.append('-');
    result.append(
            Joiner.on(':').join(Floats.asList(allAccessMethods.publicFloatArrayMethod(new float[] { 12f }))));
    result.append('-');
    result.append(Joiner.on(':')
            .join(Doubles.asList(allAccessMethods.publicDoubleArrayMethod(new double[] { 56d }))));
    result.append('-');
    result.append(myField);
    allAccessMethods.voidMethod();
    return result.toString();
}

From source file:org.truth0.subjects.PrimitiveFloatArraySubject.java

/**
 * A proposition that the provided float[] is an array of the same length and type, and
 * contains elements such that each element in {@code expected} is equal to each element
 * in the subject, and in the same position.
 *///www.  ja  v a 2  s.  c om
public void isEqualTo(Object expected, float tolerance) {
    float[] actual = getSubject();
    if (actual == expected) {
        return; // short-cut.
    }
    try {
        float[] expectedArray = (float[]) expected;
        if (expectedArray.length != actual.length) {
            failWithRawMessage("Arrays are of different lengths." + "expected: %s, actual %s",
                    Arrays.asList(expectedArray), Arrays.asList(actual));
        }
        List<Integer> unequalIndices = new ArrayList<Integer>();
        for (int i = 0; i < expectedArray.length; i++) {
            if (!MathUtil.equals(actual[i], expectedArray[i], tolerance)) {
                unequalIndices.add(i);
            }
        }

        if (!unequalIndices.isEmpty()) {
            fail("is equal to", Floats.asList(expectedArray));
        }
    } catch (ClassCastException e) {
        failWithBadType(expected);
    }
}

From source file:com.ibm.common.geojson.Position.java

@Override
public Iterator<Float> iterator() {
    return Floats.asList(values()).iterator();
}

From source file:org.truth0.subjects.PrimitiveFloatArraySubject.java

public void isNotEqualTo(Object expectedArray, float tolerance) {
    float[] actual = getSubject();
    try {/* w  w w  .ja v  a2  s.c  om*/
        float[] expected = (float[]) expectedArray;
        if (actual == expected) {
            failWithRawMessage("%s unexpectedly equal to %s", getDisplaySubject(), Floats.asList(expected));
        }
        if (expected.length != actual.length) {
            return; // Unequal-lengthed arrays are not equal.
        }
        List<Integer> unequalIndices = new ArrayList<Integer>();
        for (int i = 0; i < expected.length; i++) {
            if (!MathUtil.equals(actual[i], expected[i], tolerance)) {
                unequalIndices.add(i);
            }
        }
        if (unequalIndices.isEmpty()) {
            failWithRawMessage("%s unexpectedly equal to %s", getDisplaySubject(), Floats.asList(expected));
        }
    } catch (ClassCastException ignored) {
    } // Unequal since they are of different types.
}

From source file:eu.esdihumboldt.hale.common.instance.model.InstanceUtil.java

private static List<?> arrayToList(Object array) {
    if (array instanceof byte[]) {
        return Bytes.asList((byte[]) array);
    }/*from  ww  w  . j a  v a  2 s.  co m*/
    if (array instanceof int[]) {
        return Ints.asList((int[]) array);
    }
    if (array instanceof short[]) {
        return Shorts.asList((short[]) array);
    }
    if (array instanceof long[]) {
        return Longs.asList((long[]) array);
    }
    if (array instanceof float[]) {
        return Floats.asList((float[]) array);
    }
    if (array instanceof double[]) {
        return Doubles.asList((double[]) array);
    }
    if (array instanceof char[]) {
        return Chars.asList((char[]) array);
    }
    if (array instanceof boolean[]) {
        return Booleans.asList((boolean[]) array);
    }
    return Arrays.asList((Object[]) array);
}

From source file:edu.illinois.cs.cogcomp.sl.util.FeatureVectorBuffer.java

/**
 * Construct a feature buffer by indices and values arrays.
 * Note that we do not validate the feature indices here.
 * @param fIdxArray//from  www.j  a  va 2  s .  co  m
 * @param fValueArray
 */
public FeatureVectorBuffer(int[] fIdxArray, float[] fValueArray) {
    assert fIdxArray.length == fValueArray.length;
    idxList = new ArrayList<Integer>(Ints.asList(fIdxArray));
    valList = new ArrayList<Float>(Floats.asList(fValueArray));
}