%% Reformat Data Using Function Layer
% Create a function layer that reformats input data with format "CB"(channel, batch) to have format "SBC" (spatial, batch, channel). To specify that the layer operates on formatted data, set the Formattable option to true.

layer = functionLayer(@(X) dlarray(X,"SBC"),Formattable=true)

% Include a function layer that reformats the input to have format "SB" in a layer array. Specify that the layer has description "channel to spatial".

layers = [
    featureInputLayer(10)
    functionLayer(@(X) dlarray(X,"SBC"),Formattable=true,Description="channel to spatial")
    convolution1dLayer(3,16)]

%
% In this network, the 1-D convolution layer convolves over the "S" (spatial) dimension of its input data. This is equivalent to convolving over the "C" (channel) dimension of the network input data.
% Convert the layer array to a dlnetwork object and pass a random array of data with format "CB".

dlnet = dlnetwork(layers);

X = rand(10,64);
dlX = dlarray(X,"CB");

dlY = forward(dlnet,dlX);

% View the size and format of the output data.

size(dlY)
dims(dlY)

% Copyright 2021 The MathWorks, Inc.