%% Modeling Requirements for Matrices

% Copyright 2018 The MathWorks, Inc.

%% Guideline ID
% |1.3.1|

%% Severity
% _Mandatory_

%% Description
% HDL Coder(TM) does not support matrix data types at the DUT interfaces.
% Before the 2-D matrix signals enter the DUT Subsystem, convert the signals to
% 1-D vectors by using a Reshape block. Inside the DUT Subsystem, you can 
% convert the vectors back to matrices by using Reshape blocks, and then perform
% matrix computations. After performing computations, you must convert the 
% matrices back to vector signals at the DUT output interface. Outside the DUT
% interface, you can convert the vector signals back to matrices. 
%
% *Modeling Considerations*
%
% * When you use the Reshape block to convert vectors to 2D matrices,
% make sure that you specify the right *Output dimensions*.
% * When you use the Product block, use the right *Multiplication* mode.
% By using this mode, you can perform either matrix multiplication or 
% element-wise multiplication. The multiplied output can have different
% dimensions depending on the *Multiplication* mode.
% * When you use the Product block to perform matrix multiplication, place 
% the Matrix Multiply block inside a Subsystem block. When you generate code
% and open the generated model, you see that HDL Coder expands the 
% matrix multiplication to multiple Product and Add blocks. Placing the 
% Matrix Multiply block inside a subsystem makes the generated model easier 
% to understand. In addition, make sure that you do not provide more than
% two inputs to the Matrix Multiply block.
% * When you extract matrix data, use Selector and Assignment blocks. Make sure 
% that you do not use fixed-point data types for the index inpt ports for the
% blocks.
%%
% *Example*
%
% This example shows how to use matrix types in HDL Coder(TM). 
% Open this model |hdlcoder_matrix_multiply|. The model contains a Reshape block 
% that converts the matrix input to a 1-D vector at the DUT Subsystem interface.  
open_system('hdlcoder_matrix_multiply')
set_param('hdlcoder_matrix_multiply', 'SimulationCommand', 'update')
sim('hdlcoder_matrix_multiply')
%%
% If you open the DUT Subsystem, you see two subsystems. The Reshape blocks convert
% the 1-D array back to the 2-by-2 matrices for input to the subsystems.
% One subsystem uses a Matrix Multiply block and the other subsystem performs 
% element-wise multiplication. The output result is converted back to
% vectors.
open_system('hdlcoder_matrix_multiply/DUT')
%%
% If you generate HDL code for the DUT Subsystem and open the generated
% model, you see how the multiplication operation is performed.