[ 
https://issues.apache.org/jira/browse/MATH-1258?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Otmar Ertl updated MATH-1258:
-----------------------------
    Attachment: patch.diff

I also do not like throwing an ArrayIndexOutOfBoundsException due to 2 reasons:

* The current behavior is asymmetric. distance(a,b) succeeds while distance(b, 
a) fails with an exception, if a and b have different lengths. Since distance 
functions are known to be symmetric, their behavior should be symmetric too, 
even in case of invalid parameters.
* The element-by-element functions in MathArrays throw a 
DimensionMismatchException instead of an ArrayIndexOutOfBoundsException. For 
the sake of consistency, I think throwing a DimensionMismatchException is more 
appropriate for distance functions as well.

Please see attached patch.


> compute() method in classes in org.apache.commons.math4.ml.distance package
> ---------------------------------------------------------------------------
>
>                 Key: MATH-1258
>                 URL: https://issues.apache.org/jira/browse/MATH-1258
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Gunel Jahangirova
>            Priority: Minor
>         Attachments: patch.diff
>
>
> Hi!
> There are five classes CanberraDistance, ChebyshevDistance, 
> EarthMoversDistance, EuclideanDistance and ManhattanDistance in 
> org.apache.commons.math4.ml.distance package, which compute different types 
> of distances. Each of them contains method compute(double[] a, double[] b) 
> that accepts two double arrays as variables.
> However, if the lengths of array a is greater than the length of array b, the 
> method compute() in all the five classes produces 
> java.lang.ArrayIndexOutOfBoundsException.
> For example,
>          private void test0() {
>            CanberraDistance distance = new CanberraDistance();
>     
>             final double[] a = { 1, 2, 3, 4, 9, 4 };
>             final double[] b = { -5, -6, 7, 4, 3 };
>             distance.compute(a, b);
>        }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to