Example usage for org.apache.spark.api.java.function DoubleFlatMapFunction DoubleFlatMapFunction

List of usage examples for org.apache.spark.api.java.function DoubleFlatMapFunction DoubleFlatMapFunction

Introduction

In this page you can find the example usage for org.apache.spark.api.java.function DoubleFlatMapFunction DoubleFlatMapFunction.

Prototype

DoubleFlatMapFunction

Source Link

Usage

From source file:com.intel.daal.spark.rdd.DistributedNumericTable.java

License:Open Source License

/**
 * Flattens a DistributedNumericTable backed by HomogenNumericTables into a JavaDoubleRDD.
 * @param distNT - The source DistributedNumericTable.
 *//*from   w ww  . j a  va2 s  .  co m*/
public static JavaDoubleRDD toJavaDoubleRDD(final DistributedNumericTable distNT) {
    JavaDoubleRDD rdd = distNT.numTables.flatMapToDouble(new DoubleFlatMapFunction<NumericTableWithIndex>() {
        public List<Double> call(NumericTableWithIndex nt) {
            DaalContext context = new DaalContext();
            NumericTable table = nt.getTable(context);
            if (table instanceof HomogenNumericTable) {
                double[] array = ((HomogenNumericTable) table).getDoubleArray();
                context.dispose();
                return Arrays.asList(ArrayUtils.toObject(array));
            } else {
                context.dispose();
                return null;
            }
        }
    });
    return rdd;
}