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

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

Introduction

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

Prototype

public static float[] toArray(Collection<? extends Number> collection) 

Source Link

Document

Returns an array containing each value of collection , converted to a float value in the manner of Number#floatValue .

Usage

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

@Override
public void load(ARankColumnModel model) {
    super.load(model);

    StackedRankColumnModel m = (StackedRankColumnModel) model;
    m.setAlignment(singleAlignment);//  ww w  .ja v  a2  s.c o m
    m.setAlignment(alignment);
    m.setCompressed(compressed);
    m.setWeights(Floats.toArray(weights));
}

From source file:net.larry1123.elec.util.config.fieldhanders.floats.FloatArrayListFieldHandler.java

/**
 * {@inheritDoc}//from  w ww . j  a v  a  2 s.c  o m
 */
@Override
public void setToFile(ArrayList<Float> value) {
    if (CollectionUtils.isNotEmpty(value)) {
        getPropertiesFile().setFloatArray(getPropertyKey(), Floats.toArray(value), getSpacer());
    }
}

From source file:org.terasology.persistence.typeHandling.coreTypes.FloatTypeHandler.java

@Override
public PersistedData serializeCollection(Collection<Float> value, SerializationContext context) {
    return context.create(Floats.toArray(value));
}

From source file:juicebox.tools.utils.juicer.hiccups.GPUController.java

