classdef ReshapeLayer1002 < nnet.layer.Layer & nnet.layer.Formattable
    % A custom layer auto-generated while importing an ONNX network.
    %#codegen

    %#ok<*PROPLC>
    %#ok<*NBRAK>
    %#ok<*INUSL>
    %#ok<*VARARG>
    properties (Learnable)
    end

    properties (State)
    end

    properties
        Vars
        NumDims
    end

    methods(Static, Hidden)
        % Specify the properties of the class that will not be modified
        % after the first assignment.
        function p = matlabCodegenNontunableProperties(~)
            p = {
                % Constants, i.e., Vars, NumDims and all learnables and states
                'Vars'
                'NumDims'
                };
        end
    end


    methods(Static, Hidden)
        % Instantiate a codegenable layer instance from a MATLAB layer instance
        function this_cg = matlabCodegenToRedirected(mlInstance)
            this_cg = EDHR_Net.coder.ReshapeLayer1002(mlInstance);
        end
        function this_ml = matlabCodegenFromRedirected(cgInstance)
            this_ml = EDHR_Net.ReshapeLayer1002(cgInstance.Name);
            if isstruct(cgInstance.Vars)
                names = fieldnames(cgInstance.Vars);
                for i=1:numel(names)
                    fieldname = names{i};
                    this_ml.Vars.(fieldname) = dlarray(cgInstance.Vars.(fieldname));
                end
            else
                this_ml.Vars = [];
            end
            this_ml.NumDims = cgInstance.NumDims;
        end
    end

    methods
        function this = ReshapeLayer1002(mlInstance)
            this.Name = mlInstance.Name;
            this.OutputNames = {'Identity_0'};
            if isstruct(mlInstance.Vars)
                names = fieldnames(mlInstance.Vars);
                for i=1:numel(names)
                    fieldname = names{i};
                    this.Vars.(fieldname) = EDHR_Net.coder.ops.extractIfDlarray(mlInstance.Vars.(fieldname));
                end
            else
                this.Vars = [];
            end

            this.NumDims = mlInstance.NumDims;
        end

        function [Identity_0] = predict(this, model_1_output_Relu___)
            if isdlarray(model_1_output_Relu___)
                model_1_output_Relu__ = stripdims(model_1_output_Relu___);
            else
                model_1_output_Relu__ = model_1_output_Relu___;
            end
            model_1_output_Relu_NumDims = 4;
            model_1_output_Relu_ = EDHR_Net.coder.ops.permuteInputVar(model_1_output_Relu__, [4 3 1 2], 4);

            [Identity_0__, Identity_0NumDims__] = ReshapeGraph1004(this, model_1_output_Relu_, model_1_output_Relu_NumDims, false);
            Identity_0_ = EDHR_Net.coder.ops.permuteOutputVar(Identity_0__, [2 3 4 1], 4);

            Identity_0 = dlarray(single(Identity_0_), 'SSCB');
        end

        function [Identity_0, Identity_0NumDims1005] = ReshapeGraph1004(this, model_1_output_Relu_, model_1_output_Relu_NumDims, Training)

            % Execute the operators:
            % Reshape:
            [shape1002, Identity_0NumDims] = EDHR_Net.coder.ops.prepareReshapeArgs(model_1_output_Relu_, this.Vars.new_shape__565, coder.const(model_1_output_Relu_NumDims), 0);
            Identity_0 = reshape(model_1_output_Relu_, shape1002{:});

            % Set graph output arguments
            Identity_0NumDims1005 = Identity_0NumDims;

        end

    end

end