Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 61309 invoked from network); 11 Dec 2009 19:32:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Dec 2009 19:32:14 -0000 Received: (qmail 2317 invoked by uid 500); 11 Dec 2009 19:32:14 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 2203 invoked by uid 500); 11 Dec 2009 19:32:13 -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 2193 invoked by uid 99); 11 Dec 2009 19:32:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Dec 2009 19:32:13 +0000 X-ASF-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [194.206.126.239] (HELO smtp.nordnet.fr) (194.206.126.239) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Dec 2009 19:32:11 +0000 Received: from lehrin (7.253.146.195.dynamic.adsl.abo.nordnet.fr [195.146.253.7]) by smtp.nordnet.fr (Postfix) with ESMTP id 07D4E34237 for ; Fri, 11 Dec 2009 20:31:47 +0100 (CET) Received: by lehrin (Postfix, from userid 5001) id 79D6F408C; Fri, 11 Dec 2009 20:31:49 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on lehrin.spaceroots.local X-Spam-Level: Received: from lehrin.spaceroots.local (lehrin.spaceroots.local [127.0.0.1]) by lehrin (Postfix) with ESMTP id 1E0144085 for ; Fri, 11 Dec 2009 20:31:48 +0100 (CET) Message-ID: <4B229E23.5090509@free.fr> Date: Fri, 11 Dec 2009 20:31:47 +0100 From: Luc Maisonobe User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: dev@commons.apache.org Subject: Re: svn commit: r889516 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear: AbstractRealVector.java OpenMapRealVector.java References: <20091211063821.7008B23888FE@eris.apache.org> In-Reply-To: <20091211063821.7008B23888FE@eris.apache.org> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Old-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.2.5 billbarker@apache.org a écrit : > Author: billbarker > Date: Fri Dec 11 06:38:20 2009 > New Revision: 889516 > > URL: http://svn.apache.org/viewvc?rev=889516&view=rev > Log: > Initial fixes to the iterators. Thanks a lot for your help, Bill. Luc > > This fixes the default sparseIterator problem where a RealVector only contains zero elements, and add a sparseIterator to the OpenMapRealVector. > > Still TODO: > 1) add unit tests > 2) remove *mapTo and *mapToSelf from OpenMapRealVector > 3) fix javadocs > 4) remove support for non-zero default values in OpenMapRealVector > > Modified: > commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/AbstractRealVector.java > commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.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=889516&r1=889515&r2=889516&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 Fri Dec 11 06:38:20 2009 > @@ -769,9 +769,15 @@ > if (current.getValue() == 0) { > advance(current); > } > - next = new EntryImpl(); > - next.setIndex(current.getIndex()); > - advance(next); > + if(current.getIndex() >= 0){ > + // There is at least one non-zero entry > + next = new EntryImpl(); > + next.setIndex(current.getIndex()); > + advance(next); > + } else { > + // The vector consists of only zero entries, so deny having a next > + current = null; > + } > } > > /** Advance an entry up to the next non null one. > > Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java > URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java?rev=889516&r1=889515&r2=889516&view=diff > ============================================================================== > --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java (original) > +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java Fri Dec 11 06:38:20 2009 > @@ -1250,4 +1250,70 @@ > return (double)entries.size()/(double)getDimension(); > } > > + /** @{InheritDoc} */ > + public java.util.Iterator sparseIterator() { > + return new OpenMapSparseIterator(); > + } > + > + /** > + * Implementation of Entry optimized for OpenMap. > + *

This implementation does not allow arbitrary calls to setIndex > + * since the order that entries are returned is undefined. > + */ > + protected class OpenMapEntry extends Entry { > + private final Iterator iter; > + > + protected OpenMapEntry(Iterator iter) { > + this.iter = iter; > + } > + /** {@InheritDoc} */ > + @Override > + public double getValue() { > + return iter.value(); > + } > + > + /** {@InheritDoc} */ > + @Override > + public void setValue(double value) { > + entries.put(iter.key(), value); > + } > + > + /** {@InheritDoc} */ > + @Override > + public int getIndex() { > + return iter.key(); > + } > + } > + > + /** > + * Iterator class to do iteration over just the non-zero elements. > + *

This implementation is fail-fast, so cannot be used to modify any zero element. > + * > + */ > + > + protected class OpenMapSparseIterator implements java.util.Iterator { > + private final Iterator iter; > + private final Entry current; > + > + protected OpenMapSparseIterator() { > + iter = entries.iterator(); > + current = new OpenMapEntry(iter); > + } > + > + /** {@InheritDoc} */ > + public boolean hasNext() { > + return iter.hasNext(); > + } > + > + /** {@InheritDoc} */ > + public Entry next() { > + iter.advance(); > + return current; > + } > + > + public void remove() { > + throw new UnsupportedOperationException("Not supported"); > + } > + > + } > } > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org