-
Notifications
You must be signed in to change notification settings - Fork 1
/
mytypes.m
53 lines (52 loc) · 1.77 KB
/
mytypes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%To add custom types add a case statement with custom data type name. To
%invoke a specific type within another function use
%T = mytypes(<data type name>) then cast as follows: x = cast(x0, 'like', T.x)
%To optimize the data type for a specific application use 'pg_solv_mex'.
function T = mytypes(dt)
switch(dt)
case 'double'
T.n = double([]);
T.param = double([]);
T.y = double([]);
T.x = double([]);
case 'single'
T.n = single([]);
T.param = single([]);
T.y = single([]);
T.x = single([]);
case 'fixed8'
T.n = fi([],true,8,0);
T.param = fi([],true,8,2);
T.x = fi([],true,8,2);
T.y = fi([],true,8,2);
case 'fixed16'
T.n = fi([],true,16,0);
T.param = fi([],true,16,10);
T.y = fi([],true,16,10);
T.x = fi([],true,16,14);
case 'fixed12'
T.n = fi([],true,12,0);
T.param = fi([],true,12,9);
T.y = fi([],true,12,9);
T.x = fi([],true,12,9);
case 'fixed16override'
%use scaled doubles to detect potential overflows (see pg_solv_mex.m)
T.n = fi([],true,16,0,'DataType', 'ScaledDouble');
T.param = fi([],true,16,8,'DataType', 'ScaledDouble');
T.x = fi([],true,16,14,'DataType', 'ScaledDouble');
T.y = fi([],true,16,10,'DataType', 'ScaledDouble');
case 'fixed16+matchproc'
%Types defined with fimath settings that match processor types
F = fimath(...
'RoundingMethod','Floor', ...
'OverflowAction','Wrap', ...
'ProductMode','KeepLSB', ...
'ProductWordLength',32, ...
'SumMode','KeepLSB', ...
'SumWordLength',32);
T.n = fi([],true,16,0,F);
T.param = fi([],true,16,8,F);
T.x = fi([],true,16,14,F);
T.y = fi([],true,16,10,F);
end
end