public GPUOutputContainer process(MatrixZoomData zd, double[] normalizationVector, double[] expectedVector,
        int[] rowBounds, int[] columnBounds, int matrixSize, float[] thresholdBL, float[] thresholdDonut,
        float[] thresholdH, float[] thresholdV, NormalizationType normalizationType)
        throws NegativeArraySizeException, IOException {

    RealMatrix localizedRegionData = HiCFileTools.extractLocalBoundedRegion(zd, rowBounds[0], rowBounds[1],
            columnBounds[0], columnBounds[1], matrixSize, matrixSize, normalizationType);

    float[] observedVals = Floats
            .toArray(Doubles.asList(MatrixTools.flattenedRowMajorOrderMatrix(localizedRegionData)));

    // slice KR vector to localized region
    float[] distanceExpectedKRVector = Floats.toArray(Doubles.asList(expectedVector));

    float[] kr1CPU = Floats
            .toArray(Doubles.asList(Arrays.copyOfRange(normalizationVector, rowBounds[0], rowBounds[1])));
    float[] kr2CPU = Floats
            .toArray(Doubles.asList(Arrays.copyOfRange(normalizationVector, columnBounds[0], columnBounds[1])));

    if (kr1CPU.length < matrixSize)
        kr1CPU = ArrayTools.padEndOfArray(kr1CPU, matrixSize, Float.NaN);
    if (kr2CPU.length < matrixSize)
        kr2CPU = ArrayTools.padEndOfArray(kr2CPU, matrixSize, Float.NaN);

    float[] boundRowIndex = new float[1];
    boundRowIndex[0] = rowBounds[0];//  ww w . j  a va  2s .c om
    float[] boundColumnIndex = new float[1];
    boundColumnIndex[0] = columnBounds[0];

    //long gpu_time1 = System.currentTimeMillis();

    // transfer host (CPU) memory to device (GPU) memory
    CUdeviceptr observedKRGPU = GPUHelper.allocateInput(observedVals);
    CUdeviceptr expectedDistanceVectorGPU = GPUHelper.allocateInput(distanceExpectedKRVector);
    CUdeviceptr kr1GPU = GPUHelper.allocateInput(kr1CPU);
    CUdeviceptr kr2GPU = GPUHelper.allocateInput(kr2CPU);
    CUdeviceptr thresholdBLGPU = GPUHelper.allocateInput(thresholdBL);
    CUdeviceptr thresholdDonutGPU = GPUHelper.allocateInput(thresholdDonut);
    CUdeviceptr thresholdHGPU = GPUHelper.allocateInput(thresholdH);
    CUdeviceptr thresholdVGPU = GPUHelper.allocateInput(thresholdV);
    CUdeviceptr boundRowIndexGPU = GPUHelper.allocateInput(boundRowIndex);
    CUdeviceptr boundColumnIndexGPU = GPUHelper.allocateInput(boundColumnIndex);

    // create empty gpu arrays for the results
    int flattenedSize = matrixSize * matrixSize;
    CUdeviceptr expectedBLGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr expectedDonutGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr expectedHGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr expectedVGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr binBLGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr binDonutGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr binHGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr binVGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr observedGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);
    CUdeviceptr peakGPU = GPUHelper.allocateOutput(flattenedSize, Sizeof.FLOAT);

    // call the kernel on the card
    kernelLauncher.call(
            // inputs
            observedKRGPU,
            // output
            expectedBLGPU, expectedDonutGPU, expectedHGPU, expectedVGPU, observedGPU, binBLGPU, binDonutGPU,
            binHGPU, binVGPU, peakGPU,
            // thresholds
            thresholdBLGPU, thresholdDonutGPU, thresholdHGPU, thresholdVGPU,
            // distance expected
            expectedDistanceVectorGPU,
            // kr
            kr1GPU, kr2GPU,
            // bounds
            boundRowIndexGPU, boundColumnIndexGPU);

    // initialize memory to store GPU results
    float[] expectedBLResult = new float[flattenedSize];
    float[] expectedDonutResult = new float[flattenedSize];
    float[] expectedHResult = new float[flattenedSize];
    float[] expectedVResult = new float[flattenedSize];
    float[] binBLResult = new float[flattenedSize];
    float[] binDonutResult = new float[flattenedSize];
    float[] binHResult = new float[flattenedSize];
    float[] binVResult = new float[flattenedSize];
    float[] observedResult = new float[flattenedSize];
    float[] peakResult = new float[flattenedSize];

    // transfer device (GPU) memory to host (CPU) memory
    cuMemcpyDtoH(Pointer.to(expectedBLResult), expectedBLGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(expectedDonutResult), expectedDonutGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(expectedHResult), expectedHGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(expectedVResult), expectedVGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(binBLResult), binBLGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(binDonutResult), binDonutGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(binHResult), binHGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(binVResult), binVGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(observedResult), observedGPU, flattenedSize * Sizeof.FLOAT);
    cuMemcpyDtoH(Pointer.to(peakResult), peakGPU, flattenedSize * Sizeof.FLOAT);

    //long gpu_time2 = System.currentTimeMillis();
    //System.out.println("GPU Time: " + (gpu_time2-gpu_time1));

    int finalWidthX = rowBounds[5] - rowBounds[4];
    int finalWidthY = columnBounds[5] - columnBounds[4];

    // x2, y2 not inclusive here
    int x1 = rowBounds[2];
    int y1 = columnBounds[2];
    int x2 = x1 + finalWidthX;
    int y2 = y1 + finalWidthY;

    //System.out.println("flat = "+flattenedSize+" n = "+matrixSize+" x1 = "+x1+" x2 = "+x2+" y1 = "+y1+" y2 ="+y2);
    float[][] observedDenseCPU = GPUHelper.GPUArraytoCPUMatrix(observedResult, matrixSize, x1, x2, y1, y2);
    float[][] peakDenseCPU = GPUHelper.GPUArraytoCPUMatrix(peakResult, matrixSize, x1, x2, y1, y2);
    float[][] binBLDenseCPU = GPUHelper.GPUArraytoCPUMatrix(binBLResult, matrixSize, x1, x2, y1, y2);
    float[][] binDonutDenseCPU = GPUHelper.GPUArraytoCPUMatrix(binDonutResult, matrixSize, x1, x2, y1, y2);
    float[][] binHDenseCPU = GPUHelper.GPUArraytoCPUMatrix(binHResult, matrixSize, x1, x2, y1, y2);
    float[][] binVDenseCPU = GPUHelper.GPUArraytoCPUMatrix(binVResult, matrixSize, x1, x2, y1, y2);
    float[][] expectedBLDenseCPU = GPUHelper.GPUArraytoCPUMatrix(expectedBLResult, matrixSize, x1, x2, y1, y2);
    float[][] expectedDonutDenseCPU = GPUHelper.GPUArraytoCPUMatrix(expectedDonutResult, matrixSize, x1, x2, y1,
            y2);
    float[][] expectedHDenseCPU = GPUHelper.GPUArraytoCPUMatrix(expectedHResult, matrixSize, x1, x2, y1, y2);
    float[][] expectedVDenseCPU = GPUHelper.GPUArraytoCPUMatrix(expectedVResult, matrixSize, x1, x2, y1, y2);

    GPUHelper.freeUpMemory(new CUdeviceptr[] { observedKRGPU, expectedDistanceVectorGPU, kr1GPU, kr2GPU,
            thresholdBLGPU, thresholdDonutGPU, thresholdHGPU, thresholdVGPU, boundRowIndexGPU,
            boundColumnIndexGPU, expectedBLGPU, expectedDonutGPU, expectedHGPU, expectedVGPU, binBLGPU,
            binDonutGPU, binHGPU, binVGPU, observedGPU, peakGPU });

    return new GPUOutputContainer(observedDenseCPU, peakDenseCPU, binBLDenseCPU, binDonutDenseCPU, binHDenseCPU,
            binVDenseCPU, expectedBLDenseCPU, expectedDonutDenseCPU, expectedHDenseCPU, expectedVDenseCPU);
}

