Example usage for java.nio DoubleBuffer allocate

List of usage examples for java.nio DoubleBuffer allocate

Introduction

In this page you can find the example usage for java.nio DoubleBuffer allocate.

Prototype

public static DoubleBuffer allocate(int capacity) 

Source Link

Document

Creates a double buffer based on a newly allocated double array.

Usage

From source file:edu.iu.daal_pca.Service.java

public static void printClassificationResult(NumericTable groundTruth, NumericTable classificationResults,
        String header1, String header2, String message, int nMaxRows) {
    int nCols = (int) groundTruth.getNumberOfColumns();
    int nRows = Math.min((int) groundTruth.getNumberOfRows(), nMaxRows);

    DoubleBuffer dataGroundTruth = DoubleBuffer.allocate(nCols * nRows);
    dataGroundTruth = groundTruth.getBlockOfRows(0, nRows, dataGroundTruth);

    DoubleBuffer dataClassificationResults = DoubleBuffer.allocate(nCols * nRows);
    dataClassificationResults = classificationResults.getBlockOfRows(0, nRows, dataClassificationResults);

    System.out.println(message);/*  ww w  .  j a v  a  2  s  .co  m*/
    System.out.println(header1 + "\t" + header2);
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < 1; j++) {
            System.out.format("%+.0f\t\t%+.0f\n", dataGroundTruth.get(i * nCols + j),
                    dataClassificationResults.get(i * nCols + j));
        }
    }
}

From source file:edu.iu.daal_pca.Service.java

public static void printNumericTable(String header, NumericTable nt, long nPrintedRows, long nPrintedCols) {
    long nNtCols = nt.getNumberOfColumns();
    long nNtRows = nt.getNumberOfRows();
    long nRows = nNtRows;
    long nCols = nNtCols;

    if (nPrintedRows > 0) {
        nRows = Math.min(nNtRows, nPrintedRows);
    }/*w  w  w. j av a  2  s. co m*/

    DoubleBuffer result = DoubleBuffer.allocate((int) (nNtCols * nRows));
    result = nt.getBlockOfRows(0, nRows, result);

    if (nPrintedCols > 0) {
        nCols = Math.min(nNtCols, nPrintedCols);
    }

    StringBuilder builder = new StringBuilder();
    builder.append(header);
    builder.append("\n");
    for (long i = 0; i < nRows; i++) {
        for (long j = 0; j < nCols; j++) {
            String tmp = String.format("%-6.3f ", result.get((int) (i * nNtCols + j)));
            builder.append(tmp);
        }
        builder.append("\n");
    }
    System.out.println(builder.toString());
    // LOG.info(builder.toString());
}

From source file:edu.iu.daal_pca.Service.java

public static void printTensor(String header, Tensor dataTensor, int nPrintedRows, int nPrintedCols) {
    long[] dims = dataTensor.getDimensions();
    int nRows = (int) dims[0];
    if (nPrintedRows == 0 || nRows < nPrintedRows)
        nPrintedRows = nRows;/*from w w  w.  j a v  a2 s  . co m*/

    int nCols = 1;
    for (int i = 1; i < dims.length; i++) {
        nCols *= dims[i];
    }
    DoubleBuffer result = DoubleBuffer.allocate(nRows * nCols);
    long[] fixed = {};
    result = dataTensor.getSubtensor(fixed, 0, nPrintedRows, result);

    if (nPrintedCols == 0 || nCols < nPrintedCols) {
        nPrintedCols = nCols;
    }

    StringBuilder builder = new StringBuilder();
    builder.append(header);
    builder.append("\n");
    for (long i = 0; i < nPrintedRows; i++) {
        for (long j = 0; j < nPrintedCols; j++) {
            String tmp = String.format("%-6.3f   ", result.get((int) (i * nCols + j)));
            builder.append(tmp);
        }
        builder.append("\n");
    }
    System.out.println(builder.toString());
}

From source file:edu.iu.daal_pca.Service.java

