
Matlab Review Fi Object Code
Reviews MATLAB fixed-point (fi) code for performance, code generation efficiency, and...
Install
npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-fi-object-code -g -a claude-code -y- Repository
- matlab/matlab-agentic-toolkit1.2k
- Category
- Engineering
- Updated
- 8d ago
- License
- See repository
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Reviews MATLAB fixed-point (fi) code for performance, code generation efficiency, and correctness. Identifies antipatterns and suggests idiomatic improvements. Use when reviewing fi, fimath, numerictype, or quantizenumeric code.
fi Best Practices Review
Reviews MATLAB code for fixed-point (fi) best practices and suggests improvements for performance, code generation efficiency, and correctness.
When to Use
- Reviewing MATLAB code that uses
fi,fimath,numerictype, orquantizenumeric - Optimizing fixed-point simulation speed
- Preparing fixed-point code for C or hardware code generation
When Not to Use
- Code using only built-in integer types (
int8,uint16, etc.) withoutfi - Pure floating-point algorithms with no fixed-point intent
- Simulink-only workflows where fixed-point is configured through block dialogs (use Fixed-Point Tool instead)
Checklist
When reviewing code, check for ALL of the following:
1. Vectorize fi() Calls
Problem: Scalar fi() in a loop is slow due to per-element object construction overhead.
Fix: Pass entire arrays to fi() at once.
% BAD, slow: per-element fi object construction
for k = 1:N
x_fi(k) = fi(x(k), 1, 18, 16, F);
end
% GOOD, fast: single vectorized call, bit-true identical result
x_fi = fi(x, 1, 18, 16, F);
2. Separate Data Types from Algorithm
Problem: Hardcoding fi types inside algorithm code makes it impossible to switch between float/fixed or compare configurations.
Fix: Use a types table with empty prototypes and cast(...,'like',...).
% Types table (separate function)
function T = mytypes(dt)
switch dt
case 'double'
T.b = double([]); T.x = double([]); T.y = double([]);
case 'single'
T.b = single([]); T.x = single([]); T.y = single([]);
case 'fixed16'
F = fimath('RoundingMethod','Floor','OverflowAction','Wrap', ...
'ProductMode','KeepLSB','ProductWordLength',32, ...
'SumMode','KeepLSB','SumWordLength',32);
T.b = fi([], 1, 16, 15, F);
T.x = fi([], 1, 16, 15, F);
T.y = fi([], 1, 16, 14, F);
end
end