From source file:xfel.mods.arp.base.utils.reflection.PrimitiveTypeHelper.java

@Override
public Object convertToTypeArray(Collection<?> collection) {
    return Floats.toArray((Collection<? extends Number>) collection);
}

From source file:org.caleydo.core.io.parser.ascii.LinearDataParser.java

@Override
protected void parseFile(BufferedReader reader) throws IOException {
    // prepare for id setting of column IDs
    IDMappingManager columnIDMappingManager;
    IDType internalColumnIDType;// ww  w . j  av a2 s .c o m
    IDType externalColumnIDType = IDType.getIDType(dataSetDescription.getColumnIDSpecification().getIdType());

    IDTypeParsingRules parsingRules = null;
    if (dataSetDescription.getColumnIDSpecification().getIdTypeParsingRules() != null)
        parsingRules = dataSetDescription.getColumnIDSpecification().getIdTypeParsingRules();
    else if (externalColumnIDType.getIdTypeParsingRules() != null)
        parsingRules = externalColumnIDType.getIdTypeParsingRules();

    if (!dataDomain.getDataSetDescription().isTransposeMatrix()) {
        columnIDMappingManager = dataDomain.getDimensionIDMappingManager();
        internalColumnIDType = dataDomain.getDimensionIDType();
    } else {
        columnIDMappingManager = dataDomain.getRecordIDMappingManager();
        internalColumnIDType = dataDomain.getRecordIDType();
    }

    MappingType columnMappingType = columnIDMappingManager.createMap(internalColumnIDType, externalColumnIDType,
            false, true);

    // ------------- ID parsing stuff ------------------------------
    IDSpecification rowIDSpecification = dataSetDescription.getRowIDSpecification();
    IDCategory rowIDCategory = IDCategory.getIDCategory(rowIDSpecification.getIdCategory());
    IDType externalRowIDType = IDType.getIDType(rowIDSpecification.getIdType());

    IDType internalRowIDType;
    if (dataDomain.isColumnDimension())
        internalRowIDType = dataDomain.getRecordIDType();
    else
        internalRowIDType = dataDomain.getDimensionIDType();

    IDMappingManager rowIDMappingManager = IDMappingManagerRegistry.get().getIDMappingManager(rowIDCategory);

    MappingType rowMappingType = rowIDMappingManager.createMap(internalRowIDType, externalRowIDType, false,
            true);

    int columnOfRowIDs = dataSetDescription.getColumnOfRowIds();
    int columnOfColumnIDs = dataSetDescription.getRowOfColumnIDs();
    // fixme this is a hack needed to use the same datasetdescription
    int columnOfData = dataSetDescription.getParsingRules().iterator().next().getFromColumn();

    for (int headerCount = 0; headerCount < dataSetDescription.getNumberOfHeaderLines(); headerCount++) {
        reader.readLine();
    }

    String line;
    while ((line = reader.readLine()) != null) {
        String[] splitLine = line.split(dataSetDescription.getDelimiter());
        String columnID = splitLine[columnOfColumnIDs];
        String rowID = splitLine[columnOfRowIDs];

        Integer columnNumber = columnIDMappingManager.getID(externalColumnIDType, internalColumnIDType,
                columnID);
        if (columnNumber == null) {
            columnNumber = targetRawContainer.size();
            columnIDMappingManager.addMapping(columnMappingType, columnNumber, columnID);
            int nrRows = 0;
            if (targetRawContainer.size() > 0) {
                nrRows = targetRawContainer.get(0).size();
            }
            ArrayList<Float> newList = new ArrayList<Float>(nrRows);
            for (int i = 0; i < nrRows; i++) {
                newList.add(Float.NaN);
            }
            targetRawContainer.add(newList);

        }

        Integer rowNumber = rowIDMappingManager.getID(externalRowIDType, internalRowIDType, rowID);
        ArrayList<Float> column = targetRawContainer.get(columnNumber);
        if (rowNumber == null) {
            rowNumber = column.size();
            rowIDMappingManager.addMapping(rowMappingType, rowNumber, rowID);
            for (ArrayList<Float> tColumn : targetRawContainer) {
                tColumn.add(Float.NaN);
            }
        }
        try {
            float data = Float.parseFloat(splitLine[columnOfData]);
            column.set(rowNumber, data);

        } catch (NumberFormatException nfe) {
            // nothing to do, is already NAN
        }
    }

    int depth = targetRawContainer.get(0).size();
    for (ArrayList<Float> tColumn : targetRawContainer) {
        if (depth != tColumn.size())
            throw new IllegalStateException(
                    "Columns don't have the same length" + depth + " / " + tColumn.size());
        float[] fColumn = Floats.toArray(tColumn);
        FloatContainer container = new FloatContainer(fColumn);

        NumericalColumn<FloatContainer, Float> column = new NumericalColumn<>(
                dataSetDescription.getDataDescription());

        column.setRawData(container);

        dataDomain.getTable().addColumn(column);
    }
}

