You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Artem Barger <ar...@bargr.net> on 2016/05/30 21:05:55 UTC

[Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Hi.

Lately working w/ Apache Commons Math, library I've found myself
implementing functions which given an array of either doubles of integers
return the min or max value among all elements of an array. Moreover I've
added an argmin/argmin functions as well, which for given array of
double/int values return an index of min/max element within that array.

Since I didn't find such functions available in the project, I'm willing to
contribute these function into the framework and was curious whenever it's
usable? Also what should be the right place to put these functions? I've
added them as static method for MathArrays class, however not 100% sure
this is the right place.

Think further about these functions, I can easily make them work w/
instances of Comparable interface of accept Comparator<T> as second
parameter.

What should be the right way to handle this?

Best regards,
                      Artem Barger.

Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Artem Barger <ar...@bargr.net>.
Hi,


I've create a JIRA ticket MATH-1372 and attached a patch to it, also
submitted PR on GitHub: https://github.com/apache/commons-math/pull/36.

Best regards,
                      Artem Barger.

On Tue, May 31, 2016 at 3:32 AM, Artem Barger <ar...@bargr.net> wrote:

>
> On Tue, May 31, 2016 at 3:17 AM, Gilles <gi...@harfang.homelinux.org>
> wrote:
>
>> On Tue, 31 May 2016 02:58:27 +0300, Artem Barger wrote:
>>
>>> Methods "getMinValue()", "getMinIndex()".
>>>>
>>>> Important note: any contribution should be based on the contents of
>>>> the "develop" branch, not "master". See file
>>>>   doc/development/development.howto.txt
>>>> in the source tree.
>>>>
>>>>
>>>> ​So in order to use them I need to instantiate a RealVector, right?
>>>
>>
>> Yes.
>> And the iteration is probably not efficient since it use the
>> high-level API.
>>
>> Hence I think the question whenever to add static method w/
>>> similar functionality to MathArrays class is still valid, especially if
>>> I can enhance it to accept array or list of Comparables or to accept
>>> Comparator as an additional parameter​.
>>>
>>
>> Yes.
>> But perhaps a more general functionality would be useful.
>>
>
> ​General? Could you give an example?
> Aren't these​ enough?
>
> public static <T extends Comparable<T>> T min(T...array);
>
> public static <T extends Comparable<T>> T max(T...array);
>
> public static <T extends Comparable<T>> int argmin(T...array);
>
> public static <T extends Comparable<T>> int argmax(T...array);
>
>
>
>> Especially with the new Java 8 function types.
>>
>
> ​It's easy to implement having Java 8 function types, not sure I'm
> following you
> w/ how it could affect the API's of proposed methods.​
>
> I think I will submit a JIRA ticket w/ these and submit a patch, reviewing
> it we will
> be able to eventually come to some reasonable solution.
>
> Anyway ​if such functionality is already exist in "RealVector", I guess
>>>>
>>>>> there is no point of adding
>>>>> it to MathArrays, unless RealVector should be refactored and
>>>>> functionality
>>>>> should be removed from
>>>>> there.
>>>>>
>>>>>
>>>> Yes, refactored it should be:
>>>>  https://issues.apache.org/jira/browse/MATH-765
>>>>
>>>>
>>>> ​It says that these methods to be removed from RealVector.​
>>>
>>
>> A pity that what it says did not occur. :-}
>>
>
> ​:)))​
>
> ​Best,
>           Artem Barger.​
>
>

Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Artem Barger <ar...@bargr.net>.
On Tue, May 31, 2016 at 3:17 AM, Gilles <gi...@harfang.homelinux.org>
wrote:

> On Tue, 31 May 2016 02:58:27 +0300, Artem Barger wrote:
>
>> Methods "getMinValue()", "getMinIndex()".
>>>
>>> Important note: any contribution should be based on the contents of
>>> the "develop" branch, not "master". See file
>>>   doc/development/development.howto.txt
>>> in the source tree.
>>>
>>>
>>> ​So in order to use them I need to instantiate a RealVector, right?
>>
>
> Yes.
> And the iteration is probably not efficient since it use the
> high-level API.
>
> Hence I think the question whenever to add static method w/
>> similar functionality to MathArrays class is still valid, especially if
>> I can enhance it to accept array or list of Comparables or to accept
>> Comparator as an additional parameter​.
>>
>
> Yes.
> But perhaps a more general functionality would be useful.
>

​General? Could you give an example?
Aren't these​ enough?

public static <T extends Comparable<T>> T min(T...array);

public static <T extends Comparable<T>> T max(T...array);

