Opened 15 years ago
Last modified 15 years ago
#1164 closed defect (fixed)
vector() can't handle matrix flattening!?
Reported by: | asodja | Owned by: | asodja |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Instantiation | Version: | 1.5.0RC2 |
Keywords: | Cc: | asodja, Per Östlund |
Description
The assigment {{A := diagonal(vector(ones(1, 4)));}} gets expanded to {{A := { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} } }} and fails, while assignment {{A := diagonal(vector(ones(4)));}} (notice the params passed to {{ones()}}) works fine.
The error produced by the first option (which fails) is:
{{
instantiateDaeFunction failed for MatrixAssign
Error processing file: MAssign.mo
- Algorithm.makeAssignment failed
A := { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} }
- Algorithm.makeAssignment failed
A := { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} }
Error: Error occured while flattening model Vector may only be 1x2 or 2x1 dimensions
Error: Type mismatch in assignment in A := {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}} of Real[4, 4] := Integer[1, 1, 4]
Error: Error occured while flattening model Vector may only be 1x2 or 2x1 dimensions
Error: Type mismatch in assignment in A := {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}} of Real[4, 4] := Integer[1, 1, 4]
Error: No matching function found for MatrixAssign() of type function() => Real[4, 4], candidates are function() => Real[4, 4]
}}
It seems that the function {{vector()}} can't handle matrix flattening!?
Also see the test file in attachment.
Attachments (1)
Change History (5)
by , 15 years ago
Attachment: | MAssign.mo added |
---|
comment:1 by , 15 years ago
comment:2 by , 15 years ago
The problem was an incorrect implementation of the vector function. It should now work.
comment:3 by , 15 years ago
The model below also fails, I assume that due to the same bug:
model VectorTest function PolyToRelCoord "Transforms polygon to relative coordinate system" input Real T[4, 4] "Transformation matrix"; input Real s[3, :] "Polygon to be transformed"; output Real r[3, size(s, 2)] "Transformed polygon"; protected Real p[4] "auxillary vector variable"; algorithm for i in 1:size(s, 2) loop p := vector(T*[s[:, i]; 1]); r[:, i] := p[1:3]; end for; end PolyToRelCoord; constant Real H[4,4] = diagonal(ones(4)); constant Real ply[3,4] = [1.0, 0.0, 0.0, 1.0; 1.0, 0.0, 1.0, 0.0; 0.0, 0.0, 1.0, 1.0]; constant Real plyprime[3,4] = PolyToRelCoord(H,ply); end VectorTest;
comment:4 by , 15 years ago
The VectorTest model gives assertion errors in the C runtime, so it's probably not the same problem. I've opened another bug [here|BUG:1170].
diagonal(vector(ones(4))) produces a matrix of Reals while diagonal(vector(ones(1,4))) produces a matrix of Integers, which seems to cause some problems. I'll look into this.