From ruby-math-admin@netlab.co.jp Thu Apr 27 12:30:05 2000 Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by blade.nagaokaut.ac.jp (8.8.8/8.8.8/Debian/GNU) with ESMTP id MAA03298 for ; Thu, 27 Apr 2000 12:30:05 +0900 Resent-From: ruby-math-admin@netlab.co.jp Received: from hoyogw.netlab.co.jp by voscc.nagaokaut.ac.jp id MAA92659; Thu, 27 Apr 2000 12:26:01 +0900 (JST) Received: from hoyogw.netlab.co.jp (matz@localhost [127.0.0.1]) by hoyogw.netlab.co.jp (8.9.3+3.2W/3.7W/1.3) with SMTP id MAA16505 for ; Thu, 27 Apr 2000 12:26:00 +0900 Date: Mon, 07 Feb 2000 13:12:15 +0900 From: Masahiro TANAKA Reply-To: ruby-math@netlab.co.jp Subject: [ruby-math:00239] Re: new obj at coercing To: ruby-math@netlab.co.jp Message-Id: <20000207131215N.masa@koala.astro.isas.ac.jp> In-Reply-To: <200002062250.HAA08218@hanare00.math.sci.hokudai.ac.jp> References: <200002062250.HAA08218@hanare00.math.sci.hokudai.ac.jp> X-ML-Name: ruby-math X-Mail-Count: 00239 X-MLServer: fml [fml 2.2]; post only (only members can post) X-ML-Info: If you have a question, send a mail with the body "# help" (without quotes) to the address ruby-math-ctl@netlab.co.jp; help= X-Mailer: Mew version 1.94.1 on Emacs 20.4 / Mule 4.0 (HANANOEN) X-Dispatcher: imput version 990905(IM130) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit Precedence: bulk Resent-To: poffice@blade.nagaokaut.ac.jp Resent-Date: Thu, 27 Apr 2000 12:25:59 +0900 Resent-Message-Id: <200004271226.FMLAAA16500.ruby-math@netlab.co.jp> 田中@ISASです。 In message: <<[ruby-math:00236] new obj at coercing>> >>> gotoken@math.sci.hokudai.ac.jp (GOTO Kentaro) wrote: > 数値配列なんですけど、coercing で悩みがあります。 > > def coerce(other) > if other.type == self.type > return [self, other] > elsif other.is_a? Numeric > return [NumArray.new(self.size, other), self] > else > super > end > end > > みたいな感じにしてるんですけど、これだと必ずその場で捨てられ > るオブジェクト NumArray.new(self.size, other) が作られます。 これは、要素 other を self.size 個持つ配列を作るのですよね? 代替案として、ここでは NumArray.new(other) で 1要素の配列を 作っておき、addなどの中で 1要素+多要素の演算ができるように する、というのはいかがでしょうか。 田中昌宏