Main Content

reduce

Class: matlab.compiler.mlspark.RDD
Namespace: matlab.compiler.mlspark

Reduce elements of an RDD using the specified commutative and associative function

Syntax

result = reduce(obj,func)

Description

result = reduce(obj,func) reduces the elements of obj using the specified commutative and associative function func.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Commutative and associative function that will be applied to elements of the RDD.

Data Types: function_handle

Output Arguments

expand all

Reduced elements of the input RDD, returned as a scalar.

Examples

expand all

%% Connect to Spark
sparkProp = containers.Map({'spark.executor.cores'}, {'1'});
conf = matlab.compiler.mlspark.SparkConf('AppName','myApp', ...
                        'Master','local[1]','SparkProperties',sparkProp);
sc = matlab.compiler.mlspark.SparkContext(conf);

%% Reduce
reduceVal = sc.parallelize({1, 2, 3, 4, 5}).reduce(@(x,y)(x+y));
disp(reduceVal);

Version History

Introduced in R2016b