public static void printTensors(String header1, String header2, String message, Tensor dataTensor1,
        Tensor dataTensor2, int nPrintedRows) {
    long[] dims1 = dataTensor1.getDimensions();
    int nRows1 = (int) dims1[0];
    if (nPrintedRows == 0 || nRows1 < nPrintedRows)
        nPrintedRows = nRows1;/*  ww w  .  j  a  va2s .  com*/

    int nCols1 = 1;
    for (int i = 1; i < dims1.length; i++) {
        nCols1 *= dims1[i];
    }

    long[] dims2 = dataTensor2.getDimensions();
    int nRows2 = (int) dims2[0];
    if (nPrintedRows == 0 || nRows2 < nPrintedRows)
        nPrintedRows = nRows2;

    int nCols2 = 1;
    for (int i = 1; i < dims2.length; i++) {
        nCols2 *= dims2[i];
    }

    long[] fixed = {};

    DoubleBuffer result1 = DoubleBuffer.allocate(nRows1 * nCols1);
    result1 = dataTensor1.getSubtensor(fixed, 0, nPrintedRows, result1);

    DoubleBuffer result2 = DoubleBuffer.allocate(nRows2 * nCols2);
    result2 = dataTensor2.getSubtensor(fixed, 0, nPrintedRows, result2);

    StringBuilder builder = new StringBuilder();
    builder.append(message);
    builder.append("\n");
    builder.append(header1 + "\t" + header2 + "\n");
    for (long i = 0; i < nPrintedRows; i++) {
        for (long j = 0; j < nCols1; j++) {
            String tmp = String.format("%-6.3f   ", result1.get((int) (i * nCols1 + j)));
            builder.append(tmp);
        }
        builder.append("\t");
        for (long j = 0; j < nCols2; j++) {
            String tmp = String.format("%-6.3f   ", result2.get((int) (i * nCols2 + j)));
            builder.append(tmp);
        }
        builder.append("\n");
    }
    System.out.println(builder.toString());
}

From source file:edu.iu.daal_pca.Service.java

public static Tensor readTensorFromCSV(DaalContext context, String datasetFileName) {
    FileDataSource dataSource = new FileDataSource(context, datasetFileName,
            DataSource.DictionaryCreationFlag.DoDictionaryFromContext,
            DataSource.NumericTableAllocationFlag.DoAllocateNumericTable);
    dataSource.loadDataBlock();//from   w w  w  . j  a  va  2 s.co  m
    NumericTable nt = dataSource.getNumericTable();
    int nRows = (int) nt.getNumberOfRows();
    int nCols = (int) nt.getNumberOfColumns();
    if (nCols > 1) {
        long[] dims = { nRows, nCols };
        float[] data = new float[nRows * nCols];
        DoubleBuffer buffer = DoubleBuffer.allocate(nRows * nCols);
        buffer = nt.getBlockOfRows(0, nRows, buffer);
        for (int i = 0; i < nRows * nCols; i++) {
            data[i] = (float) buffer.get(i);
        }

        return new HomogenTensor(context, dims, data);
    } else {
        long[] dims = { nRows };
        float[] data = new float[nRows];
        DoubleBuffer buffer = DoubleBuffer.allocate(nRows);
        buffer = nt.getBlockOfRows(0, nRows, buffer);
        for (int i = 0; i < nRows; i++) {
            data[i] = (float) buffer.get(i);
        }

        return new HomogenTensor(context, dims, data);
    }
}

From source file:ummisco.gama.opengl.vaoGenerator.GeomMathUtils.java

static public DoubleBuffer getDoubleBuffer(final Matrix4d matrix) {
    final DoubleBuffer result = DoubleBuffer.allocate(16);
    result.put(0, matrix.m00);//from   ww w  .j a v  a  2s .c o m
    result.put(1, matrix.m01);
    result.put(2, matrix.m02);
    result.put(3, matrix.m03);
    result.put(4, matrix.m10);
    result.put(5, matrix.m11);
    result.put(6, matrix.m12);
    result.put(7, matrix.m13);
    result.put(8, matrix.m20);
    result.put(9, matrix.m21);
    result.put(10, matrix.m22);
    result.put(11, matrix.m23);
    result.put(12, matrix.m30);
    result.put(13, matrix.m31);
    result.put(14, matrix.m32);
    result.put(15, matrix.m33);
    return result;
}