Sparse Matrix-Vector Product
Libraries:
HDL Coder /
RCP and HIL
Description
The Sparse Matrix-Vector Product block multiplies the sparse matrix
A
with an input vector x
.
Examples
Model 2-D Matrix-Vector Multiplication
This example builds a 2-dimensional matrix-vector multiplication function by using the Sparse Matrix-Vector Product block.
To implement this function, specify the parameter Matrix A as [1,2,0;3,0,4;0,5,6]
and input vector x
as [1,2,3]
for the model.
load_system("SMVPblock2DExample") sim("SMVPblock2DExample"); open_system("SMVPblock2DExample");
You can verify the results by performing 2-dimensional matrix-vector multiplication. In the MATLAB® Command Window, enter the value of matrix A
and input vector x
:
A = [1,2,0;3,0,4;0,5,6]; x = [1,2,3];
Compute x'
and multiply with matrix A
:
x = x'; y = A*x
y = 5 15 28
Model 3-D Matrix-Vector Multiplication
This example builds a 3-dimensional matrix-vector multiplication function by using the Sparse Matrix-Vector Product block.
To implement this function, specify the parameter Matrix A as:
A(:,:,1) = [1,2,0;3,0,4;0,5,6]
; A(:,:,2) = [1,2,3;3,5,4;7,5,6]
; A(:,:,3) = [1,2,0;3,0,4;0,5,6]
;
and the input vector x
as [1,2,3]
. There is a Selector block to select the required matrix configuration based on specified indices. The Selector block has zero-based index mode where an index of 0 specifies the first element of the input vector. Therefore, for a 3-D input signal, 0
, 1
, and 2
are the valid input elements. In this example, the value of input for Sel
is 2
. For more information, see Selector.
load_system("SMVPblock3DExample") sim("SMVPblock3DExample"); open_system("SMVPblock3DExample");
To perform 3-dimensional matrix-vector multiplication, in the MATLAB® Command Window, enter the value of matrix A
and input vector x
:
A(:,:,1) = [1,2,0;3,0,4;0,5,6]; A(:,:,2) = [1,2,3;3,5,4;7,5,6]; A(:,:,3) = [1,2,0;3,0,4;0,5,6]; x = [1,2,3];
For the 3-D input signal, the value of input signal Sel
= 2 selects matrix A(:,:,3)
. Compute x'
and multiply with matrix A(:,:,3)
:
x = x'; y = A(:,:,3)*x
y = 5 15 28
Ports
Input
x — Input signal
scalar | vector
Input signal, specified as a scalar or vector. The Sparse Matrix-Vector Product block supports fixed-point data types. The number of input ports depends on the dimension of Matrix A. For example, see Model 3-D Matrix-Vector Multiplication.
Data Types: single
| double
| fixed point
Output
y — Output signal
scalar | vector
Output signal, returned as a scalar or vector. The output signal is the input signal multiplied by the sparse matrix specified by Matrix A.
Data Types: single
| double
| fixed point
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Main
Matrix A — Sparse matrix
1
(default) | real scalar, vector, or matrix
Specify the sparse matrix to multiply the input vector by. Matrix A can be a real scalar, vector, or matrix.
Programmatic Use
To get the block parameter value
programmatically, use the get_param
function.
Parameter: | A |
Values: | "1" | real scalar, vector, or matrix |
Signal Attributes
Output minimum — Minimum output value for range checking
[]
(default) | scalar
Specify the minimum value of the output range that the software checks.
The software uses the output minimum to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking)
Automatic scaling of fixed-point data types
Programmatic Use
To set the block parameter value
programmatically, use the set_param
function.
Parameter: | OutMin |
Values: | '[]' (default) | scalar in quotes |
Output maximum — Maximum output value for range checking
[]
(default) | scalar
Specify the maximum value of the output range that the software checks.
The software uses the output maximum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking)
Automatic scaling of fixed-point data types
Programmatic Use
To set the block parameter value
programmatically, use the set_param
function.
Parameter: | OutMax |
Values: | '[]' (default) | scalar in quotes |
Output data type — Output data type
'Inherit: Inherit via internal rule'
(default) | 'Inherit: Keep MSB'
| 'Inherit: Match scaling'
| 'Inherit: Inherit via back propagation'
| 'Inherit: Same as first input'
| 'double'
| 'single'
| 'half'
| 'int8'
| 'uint8'
| 'int16'
| 'uint16'
| 'int32'
| 'uint32'
| 'int64'
| 'uint64'
| 'fixdt(1,16)'
| 'fixdt(1,16,0)'
| 'fixdt(1,16,2^0,0)'
| '<data type expression>'
Choose the data type for the output. The type can be inherited, specified
directly, or expressed as a data type object such as
Simulink.NumericType
.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | OutDataTypeStr |
Values: | 'Inherit: Inherit via internal
rule' (default) | 'Inherit: Keep MSB' | 'Inherit: Match scaling' | 'Inherit: Inherit via back propagation' | 'Inherit: Same as first input' | 'double' | 'single' | 'half' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | '<data type expression>' |
Parameter Attributes
Parameter minimum — Minimum value of sparse matrix
[]
(default) | scalar
Specify the minimum value of Matrix A. The default value is
[]
(unspecified). The software uses this value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters)
Automatic scaling of fixed-point data types
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | ParamMin |
Values: | '[]' (default) | scalar in quotes |
Parameter maximum — Maximum value of sparse matrix
[]
(default) | scalar
Specify the maximum value of Matrix A. The default value is
[]
(unspecified). The software uses this value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters)
Automatic scaling of fixed-point data types
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | ParamMax |
Values: | '[]' (default) | scalar in quotes |
Parameter data type — Specify the data type of the sparse matrix
'Inherit: Inherit via back propagation'
(default) | 'double'
| 'single'
| 'half'
| 'int8'
| 'uint8'
| 'int16'
| 'uint16'
| 'int32'
| 'uint32'
| 'int64'
| 'uint64'
| '
| 'fixdt(1,16)'
| 'fixdt(1,16,0)'
| 'fixdt(1,16,2^0,0)'
| 'Enum: <class name>'
| '<data type expression>'
Specify the data type of the Matrix A parameter.
While tuning a parameter with this Parameter data type setting, specify the Parameter minimum and Parameter maximum parameters. These settings tell the software about the range of values you want during the simulation and allows the software to provide a full precision data type with sufficient range to allow safe tuning within the specified range.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | ParamDataTypeStr |
Values: | 'Inherit: Inherit via back
propagation' (default) | 'double' | 'single' | 'half' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'boolean' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'Enum: <class name>' | '<data type expression>' |
Extended Capabilities
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has one default HDL architecture.
By default, the following HDL block property is available.
Native Floating Point | |
---|---|
LatencyStrategy | Specify whether to map the blocks in your design to
|
Version History
Introduced in R2024b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)