From dev-return-117869-apmail-commons-dev-archive=commons.apache.org@commons.apache.org Fri Jan 29 02:45:06 2010 Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 84708 invoked from network); 29 Jan 2010 02:45:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Jan 2010 02:45:05 -0000 Received: (qmail 18544 invoked by uid 500); 29 Jan 2010 02:45:05 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 18343 invoked by uid 500); 29 Jan 2010 02:45:04 -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 18333 invoked by uid 99); 29 Jan 2010 02:45:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jan 2010 02:45:04 +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 (athena.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 02:44:56 +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 <0KWZ00CYXM9ZBH40@vms173019.mailsrvcs.net> for dev@commons.apache.org; Thu, 28 Jan 2010 20:44:25 -0600 (CST) Message-id: <58B12D334B4B4609BE60AA61162FE523@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> In-reply-to: <4B61F018.4090404@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: Thu, 28 Jan 2010 18:44:23 -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 -------------------------------------------------- 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). > 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