public static <T extends Comparable<T>> int argmin(T...array);

public static <T extends Comparable<T>> int argmax(T...array);



> Especially with the new Java 8 function types.
>

​It's easy to implement having Java 8 function types, not sure I'm
following you
w/ how it could affect the API's of proposed methods.​

I think I will submit a JIRA ticket w/ these and submit a patch, reviewing
it we will
be able to eventually come to some reasonable solution.

Anyway ​if such functionality is already exist in "RealVector", I guess
>>>
>>>> there is no point of adding
>>>> it to MathArrays, unless RealVector should be refactored and
>>>> functionality
>>>> should be removed from
>>>> there.
>>>>
>>>>
>>> Yes, refactored it should be:
>>>  https://issues.apache.org/jira/browse/MATH-765
>>>
>>>
>>> ​It says that these methods to be removed from RealVector.​
>>
>
> A pity that what it says did not occur. :-}
>

​:)))​

​Best,
          Artem Barger.​

Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Gilles <gi...@harfang.homelinux.org>.
On Tue, 31 May 2016 02:58:27 +0300, Artem Barger wrote:
>> Methods "getMinValue()", "getMinIndex()".
>>
>> Important note: any contribution should be based on the contents of
>> the "develop" branch, not "master". See file
>>   doc/development/development.howto.txt
>> in the source tree.
>>
>>
> \u200bSo in order to use them I need to instantiate a RealVector, right?

Yes.
And the iteration is probably not efficient since it use the
high-level API.

> Hence I think the question whenever to add static method w/
> similar functionality to MathArrays class is still valid, especially 
> if
> I can enhance it to accept array or list of Comparables or to accept
> Comparator as an additional parameter\u200b.

Yes.
But perhaps a more general functionality would be useful.
Especially with the new Java 8 function types.

>
>> Anyway \u200bif such functionality is already exist in "RealVector", I 
>> guess
>>> there is no point of adding
>>> it to MathArrays, unless RealVector should be refactored and 
>>> functionality
>>> should be removed from
>>> there.
>>>
>>
>> Yes, refactored it should be:
>>  https://issues.apache.org/jira/browse/MATH-765
>>
>>
> \u200bIt says that these methods to be removed from RealVector.\u200b

A pity that what it says did not occur. :-}

>> [Also, I think that the functionality which you proposed might be
>> available or fairly easily achievable in Java 8.]
>>
>>
> \u200bWhat is the minimal Java version currently officially supported by 
> CM\u200b?

Java 7 currently.

> I just wondering in context of MATH-1371, since assuming it's Java 8 
> I can
> add some more improvements.

You are welcome to start a new thread about the issue of the minimally
supported Java version.

Regards,
Gilles

>
>
>
>>
>> Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Artem Barger <ar...@bargr.net>.
> Methods "getMinValue()", "getMinIndex()".
>
> Important note: any contribution should be based on the contents of
> the "develop" branch, not "master". See file
>   doc/development/development.howto.txt
> in the source tree.
>
>
​So in order to use them I need to instantiate a RealVector, right?
Hence I think the question whenever to add static method w/
similar functionality to MathArrays class is still valid, especially if
I can enhance it to accept array or list of Comparables or to accept
Comparator as an additional parameter​.



> Anyway ​if such functionality is already exist in "RealVector", I guess
>> there is no point of adding
>> it to MathArrays, unless RealVector should be refactored and functionality
>> should be removed from
>> there.
>>
>
> Yes, refactored it should be:
>  https://issues.apache.org/jira/browse/MATH-765
>
>
​It says that these methods to be removed from RealVector.​



> [Also, I think that the functionality which you proposed might be
> available or fairly easily achievable in Java 8.]
>
>
​What is the minimal Java version currently officially supported by CM​?
I just wondering in context of MATH-1371, since assuming it's Java 8 I can
add some more improvements.



