[Tioga-users] Tioga and NArray
Bill Paxton
paxton at kitp.ucsb.edu
Mon Apr 28 11:30:20 EDT 2008
Hi Dave,
I'm forwarding your message to tioga-users until the mailing list
issues get resolved.
Thanks for the NArray info. If there are performance concerns,
perhaps some of the conversion can move to the Dvector/Dtable c
code. If you figure out how to get hold of the NArray pointer, it
shouldn't be too hard to do the memcpy.
BTW: you asked about the possible impact of a python version of tioga
on the ruby version. First, let me say that the ruby version is
alive and well and is the version that Vincent and I use on a daily
basis. The python version came about because there are python users
who wanted to have tioga in their native language. So far, the
effort has had a positive effect on the ruby implementation, both in
terms of internal cleanup and, even better, in terms of good new
ideas about functionality that will eventually show up in both python
and ruby versions of tioga.
Cheers,
Bill
On Apr 28, 2008, at 8:09 AM, David MacMahon wrote:
> Thanks for the feedback, Bill. I had signed up using
> davidm at rubyforge.org, which worked until I tried to post and then
> it failed with...
>
> 550 5.7.1 <davidm at rubyforge.org>: Sender address rejected: Mail
> server in loopback network
>
> ...so I reposted from my regular address (which I will sign up with
> later this morning, I've got more to say!).
>
> BTW, the "from_na" scheme does work...
>
> $ irb -r narray -r Dobjects/Dvector
> irb(main):001:0> module Dobjects
> irb(main):002:1> class Dvector
> irb(main):003:2> def self.from_na(na)
> irb(main):004:3> _load([1, na.length, na.to_s].pack('CIa*'))
> irb(main):005:3> end
> irb(main):006:2> end
> irb(main):007:1> end
> => nil
> irb(main):008:0> na=NArray.dfloat(4).randomn
> => NArray(ref).float(4):
> [ 0.437404, 1.90081, -1.23652, -0.832147 ]
> irb(main):009:0> dv=Dobjects::Dvector.fr
> Dobjects::Dvector.freeze Dobjects::Dvector.from_na
> Dobjects::Dvector.frozen?
> irb(main):009:0> dv=Dobjects::Dvector.from_na(na)
> => 0.437404 1.90081 -1.23652 -0.832147
>
> That's probably about the fastest conversion possible without
> getting the NArray structure from the Ruby VALUE in C and doing a
> memcpy of its data. I'm also close to a similar technique for a
> "to_na" instance method using _dump.
>
> Something similar should be possible with Dtable, though there
> might need to be a transpose involved.
>
> Dave
>
> On Apr 28, 2008, at 7:29 , Bill Paxton wrote:
>> Hi Dave,
>>
>> Good progress! If the "from_na" scheme works, it should become a
>> part of tioga, so keep everyone informed.
>>
>> --Bill
>>
>> p.s. It would probably be a good idea for you to sign up for the
>> tioga mailing lists!
>>
>>
>> On Apr 28, 2008, at 12:21 AM, David MacMahon wrote:
>>
>>> Thanks for the reply, Bill!
>>>
>>>> Concerning NArray -- we are currently going through a reworking of
>>>> the tioga implementation prompted by Taro Sato's project to make a
>>>> Python version. Taro's version of tioga doesn't use Dvectors -- it
>>>> uses the standard python analog of NArray.
>>>
>>> That sounds interesting, though I'm not sure what that means for
>>> the future of Ruby Tioga.
>>>
>>>
>>>> So, if you're willing to help Taro get some new software
>>>> working, you
>>>> might want to give "PyTioga" a try!
>>>
>>> Thanks for the info, but switching to Python is not a palatable
>>> option.
>>>
>>>> For the ruby Tioga, the NArray to Array to Dvector hack is probably
>>>> the best work around for the short term.
>>>
>>> I've had some initial success (very initial) using NArray with
>>> the sine.rb sample. Perhaps it was automatically doing the
>>> NArray->Array->Dvector conversion under the covers, but here's a
>>> diff of the changes I made...
>>>
>>> $ diff -U0 sine.rb na_sine.rb
>>> --- sine.rb 2008-04-23 12:28:55.000000000 -0700
>>> +++ na_sine.rb 2008-04-27 22:40:21.000000000 -0700
>>> @@ -10,0 +11 @@
>>> +require 'narray'
>>> @@ -34,2 +35,2 @@
>>> - xAxis = Dvector.new(num) {|i| 2*PI*i/(num-1) }
>>> - yAxis = xAxis.sin
>>> + xAxis = NArray.float(num).indgen!.mul!(2*PI/(num-1))
>>> + yAxis = NMath.sin(xAxis)
>>>
>>> If needed, I can monkey-patch a "from_na" method into the Dvector
>>> class...
>>>
>>> module Dobjects
>>> class Dvector
>>> def self.from_na(na)
>>> _load([1, na.length, na.to_s].pack('CIa*'))
>>> end
>>> end
>>> end
>>>
>>> I think I can do something similar for Dtable, too.
>>>
>>> Dave
>>>
>>> _______________________________________________
>>> Tioga-users mailing list
>>> Tioga-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/tioga-users
>>>
>>
>
>
More information about the Tioga-users
mailing list