Java* API Reference for Intel® Data Analytics Acceleration Library 2016 Update 4

DataStructuresMerged.java

/* file: DataStructuresMerged.java */
/*******************************************************************************
* Copyright 2014-2016 Intel Corporation All Rights Reserved.
*
* The source code, information and material ("Material") contained herein is
* owned by Intel Corporation or its suppliers or licensors, and title to such
* Material remains with Intel Corporation or its suppliers or licensors. The
* Material contains proprietary information of Intel or its suppliers and
* licensors. The Material is protected by worldwide copyright laws and treaty
* provisions. No part of the Material may be used, copied, reproduced,
* modified, published, uploaded, posted, transmitted, distributed or disclosed
* in any way without Intel's prior express written permission. No license under
* any patent, copyright or other intellectual property rights in the Material
* is granted to or conferred upon you, either expressly, by implication,
* inducement, estoppel or otherwise. Any license under such intellectual
* property rights must be express and approved by Intel in writing.
*
* Unless otherwise agreed by Intel in writing, you may not remove or alter this
* notice or any other notice embedded in Materials by Intel or Intel's
* suppliers or licensors in any way.
*******************************************************************************/
package com.intel.daal.examples.datasource;
import java.nio.DoubleBuffer;
import com.intel.daal.data_management.data.NumericTable;
import com.intel.daal.data_management.data.HomogenNumericTable;
import com.intel.daal.data_management.data.MergedNumericTable;
import com.intel.daal.examples.utils.Service;
import com.intel.daal.services.DaalContext;
/*
// Merged data structures example
*/
class DataStructuresMerged {
private static final int nVectors = 5;
private static final int nFeatures1 = 6;
private static final int nFeatures2 = 5;
private static final int firstReadRow = 3;
private static final int nRead = 1;
private static DaalContext context = new DaalContext();
public static void main(String[] args) {
System.out.println("Merged numeric table example");
int readFeatureIdx;
double[] data1 = {
0.0, 0.1, 0.2, 0.3, 0.4, 0.5,
1.0, 1.1, 1.2, 1.3, 1.4, 1.5,
2.0, 2.1, 2.2, 2.3, 2.4, 2.5,
3.0, 3.1, 3.2, 3.3, 3.4, 3.5,
4.0, 4.1, 4.2, 4.3, 4.4, 4.5,
};
double[] data2 = {
0.6, 0.7, 0.8, 0.9, 1,
1.6, 1.7, 1.8, 1.9, 2,
2.6, 2.7, 2.8, 2.9, 3,
3.6, 3.7, 3.8, 3.9, 4,
4.6, 4.7, 4.8, 4.9, 5,
};
/* Create two homogen numeric tables from data arrays */
HomogenNumericTable dataTable1 = new HomogenNumericTable(context, data1, nFeatures1, nVectors);
HomogenNumericTable dataTable2 = new HomogenNumericTable(context, data2, nFeatures2, nVectors);
/* Create merged numeric table consisting of two homogen numeric tables */
MergedNumericTable dataTable = new MergedNumericTable(context);
dataTable.addNumericTable(dataTable1);
dataTable.addNumericTable(dataTable2);
DoubleBuffer dataDouble = DoubleBuffer.allocate(0);
/* Read one row from merged numeric table */
dataDouble = dataTable.getBlockOfRows(firstReadRow, nRead, dataDouble);
printDoubleBuffer(dataDouble, nFeatures1 + nFeatures2, nRead, "Print 1 row from merged numeric table:");
/* Modify row of the merged numeric table */
for (int i = 0; i < nFeatures1 + nFeatures2; i++) dataDouble.put(i, dataDouble.get(i) * dataDouble.get(i));
dataTable.releaseBlockOfRows(firstReadRow, nRead, dataDouble);
/* Read the same row from homogen numeric tables */
dataDouble = dataTable1.getBlockOfRows(firstReadRow, nRead, dataDouble);
printDoubleBuffer(dataDouble, nFeatures1, nRead, "Print 1 row from first homogen numeric table:");
dataTable1.releaseBlockOfRows(firstReadRow, nRead, dataDouble);
dataDouble = dataTable2.getBlockOfRows(firstReadRow, nRead, dataDouble);
printDoubleBuffer(dataDouble, nFeatures2, nRead, "Print 1 row from second homogen numeric table:");
dataTable2.releaseBlockOfRows(firstReadRow, nRead, dataDouble);
context.dispose();
}
private static void printDoubleBuffer (DoubleBuffer buf, int nColumns, int nRows, String message) {
int step = (int)nColumns;
System.out.println(message);
for (int i = 0; i < nRows; i++) {
for (int j = 0; j < nColumns; j++) {
System.out.format("%6.3f ", buf.get(i * step + j));
}
System.out.println("");
}
System.out.println("");
}
}