Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading is unclear about array multiplication. #1469

Closed
modelica-trac-importer opened this issue Nov 4, 2018 · 5 comments
Closed

Overloading is unclear about array multiplication. #1469

modelica-trac-importer opened this issue Nov 4, 2018 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@modelica-trac-importer
Copy link
Collaborator

Reported by stefanv on 25 Apr 2014 14:09 UTC
The specification states that vector*vector and vector*matrix should be left undefined instead of following the rules of section 10.6.4. Does that mean if I write,

model M
    Complex A[3,4], B[4,5], C[3,5];
equation
    C = A * B;
end M;

that I should get an error?

If that is the case, the scalarProduct function within the '*' operator in Complex will never be called.

My original interpretation after initially skimming chapter 14 was that a Modelica tool should find a matching function within operator '*', so for example, the multiplication above would find the following if it existed:

operator record Complex
    ...
    operator '*'
        ...
        function matMatMul
            import Complex;
            input Complex A[:,:];
            input Complex B[size(A,2),:];
            output Complex C[size(A,1),size(B,2)];
        algorithm
            ...
        end matMatMul;
        ...
    end '*';
    ...
end Complex;

I assume that this interpretation is incorrect?


Migrated-From: https://trac.modelica.org/Modelica/ticket/1469

@modelica-trac-importer
Copy link
Collaborator Author

Comment by sjoelund.se on 14 May 2014 14:53 UTC
You are performing a matrix*matrix operation, which is defined.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by stefanv on 14 May 2014 20:31 UTC
Sorry, my example is wrong. I meant to write a vector*matrix multiplication, for which my question still stands.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by sjoelund.se on 14 May 2014 21:27 UTC
So you mean vector*matrix:

model M
    Complex A[4], B[4,5], C[5];
equation
    C = A * B;
end M;

It will

  1. Not match elementary operations
  2. Not match scalarProduct (because that takes 2 vectors as input and operator functions are not vectorized)
  3. Not be promoted using any 'constructor' calls
  4. Not match any array vectorization because .* was not used and '*' is not defined for vector*matrix
  5. It is thus an error

However, it would be accepted due to point 2 if you had defined a function like this:

    operator '*'
        ...
        function vecMatMul
            import Complex;
            input Complex A[:];
            input Complex B[:,:]; // We can define any sort of dimensions we like in here. Doesn't have to be [size(A,1),:]
            output WhatEver something;
        algorithm
            ...
        end vecMatMul;
        ...
    end '*';

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 17 Jun 2014 15:25 UTC
In 14.4
change "a is an instance of class A" to "a is an intance or array of instances of class A" (and similarly for the rest, change similarly at other places).

  1. Remove "arrays of such"
  2. ok
  3. ok
  4. If a or b are array expressions...
    Similarly for "Unary operator"
    No change for "String".

This will allow array operations to be overloaded (in rule 2/3).
Note: This means Complex matrix*real matrix will not use a user-defined function in Complex taking complex matrix arguments, and will not match anything in step 4 - since there is no constructor called in that step. That would be a useful addition later.

Agreement.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 18 Jun 2014 06:53 UTC
Resolved in r7690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests