classdef functionLayer < nnet.layer.Layer
% This layer wraps an arbitrary dlarray function in a layer interface so
% that dlarray functions without learnable parameters can be used easily in
% dlnetwork.
    
   properties
      ForwardFcn 
   end
    
    methods
        function layer = functionLayer(name,forwardFcn)
            % This function must have the same name as the class.

            layer.Name = name;
            layer.ForwardFcn = forwardFcn;

        end
        
        function X = predict(layer,X)
            % Forward input data through the layer at prediction time and
            % output the result.
            %
            % Inputs:
            %         layer       - Layer to forward propagate through
            %         X1, ..., Xn - Input data
            % Outputs:
            %         Z1, ..., Zm - Outputs of layer forward function
           
            % Layer forward function for prediction goes here.
            X = layer.ForwardFcn(X);
        end
    end
end