Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 32201 invoked from network); 29 Jan 2010 09:55:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Jan 2010 09:55:22 -0000 Received: (qmail 99873 invoked by uid 500); 29 Jan 2010 09:55:21 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 99741 invoked by uid 500); 29 Jan 2010 09:55:21 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 99731 invoked by uid 99); 29 Jan 2010 09:55:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jan 2010 09:55:21 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FM_FAKE_HELO_VERIZON,SPF_PASS,STOX_REPLY_TYPE X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of billwbarker@verizon.net designates 206.46.173.19 as permitted sender) Received: from [206.46.173.19] (HELO vms173019pub.verizon.net) (206.46.173.19) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jan 2010 09:55:11 +0000 MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; format=flowed; charset=iso-8859-1; reply-type=original Received: from BillPC ([unknown] [71.165.190.183]) by vms173019.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0KX000LQ467DGOA0@vms173019.mailsrvcs.net> for dev@commons.apache.org; Fri, 29 Jan 2010 03:54:50 -0600 (CST) Message-id: <8FE2A9C779C6406B9B0C22F14C8E8FDA@BillPC> From: "Bill Barker" To: "Commons Developers List" References: <20100128194232.18DB12388A18@eris.apache.org> <3796c6d51001281203v5c943e57l9717905ef6554c2e@mail.gmail.com> <3796c6d51001281205t47a2f46el9e15a7a2660bfefa@mail.gmail.com> <4B61F018.4090404@free.fr> <58B12D334B4B4609BE60AA61162FE523@BillPC> <4B62A10B.1030906@free.fr> In-reply-to: <4B62A10B.1030906@free.fr> Subject: Re: svn commit: r904231 - in /commons/proper/math/trunk/src:main/java/org/apache/commons/math/linear/AbstractRealVector.javasite/xdoc/changes.xml test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java Date: Fri, 29 Jan 2010 01:54:49 -0800 X-Priority: 3 X-MSMail-priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 14.0.8089.726 X-MIMEOLE: Produced By Microsoft MimeOLE V14.0.8089.726 X-Virus-Checked: Checked by ClamAV on apache.org -------------------------------------------------- From: "Luc Maisonobe" Sent: Friday, January 29, 2010 12:49 AM To: "Commons Developers List" Subject: Re: svn commit: r904231 - in /commons/proper/math/trunk/src:main/java/org/apache/commons/math/linear/AbstractRealVector.javasite/xdoc/changes.xml test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java > Bill Barker a �crit : >> >> >> -------------------------------------------------- >> From: "Luc Maisonobe" >> Sent: Thursday, January 28, 2010 12:14 PM >> To: "Commons Developers List" >> Subject: Re: svn commit: r904231 - in >> /commons/proper/math/trunk/src:main/java/org/apache/commons/math/linear/AbstractRealVector.javasite/xdoc/changes.xml >> test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java >> >>> Mikkel Meyer Andersen a �crit : >>>> Hi. >>>> >>>> Thanks! >>>> >>>> Why use an iterator instead of just a simple for-loop? And what about >>>> saving >>>> the values until the vector invalidates - I see pros and cons for both >>>> approaches, so it's more to hear what your thoughts were? >>> >>> It is because there already are several implementations of the class and >>> they may use different strategies to access elements. Such iterators >>> have been introduced by recent changes so I thought it was better to >>> stick with them now. >>> >> >> +1 >> There is a case for using the sparseIterator, but that probably makes >> the methods overly complicated (since zero values have to be handled >> specially). > > I did hesitate to add this. I thought adding special getSparseMinIndex > and so on, that would explicitely ignore non-zeros. We can add them too > if you think ignoring zeros is the right thing to do. In that case, we > simply copy the methods and change iterator into sparse iterator, that's > all. > I personally have no interest in getSparseMinIndex. Granted, the iterator for OpenMapRealVector is slightly expensive (does a map lookup for each index), but the more I think about it the less I like using sparseIterator here. This would involve something like: if(minValue > 0) { //repeat loop with iterator to find a zero value } possibly traversing the vector twice. For 2.1 I'd just go with this addition, and deal with any user complaints in a later version. > Luc > >> >>> As for saving the values, we cannot be sure when the vector changes. >>> Users may do this several ways and we simply did not implement any >>> control on that. >>> >>> Luc >>> >>>> >>>> Cheers, Mikkel. >>>> >>>> On 28/01/2010 8:42 PM, wrote: >>>> >>>> Author: luc >>>> Date: Thu Jan 28 19:42:31 2010 >>>> New Revision: 904231 >>>> >>>> URL: http://svn.apache.org/viewvc?rev=904231&view=rev >>>> Log: >>>> added min/max getters for real vectors >>>> For compatibility reasons, these methods have been put in the topmost >>>> abstract class but not in the interface yet. It could be pushed to the >>>> interface when next major version will be released. >>>> JIRA: MATH-334 >>>> >>>> Modified: >>>> >>>> >>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java >>>> >>>> commons/proper/math/trunk/src/site/xdoc/changes.xml >>>> >>>> >>>> commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java >>>> >>>> >>>> Modified: >>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java >>>> >>>> URL: >>>> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java?rev=904231&r1=904230&r2=904231&view=diff >>>> >>>> ============================================================================== >>>> >>>> --- >>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java >>>> >>>> (original) >>>> +++ >>>> commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java >>>> >>>> Thu Jan 28 19:42:31 2010 >>>> @@ -292,6 +292,58 @@ >>>> return d; >>>> } >>>> >>>> + /** Get the index of the minimum entry. >>>> + * @return index of the minimum entry or -1 if vector length is 0 >>>> + * or all entries are NaN >>>> + */ >>>> + public int getMinIndex() { >>>> + int minIndex = -1; >>>> + double minValue = Double.POSITIVE_INFINITY; >>>> + Iterator iterator = iterator(); >>>> + while (iterator.hasNext()) { >>>> + final Entry entry = iterator.next(); >>>> + if (entry.getValue() <= minValue) { >>>> + minIndex = entry.getIndex(); >>>> + minValue = entry.getValue(); >>>> + } >>>> + } >>>> + return minIndex; >>>> + } >>>> + >>>> + /** Get the value of the minimum entry. >>>> + * @return value of the minimum entry or NaN if all entries are >>>> NaN >>>> + */ >>>> + public double getMinValue() { >>>> + final int minIndex = getMinIndex(); >>>> + return minIndex < 0 ? Double.NaN : getEntry(minIndex); >>>> + } >>>> + >>>> + /** Get the index of the maximum entry. >>>> + * @return index of the maximum entry or -1 if vector length is 0 >>>> + * or all entries are NaN >>>> + */ >>>> + public int getMaxIndex() { >>>> + int maxIndex = -1; >>>> + double maxValue = Double.NEGATIVE_INFINITY; >>>> + Iterator iterator = iterator(); >>>> + while (iterator.hasNext()) { >>>> + final Entry entry = iterator.next(); >>>> + if (entry.getValue() >= maxValue) { >>>> + maxIndex = entry.getIndex(); >>>> + maxValue = entry.getValue(); >>>> + } >>>> + } >>>> + return maxIndex; >>>> + } >>>> + >>>> + /** Get the value of the maximum entry. >>>> + * @return value of the maximum entry or NaN if all entries are >>>> NaN >>>> + */ >>>> + public double getMaxValue() { >>>> + final int maxIndex = getMaxIndex(); >>>> + return maxIndex < 0 ? Double.NaN : getEntry(maxIndex); >>>> + } >>>> + >>>> /** {@inheritDoc} */ >>>> public RealVector mapAbs() { >>>> return copy().mapAbsToSelf(); >>>> >>>> Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml >>>> URL: >>>> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=904231&r1=904230&r2=904231&view=diff >>>> >>>> ============================================================================== >>>> >>>> --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) >>>> +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Jan 28 >>>> 19:42:31 >>>> 2010 >>>> @@ -39,6 +39,10 @@ >>>> >>>> >>>> >>>> + >>>> + Added min/max getters for real vectors (not yet in the >>>> RealVector >>>> interface for >>>> + compatibility purposes, but in the AbstractRealVector abstract >>>> class). >>>> + >>>> >>>> Fixed automatic step initialization in embedded Runge-Kutta >>>> integrators. >>>> The relative tolerance setting was never used, only the >>>> absolute >>>> tolerance >>>> >>>> Modified: >>>> commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java >>>> >>>> URL: >>>> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java?rev=904231&r1=904230&r2=904231&view=diff >>>> >>>> ============================================================================== >>>> >>>> --- >>>> commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java >>>> >>>> (original) >>>> +++ >>>> commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java >>>> >>>> Thu Jan 28 19:42:31 2010 >>>> @@ -1308,6 +1308,30 @@ >>>> } >>>> >>>> >>>> + public void testMinMax() { >>>> + ArrayRealVector v1 = new ArrayRealVector(new double[] { 0, >>>> -6, 4, >>>> 12, 7 }); >>>> + assertEquals(1, v1.getMinIndex()); >>>> + assertEquals(-6, v1.getMinValue(), 1.0e-12); >>>> + assertEquals(3, v1.getMaxIndex()); >>>> + assertEquals(12, v1.getMaxValue(), 1.0e-12); >>>> + ArrayRealVector v2 = new ArrayRealVector(new double[] { >>>> Double.NaN, >>>> 3, Double.NaN, -2 }); >>>> + assertEquals(3, v2.getMinIndex()); >>>> + assertEquals(-2, v2.getMinValue(), 1.0e-12); >>>> + assertEquals(1, v2.getMaxIndex()); >>>> + assertEquals(3, v2.getMaxValue(), 1.0e-12); >>>> + ArrayRealVector v3 = new ArrayRealVector(new double[] { >>>> Double.NaN, >>>> Double.NaN }); >>>> + assertEquals(-1, v3.getMinIndex()); >>>> + assertTrue(Double.isNaN(v3.getMinValue())); >>>> + assertEquals(-1, v3.getMaxIndex()); >>>> + assertTrue(Double.isNaN(v3.getMaxValue())); >>>> + ArrayRealVector v4 = new ArrayRealVector(new double[0]); >>>> + assertEquals(-1, v4.getMinIndex()); >>>> + assertTrue(Double.isNaN(v4.getMinValue())); >>>> + assertEquals(-1, v4.getMaxIndex()); >>>> + assertTrue(Double.isNaN(v4.getMaxValue())); >>>> + } >>>> + >>>> + >>>> /** verifies that two vectors are close (sup norm) */ >>>> protected void assertClose(String msg, double[] m, double[] n, >>>> double tolerance) { >>>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >>> For additional commands, e-mail: dev-help@commons.apache.org >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> For additional commands, e-mail: dev-help@commons.apache.org >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org