gusucode.com > bigdata 工具箱 matlab源码程序 > bigdata/+matlab/+bigdata/+internal/+lazyeval/ChunkwiseProcessor.m
%ChunkwiseProcessor % Data Processor that applies a chunk-wise function handle to the input % data. % % This will apply a function handle chunk-wise to all of the data. It will % emit data continuously throughout a pass. % % See LazyTaskGraph for a general description of input and outputs. % Specifically, each iteration will emit a 1 x NumOutputs cell array where % each cell contains a chunk of output of the corresponding operation % output. % % Copyright 2015-2016 The MathWorks, Inc. classdef (Sealed) ChunkwiseProcessor < matlab.bigdata.internal.lazyeval.AbstractChunkwiseProcessor properties (SetAccess = immutable) % The chunk-wise function handle. FunctionHandle; % A function handle that will be called after each function call % with both the inputs and the outputs of the call. PostCheckHandle; end methods (Static) % Create a data processor factory that can be used by the execution % environment to construct instances of this class. function factory = createFactory(functionHandle, numOutputs, ... inputFutureMap, isInputReplicated, postCheckHandle, allowTallDimExpansion) if nargin < 5 || isempty(postCheckHandle) postCheckHandle = @(varargin)[]; end if nargin < 6 allowTallDimExpansion = true; end factory = @createProcessor; function dataProcessor = createProcessor(partition) import matlab.bigdata.internal.lazyeval.ChunkwiseProcessor; isInputSinglePartition = isInputReplicated | (partition.NumPartitions == 1); dataProcessor = ChunkwiseProcessor(functionHandle, numOutputs, ... inputFutureMap, isInputSinglePartition, postCheckHandle, allowTallDimExpansion); end end end % Methods overridden in the AbstractChunkwiseProcessor base class. methods (Access = protected) function [isFinished, data] = callFunctionHandle(obj, isLastOfAllInput, inputs, ~) [data{1:obj.NumOutputs}] = matlab.bigdata.internal.lazyeval.callFunctionHandle(obj.FunctionHandle, inputs{:}); isFinished = isLastOfAllInput; err = feval(obj.PostCheckHandle, inputs, data); if ~isempty(err) obj.throwFromFunctionHandle(err); end end function throwFromFunctionHandle(obj, err) obj.FunctionHandle.throwAsFunction(err); end end methods (Access = private) % Private constructor for factory method. function obj = ChunkwiseProcessor(functionHandle, numOutputs, ... inputFutureMap, isInputSinglePartition, postCheckHandle, allowTallDimExpansion) import matlab.bigdata.internal.lazyeval.InputBuffer; enableBuffer = true; obj = obj@matlab.bigdata.internal.lazyeval.AbstractChunkwiseProcessor(... numOutputs, inputFutureMap, enableBuffer, isInputSinglePartition, ... functionHandle.MaxNumSlices, allowTallDimExpansion); obj.FunctionHandle = functionHandle; obj.PostCheckHandle = postCheckHandle; end end end