>
> Gilles
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Gilles <gi...@harfang.homelinux.org>.
On Tue, 31 May 2016 01:34:50 +0300, Artem Barger wrote:
> Hi
>
> On Tue, May 31, 2016 at 1:19 AM, Gilles 
> <gi...@harfang.homelinux.org>
> wrote:
>
>> Hi.
>>
>> On Tue, 31 May 2016 00:05:55 +0300, Artem Barger wrote:
>>
>>> Hi.
>>>
>>> Lately working w/ Apache Commons Math, library I've found myself
>>> implementing functions which given an array of either doubles of 
>>> integers
>>> return the min or max value among all elements of an array. 
>>> Moreover I've
>>> added an argmin/argmin functions as well, which for given array of
>>> double/int values return an index of min/max element within that 
>>> array.
>>>
>>> Since I didn't find such functions available in the project, I'm 
>>> willing
>>> to
>>> contribute these function into the framework and was curious 
>>> whenever it's
>>> usable? Also what should be the right place to put these functions? 
>>> I've
>>> added them as static method for MathArrays class, however not 100% 
>>> sure
>>> this is the right place.
>>>
>>> Think further about these functions, I can easily make them work w/
>>> instances of Comparable interface of accept Comparator<T> as second
>>> parameter.
>>>
>>> What should be the right way to handle this?
>>>
>>
>> It might be added to MathArrays indeed.
>> Note that such a functionality is available in "RealVector".
>>
>
> \u200bI might be looking on the wrong source tree, but I do not see it in
> "RealVector".
> Currently I'm using this repo: "
> http://git-wip-us.apache.org/repos/asf/commons-math.git"
> and looking on master branch.

https://git1-us-west.apache.org/repos/asf?p=commons-math.git;a=blob;f=src/main/java/org/apache/commons/math4/linear/RealVector.java;h=545a521ce729312b7ae630a9856fca4f22c45e00;hb=HEAD

Methods "getMinValue()", "getMinIndex()".

Important note: any contribution should be based on the contents of
the "develop" branch, not "master". See file
   doc/development/development.howto.txt
in the source tree.

> Anyway \u200bif such functionality is already exist in "RealVector", I 
> guess
> there is no point of adding
> it to MathArrays, unless RealVector should be refactored and 
> functionality
> should be removed from
> there.

Yes, refactored it should be:
  https://issues.apache.org/jira/browse/MATH-765

[Also, I think that the functionality which you proposed might be
available or fairly easily achievable in Java 8.]


Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Artem Barger <ar...@bargr.net>.
Hi

On Tue, May 31, 2016 at 1:19 AM, Gilles <gi...@harfang.homelinux.org>
wrote:

> Hi.
>
> On Tue, 31 May 2016 00:05:55 +0300, Artem Barger wrote:
>
>> Hi.
>>
>> Lately working w/ Apache Commons Math, library I've found myself
>> implementing functions which given an array of either doubles of integers
>> return the min or max value among all elements of an array. Moreover I've
>> added an argmin/argmin functions as well, which for given array of
>> double/int values return an index of min/max element within that array.
>>
>> Since I didn't find such functions available in the project, I'm willing
>> to
>> contribute these function into the framework and was curious whenever it's
>> usable? Also what should be the right place to put these functions? I've
>> added them as static method for MathArrays class, however not 100% sure
>> this is the right place.
>>
>> Think further about these functions, I can easily make them work w/
>> instances of Comparable interface of accept Comparator<T> as second
>> parameter.
>>
>> What should be the right way to handle this?
>>
>
> It might be added to MathArrays indeed.
> Note that such a functionality is available in "RealVector".
>

​I might be looking on the wrong source tree, but I do not see it in
"RealVector".
Currently I'm using this repo: "
http://git-wip-us.apache.org/repos/asf/commons-math.git"
and looking on master branch.

Anyway ​if such functionality is already exist in "RealVector", I guess
there is no point of adding
it to MathArrays, unless RealVector should be refactored and functionality
should be removed from
there.



>
> Regards,
> Gilles
>
>
>
>> Best regards,
>>                       Artem Barger.
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [Math] Adding min/max and argmin/argmax values for an arrays of double/int (Comparable).

Posted by Gilles <gi...@harfang.homelinux.org>.
Hi.

On Tue, 31 May 2016 00:05:55 +0300, Artem Barger wrote:
> Hi.
>
> Lately working w/ Apache Commons Math, library I've found myself
> implementing functions which given an array of either doubles of 
> integers
> return the min or max value among all elements of an array. Moreover 
> I've
> added an argmin/argmin functions as well, which for given array of
> double/int values return an index of min/max element within that 
> array.
>
> Since I didn't find such functions available in the project, I'm 
> willing to
> contribute these function into the framework and was curious whenever 
> it's
> usable? Also what should be the right place to put these functions? 
> I've
> added them as static method for MathArrays class, however not 100% 
> sure
> this is the right place.
>
> Think further about these functions, I can easily make them work w/
> instances of Comparable interface of accept Comparator<T> as second
> parameter.
>
> What should be the right way to handle this?

It might be added to MathArrays indeed.
Note that such a functionality is available in "RealVector".

Regards,
Gilles


>
> Best regards,
>                       Artem Barger.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org