Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6E5867A44 for ; Thu, 11 Aug 2011 11:19:11 +0000 (UTC) Received: (qmail 94832 invoked by uid 500); 11 Aug 2011 11:19:10 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 94452 invoked by uid 500); 11 Aug 2011 11:19:02 -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 94444 invoked by uid 99); 11 Aug 2011 11:19:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 11:19:00 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [193.74.71.27] (HELO eir.is.scarlet.be) (193.74.71.27) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2011 11:18:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scarlet.be; s=scarlet; t=1313061511; bh=anbQpft07+eUzidIJSTdgC+1d8P/yYpRmcMvEtXoXyc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Transfer-Encoding:In-Reply-To; b=Ue6LlcVcSyMa8HnAj2trAE8aE+ecYYvcO6L0ay95xHGjkJGJbGo6SF0Aja2nnJe/q hPpdrfLfe2JdXo5PjM968DctEM7vAuiK+AOkzSM8QBOSSqovLDQwh+gm7ZtdVvRPNN M/tlh1Mo/aCyXFycqbeHaoFhplM+0TXQuZBhJNMk= Received: from mail.harfang.homelinux.org (ip-213-49-235-93.dsl.scarlet.be [213.49.235.93]) by eir.is.scarlet.be (8.14.5/8.14.5) with ESMTP id p7BBIUt9005105 for ; Thu, 11 Aug 2011 13:18:31 +0200 X-Scarlet: d=1313061511 c=213.49.235.93 Received: from localhost (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id E7EE0617D1 for ; Thu, 11 Aug 2011 13:22:38 +0200 (CEST) Received: from mail.harfang.homelinux.org ([192.168.20.11]) by localhost (mail.harfang.homelinux.org [192.168.20.11]) (amavisd-new, port 10024) with ESMTP id y1whzEzHWY5C for ; Thu, 11 Aug 2011 13:22:37 +0200 (CEST) Received: from dusk.harfang.homelinux.org (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 1458E6175A for ; Thu, 11 Aug 2011 13:22:37 +0200 (CEST) Received: from eran by dusk.harfang.homelinux.org with local (Exim 4.76) (envelope-from ) id 1QrTLQ-0003vt-RT for dev@commons.apache.org; Thu, 11 Aug 2011 13:22:36 +0200 Date: Thu, 11 Aug 2011 13:22:36 +0200 From: Gilles Sadowski To: dev@commons.apache.org Subject: Re: [math] Read-only RealVector Message-ID: <20110811112236.GB2590@dusk.harfang.homelinux.org> Mail-Followup-To: dev@commons.apache.org References: <1313048561.2738.2.camel@knuffelchen> <1313052399.2877.6.camel@knuffelchen> <4E43A1BB.3050508@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: Tiny Tux X-PGP-Key-Fingerprint: 53B9 972E C2E6 B93C BEAD 7092 09E6 AF46 51D0 5641 User-Agent: Mutt/1.5.21 (2010-09-15) X-DCC-scarlet.be-Metrics: eir 20001; Body=1 Fuz1=1 Fuz2=1 X-Virus-Scanned: clamav-milter 0.97.1-exp at eir X-Virus-Status: Clean Hello S�bastien. > > > > Well, in fact I would very much like to have immutable vectors too. > > Immutability is really a way to simplify implementations. Surprisingly it > > sometimes also decrease time and memory consumption, because defensive > > copies littering user code can be avoided. > > > Luc, I have a silly question. Why do you think immutable vectors would > prevent defensive copy ? Creating an immutable vector from an existing > mutable vector would require a defensive copy, wouldn't it? > Thats the reason why I'm talking about read-only vectors, and not > immutable vectors. > The solver would keep a reference to the underlying (mutable) vector, > so would be able to modify (indirectly) the read-only vector. > The observer would only have a reference to the read-only vector, so > would not be able to modify the underlying vector. I think that you were right to stress the difference between immutable and read-only. If I'm not mistaken, in JDK parlance they call the latter "unmodifiable" (cf. the methods "unmodifiableCollection" and siblings in the standard class "java.util.Collections"). The idea which you referred to at the beginning of this thread is exactly what they do: The wrapping class throws "UnsupportedOperationException" from any "mutating" method. What Luc said is that when you pass an (already) immutable object, you do not have to make a copy; a reference is as safe. I'm not sure whether that would still be true with an unmodifiable reference. I.e. couldn't it be cast to its underlying modifiable reference? However that would be on-purpose nasty code, not a mistake on the part of the checker code. So, a utility method like public static RealVector unmodifiableRealVector(RealVector v) in class "AbstractRealVector", would fit your need, IMO. Best, Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org