From source file:org.apache.flink.examples.java.ml.GPULinearRegressionWithPointers.java

private static DataP getPointersToData(String fileLocation) {
    ArrayList<Float> xs = new ArrayList<>();
    ArrayList<Float> ys = new ArrayList<>();

    try {/*from  ww w  . j  ava  2 s  . c  o  m*/
        BufferedReader br = new BufferedReader(new FileReader(fileLocation));
        String line = br.readLine();

        while (line != null) {
            String[] tokens = line.split(" ");
            xs.add(Float.valueOf(tokens[0]));
            ys.add(Float.valueOf(tokens[1]));
            line = br.readLine();
        }

        br.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    CUcontext context = new CUcontext();
    cuCtxCreate(context, 0, device);

    // get input x data from elements
    CUdeviceptr pxs = new CUdeviceptr();
    CUdeviceptr pys = new CUdeviceptr();
    CUdeviceptr pxsr = new CUdeviceptr();
    CUdeviceptr pysr = new CUdeviceptr();
    CUdeviceptr n = new CUdeviceptr();

    cuMemAlloc(pxs, Sizeof.FLOAT * xs.size());
    cuMemAlloc(pys, Sizeof.FLOAT * ys.size());
    cuMemAlloc(pxsr, Sizeof.FLOAT * xs.size());
    cuMemAlloc(pysr, Sizeof.FLOAT * ys.size());
    cuMemAlloc(n, Sizeof.INT);

    float[] vxs = Floats.toArray(xs);
    float[] vys = Floats.toArray(ys);

    cuMemcpyHtoD(pxs, Pointer.to(vxs), Sizeof.FLOAT * xs.size());
    cuMemcpyHtoD(pys, Pointer.to(vys), Sizeof.FLOAT * ys.size());
    cuMemcpyHtoD(n, Pointer.to(new int[] { xs.size() }), Sizeof.INT);

    return new DataP(pxs, pys, pxsr, pysr, n, vxs.length);
}

From source file:com.vertigo.familyplot.library.HorizontalBarGraph.java

private float[] getFloats() {
    return Floats.toArray(Collections2.transform(datapoints, new Function<Entry, Float>() {
        @Override//w w w . ja va2 s.  c om
        public Float apply(Entry input) {
            return input.getValue();
        }
    }));
}

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

public IFeatureVector toFeatureVector(boolean sorted) {
    if (!sorted)//from www .  j  a  v  a 2 s .com
        return new SparseFeatureVector(Ints.toArray(idxList), Floats.toArray(valList), false);
    if (idxList.size() == 0)
        return new SparseFeatureVector(new int[0], new float[0]);
    // sort items
    Integer[] idxs = new Integer[idxList.size()];
    for (int i = 0; i < idxs.length; i++)
        idxs[i] = i;
    Arrays.sort(idxs, new Comparator<Integer>() {
        public int compare(Integer o1, Integer o2) {
            return Integer.compare(idxList.get(o1), idxList.get(o2));
        }
    });

    int preIdx = -1;

    if (sorted && idxList.get(idxs[0]) < 0) {
        logger.error("Feature vector index should start at 1. Please shift your feature vector "
                + "index by 1 using shift(int offset) function . See readme for details.");
        throw new IllegalArgumentException("index must be >= 1");
    }

    int numNonZeroFeature = 0;
    for (int i = 0; i < idxs.length; i++) {
        if (preIdx == idxList.get(idxs[i])) {
            continue;
        }
        numNonZeroFeature++;
        preIdx = idxList.get(idxs[i]);
    }
    int[] indices = new int[numNonZeroFeature];
    float[] values = new float[numNonZeroFeature];

    numNonZeroFeature = 0;
    preIdx = -1;
    for (int i = 0; i < idxList.size(); i++) {
        if (preIdx == idxList.get(idxs[i])) {
            values[numNonZeroFeature - 1] += valList.get(idxs[i]);
            continue;
        }
        indices[numNonZeroFeature] = idxList.get(idxs[i]);
        values[numNonZeroFeature] = valList.get(idxs[i]);
        preIdx = idxList.get(idxs[i]);
        numNonZeroFeature++;
    }
    return new SparseFeatureVector(indices, values, sorted);
}

From source file:com.galois.qrstream.qrpipe.Receive.java

/**
 * Update IProgress with QR finder points that were
 * found during the QR decoding. It orders the (x,y)
 * coordinates as follows: [x1,y2,x2,y2...xi,yi...].
 *///from  ww w .  j a v  a2 s .c om
private void displayQRFinderPoints(Iterable<Result> decodedQRCodes) {
    List<Float> list = Lists.newArrayList();
    for (Result qr : decodedQRCodes) {
        ResultPoint[] points = qr.getResultPoints();
        if (points != null) {
            for (ResultPoint point : points) {
                if (point != null) {
                    list.add(point.getX());
                    list.add(point.getY());
                }
            }
        }
    }
    progress.drawFinderPoints(Floats.toArray(list));
}