ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Add argmin and argmax array functions returning indices

Open modelica-trac-importer opened this issue 7 years ago • 5 comments

Reported by beutlich on 3 May 2017 12:54 UTC Section 10.3.4 declares min and max array functions. However, the indices satisfying the min or max are not returned. In MATLAB the min and max reduction functions have a second output argument returning these indices.

See also #1980 for reshape.


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

modelica-trac-importer avatar Nov 04 '18 21:11 modelica-trac-importer

Comment by hansolsson on 10 May 2017 14:30 UTC I agree that it seems like useful functionality, but exactly how?

  • Is it the first, last, or any element being equal to max/min?
  • For a matrix (or higher dimensional entity) do we return one argument per array subscript, or one vector of subscripts?
  • Only for the array functions, right?

modelica-trac-importer avatar Nov 04 '18 21:11 modelica-trac-importer

Comment by jmattsson on 29 May 2017 08:06 UTC Replying to [comment:1 Hans Olsson]:

Only for the array functions, right?

Preferably for the reduction expression variants, as well. Otherwise you get:

(x, i) = min(y[j] * j for j in 1:n);    // This is an error 
(x, i) = min({y[j] * j for j in 1:n});  // this is allowed

It's bad enough that sum() behaves different with an array argument and as a reduction expression without adding more.

modelica-trac-importer avatar Nov 04 '18 21:11 modelica-trac-importer

Comment by hansolsson on 16 Jun 2017 14:45 UTC As noted in #2190 if they can be used in continuous-time equations the additional output need to generate events. (Another option is to restrict the use of argmin/argmax.)

An argument for restricting the use is to avoid the numerical issues if multiple array elements are at the maximum/minimum (which does not seem unlikely).

modelica-trac-importer avatar Nov 04 '18 21:11 modelica-trac-importer

Modified by beutlich on 6 Oct 2017 06:12 UTC

modelica-trac-importer avatar Nov 04 '18 21:11 modelica-trac-importer

Modified by beutlich on 10 Jan 2018 08:23 UTC

modelica-trac-importer avatar Nov 04 '18 21:11 modelica-trac-importer