Narray and the stdlib

On a ruby-core thread:

(in reference to RCR 260: Make 'Rational' a built-in class )

rational and complex support certainly would gain scientific users.

speaking of scientific users, wouldn't something like stock NArray be
nice in the stdlib? It's general enough to be widely useful and not
overly complex.

I can think of one argument against it, younger rubyists might reach
for it when it's not strictly needed - thereby negating some of the
beautiful wizardry ruby arrays and the like can do. However, it'd
give a nice generally available base to do some efficient heavy data
lifting.

Thoughts?

Cameron

···

On 10/24/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

In article <dcedf5e20510250919v45bdfdc6iceb8472fc2e56ce2@mail.gmail.com>,

On a ruby-core thread:

(in reference to RCR 260: Make 'Rational' a built-in class )

rational and complex support certainly would gain scientific users.

speaking of scientific users, wouldn't something like stock NArray be
nice in the stdlib? It's general enough to be widely useful and not
overly complex.

I can think of one argument against it, younger rubyists might reach
for it when it's not strictly needed - thereby negating some of the
beautiful wizardry ruby arrays and the like can do.

Well, perhaps we could build Hal's Ruby number questionaire into the Ruby
install process and you wouldn't be allowed to use things like narray
until your Ruby number reached a certain level. :wink:

However, it'd
give a nice generally available base to do some efficient heavy data
lifting.

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX). However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

I don't recall if narray is available as a gem or not. As I recall the
last time I downloaded it it was not a gem. So gem-ifying narray would
probably help, although I am using a version of narray that I have
modified so it doesn't do me much good.

Phil
....whose Ruby number is a pathetic 75

···

Cameron McBride <cameron.mcbride@gmail.com> wrote:

On 10/24/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

what did you do? mine suports read/write mmap so an narray can be backed by a
file and any write to the narray writes to the file - very dangerous, not
reccomended, and extremely useful for tweaking a gb grid with minimal io.

-a

···

On Wed, 26 Oct 2005, Phil Tomson wrote:

In article <dcedf5e20510250919v45bdfdc6iceb8472fc2e56ce2@mail.gmail.com>,
Cameron McBride <cameron.mcbride@gmail.com> wrote:

On a ruby-core thread:

(in reference to RCR 260: Make 'Rational' a built-in class )

On 10/24/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

rational and complex support certainly would gain scientific users.

speaking of scientific users, wouldn't something like stock NArray be
nice in the stdlib? It's general enough to be widely useful and not
overly complex.

I can think of one argument against it, younger rubyists might reach
for it when it's not strictly needed - thereby negating some of the
beautiful wizardry ruby arrays and the like can do.

Well, perhaps we could build Hal's Ruby number questionaire into the Ruby
install process and you wouldn't be allowed to use things like narray
until your Ruby number reached a certain level. :wink:

However, it'd
give a nice generally available base to do some efficient heavy data
lifting.

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX). However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

I don't recall if narray is available as a gem or not. As I recall the
last time I downloaded it it was not a gem. So gem-ifying narray would
probably help, although I am using a version of narray that I have
modified so it doesn't do me much good.

--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama

===============================================================================

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX).

Yeah, me too.

Along this line, I thought it would be handy if code written with
NArray could be shared with others on platforms less inclined to
compile extensions. My preferred platforms seem to always have a
compiler in the path, but I hear this is not always the case. I
figured including NArray might be a reasonable step towards playing
well with others.

However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

A good point. Given the limited responses to this thread, I'll take
it as confirmation of limited appeal.

probably help, although I am using a version of narray that I have
modified so it doesn't do me much good.

Another good point. Some of the beauty of NArray is the ease of
extending it, which would again require compilation.

*sigh* Great. Now all I've done is publicly concede to arguments
against including NArray. That's not what I was trying to do... :slight_smile:

I guess I was just envisioning ruby grwoing in appeal for large data
analysis (out of the box). An alternative to IDL or MATLAB with legs
to easily do web services and text munging. If ruby had something
like NArray built in, one can get a good chunk quickly moving before
reaching for external packages. Plus, it'd at least strongly suggest
an "approved" numerical extension to further build on - perhaps
consolidating efforts.

Cameron

···

On 10/25/05, Phil Tomson <ptkwt@aracnet.com> wrote:

In article <Pine.LNX.4.62.0510251406490.2231@harp.ngdc.noaa.gov>,

···

Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

On Wed, 26 Oct 2005, Phil Tomson wrote:

In article <dcedf5e20510250919v45bdfdc6iceb8472fc2e56ce2@mail.gmail.com>,
Cameron McBride <cameron.mcbride@gmail.com> wrote:

On a ruby-core thread:

(in reference to RCR 260: Make 'Rational' a built-in class )

On 10/24/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX). However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

I don't recall if narray is available as a gem or not. As I recall the
last time I downloaded it it was not a gem. So gem-ifying narray would
probably help, although I am using a version of narray that I have
modified so it doesn't do me much good.

what did you do? mine suports read/write mmap so an narray can be backed by a
file and any write to the narray writes to the file - very dangerous, not
reccomended, and extremely useful for tweaking a gb grid with minimal io.

I wanted to treat an NArray as an N-dimensional point so that I could find
the distance from one point to another. I added a distance method and a
couple of other geometrically oriented methods in C.

Phil

btw, this sounds like a fun hack. this anywhere public? (yes, I'm
ignoring the "not reccomended" - sometimes the dangerous toys are the
most fun...)

Cameron

···

On 10/25/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

what did you do? mine suports read/write mmap so an narray can be backed by a
file and any write to the narray writes to the file - very dangerous, not
reccomended, and extremely useful for tweaking a gb grid with minimal io.

Actually, the only popular compilerless platform today is Windows, so
getting NArray into the one-click installer would get you a fair way
along.

martin

···

Cameron McBride <cameron.mcbride@gmail.com> wrote:

Along this line, I thought it would be handy if code written with
NArray could be shared with others on platforms less inclined to
compile extensions. My preferred platforms seem to always have a
compiler in the path, but I hear this is not always the case. I
figured including NArray might be a reasonable step towards playing
well with others.

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX).

Yeah, me too.

Along this line, I thought it would be handy if code written with
NArray could be shared with others on platforms less inclined to
compile extensions. My preferred platforms seem to always have a
compiler in the path, but I hear this is not always the case. I
figured including NArray might be a reasonable step towards playing
well with others.

However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

A good point. Given the limited responses to this thread, I'll take
it as confirmation of limited appeal.

i personally think this is because no one understands how to use it... once
you do it's quite useful for many programming tasks... google
'multi-dimensional array' and you'll see what i mean. the fact that narray's
give you methods like

   na.shape
   na.rank

alone is a reason to use them instead of some loopy array ctor that hands you
back an array of who knows what dimensionality.

probably help, although I am using a version of narray that I have modified
so it doesn't do me much good.

Another good point. Some of the beauty of NArray is the ease of extending
it, which would again require compilation.

*sigh* Great. Now all I've done is publicly concede to arguments against
including NArray. That's not what I was trying to do... :slight_smile:

I guess I was just envisioning ruby grwoing in appeal for large data
analysis (out of the box). An alternative to IDL or MATLAB with legs to
easily do web services and text munging. If ruby had something like NArray
built in, one can get a good chunk quickly moving before reaching for
external packages. Plus, it'd at least strongly suggest an "approved"
numerical extension to further build on - perhaps consolidating efforts.

my take on it is this - if you are serious about doing numerical analysis you
have a compiler. all the guys in my building that don't even understand what
'object' means and who don't see anything wrong with common blocks - they
still know how to compile. that's because they code in fortran and c. they
understand how to compile to a larger degree than they understand 'data
encapsulation' or 'abstraction'. in summary, anyone running on a box that has
no compiler will be thwarted at every step installing numerical applications -
not only ruby. also, the one-click-installer includes tons of compiled
extensions so i don't see why narray should be any different.

regards.

-a

···

On Wed, 26 Oct 2005, Cameron McBride wrote:

On 10/25/05, Phil Tomson <ptkwt@aracnet.com> wrote:

--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama

===============================================================================

hmmm. what were you doing? sounds interesting. any chance you could post
that on sciruby?

regards.

-a

···

On Wed, 26 Oct 2005, Phil Tomson wrote:

In article <Pine.LNX.4.62.0510251406490.2231@harp.ngdc.noaa.gov>,
Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

On Wed, 26 Oct 2005, Phil Tomson wrote:

In article <dcedf5e20510250919v45bdfdc6iceb8472fc2e56ce2@mail.gmail.com>,
Cameron McBride <cameron.mcbride@gmail.com> wrote:

On a ruby-core thread:

(in reference to RCR 260: Make 'Rational' a built-in class )

On 10/24/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX). However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

I don't recall if narray is available as a gem or not. As I recall the
last time I downloaded it it was not a gem. So gem-ifying narray would
probably help, although I am using a version of narray that I have
modified so it doesn't do me much good.

what did you do? mine suports read/write mmap so an narray can be backed by a
file and any write to the narray writes to the file - very dangerous, not
reccomended, and extremely useful for tweaking a gb grid with minimal io.

I wanted to treat an NArray as an N-dimensional point so that I could find
the distance from one point to another. I added a distance method and a
couple of other geometrically oriented methods in C.

--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama

===============================================================================

a great point, Windows is the primary concern.

Unfortunately, it looks like the one-click installer team is a bit
inundated with inclusion requests.
  http://rubyforge.org/tracker/?atid=718&group_id=167&func=browse

Cameron

···

On 10/26/05, Martin DeMello <martindemello@yahoo.com> wrote:

Actually, the only popular compilerless platform today is Windows, so
getting NArray into the one-click installer would get you a fair way
along.

here you go:

   http://codeforpeople.com/lib/ruby/nmap/

a teaser:

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > cat sample.rb
   require "mmap"
   require "narray"

   class NMap
     %w( path na_type dims bytes_per_pixel size mmap narray ).each do |m|
       attr_accessor m
     end
     alias_method "na", "narray"
     alias_method "na=", "narray="

     def initialize path, na_type, *dims
       self.path = path
       self.na_type = na_type
       self.dims = dims
       self.bytes_per_pixel = NArray::new(na_type, 1).to_s.size
       self.size = dims.inject(1){|s,d| s * d}

···

On Wed, 26 Oct 2005, Cameron McBride wrote:

On 10/25/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

what did you do? mine suports read/write mmap so an narray can be backed by a
file and any write to the narray writes to the file - very dangerous, not
reccomended, and extremely useful for tweaking a gb grid with minimal io.

btw, this sounds like a fun hack. this anywhere public? (yes, I'm ignoring
the "not reccomended" - sometimes the dangerous toys are the most fun...)

     #
     # this is a race condition - atomic creation is required for real code
     #
       unless test ?e, path
         open(path, "w"){|f| f.truncate(size * bytes_per_pixel)}
         map
         narray = 0
       else
         map
       end
     end
     def map
       self.mmap = Mmap::new path, "rw", Mmap::MAP_SHARED
       self.narray = NArray::str mmap.to_str, na_type, *dims
     end
   end

   nmap = NMap::new 'data', NArray::INT, 3, 2

   p nmap.na
   nmap.na = nmap.na + 1

   nmap.mmap.msync
   nmap.mmap.munmap

we run a few times:

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > ruby sample.rb
   NArray(ref).int(3,2):
   [ [ 0, 0, 0 ],
     [ 0, 0, 0 ] ]

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > ruby sample.rb
   NArray(ref).int(3,2):
   [ [ 1, 1, 1 ],
     [ 1, 1, 1 ] ]

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > ruby sample.rb
   NArray(ref).int(3,2):
   [ [ 2, 2, 2 ],
     [ 2, 2, 2 ] ]

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > ruby sample.rb
   NArray(ref).int(3,2):
   [ [ 3, 3, 3 ],
     [ 3, 3, 3 ] ]

note

   - data is backed by a file
   - file is magically changed with no io done explicitly
   - if you changed only one row of a gb grid only a few pages would be
     read/written. example:

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > ls -ltar gb
   -rw-rw-r-- 1 ahoward ahoward 1073741824 Oct 26 11:15 gb

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > time ruby a.rb 1
   NArray(ref).byte(1024,1024,1024):
   [ [ [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... ],
       [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... ],
    ...

   real 0m0.029s
   user 0m0.010s
   sys 0m0.020s

   jib:~/eg/ruby/nmap/narray_mmap/nmap-0.0.0 > time ruby a.rb 42
   NArray(ref).byte(1024,1024,1024):
   [ [ [ 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, ... ],
       [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... ],
    ...

   real 0m0.028s
   user 0m0.020s
   sys 0m0.000s

so, that's about 0.28 seconds to read in a gigabyte sized cube, change one row
of it, and write it back out! not too shabby.

the speed, of course, is a result of the fact that mmap doesn't actually
read/write the entire file. but using narray to get around having to use
loops and pack to write binary data is also a huge speedup. for instance
doing something like

   nmap.na = nmap.na * 2

doubles the entire grid without loops or type conversion (pack).

regards.

-a
--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
anything that contradicts experience and logic should be abandoned.
-- h.h. the 14th dalai lama

===============================================================================

In article <Pine.LNX.4.62.0510251753520.2231@harp.ngdc.noaa.gov>,

In article <Pine.LNX.4.62.0510251406490.2231@harp.ngdc.noaa.gov>,

In article <dcedf5e20510250919v45bdfdc6iceb8472fc2e56ce2@mail.gmail.com>,

On a ruby-core thread:

(in reference to RCR 260: Make 'Rational' a built-in class )

Personally, I'd really like it if it were in the standard lib because then
I wouldn't have to install it on all the different machines I want to use
it on (Currently running simulations on a Linux box, two Solaris boxen,
and OSX). However, I think the real pushback is that the standard ruby
distro is getting rather large and adding something with the limited
appeal of narray may not be such a good idea in the effort to keep Ruby
trim.

I don't recall if narray is available as a gem or not. As I recall the
last time I downloaded it it was not a gem. So gem-ifying narray would
probably help, although I am using a version of narray that I have
modified so it doesn't do me much good.

what did you do? mine suports read/write mmap so an narray can be

backed by a

file and any write to the narray writes to the file - very dangerous, not
reccomended, and extremely useful for tweaking a gb grid with minimal io.

I wanted to treat an NArray as an N-dimensional point so that I could find
the distance from one point to another. I added a distance method and a
couple of other geometrically oriented methods in C.

hmmm. what were you doing? sounds interesting. any chance you could post
that on sciruby?

I'm using a Particle Swarm Optimizer (PSO) that I've written in Ruby to
find minimal-energy (aka: ground state, or most stable) atomic clusters
of silicon. It's for my Masters thesis. I can post something on sciruby
after I'm done which I hope will be in early December. Then give me a
month or two to recover from this ordeal... I figure I can post something
in January or February.

Phil

···

Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

On Wed, 26 Oct 2005, Phil Tomson wrote:

Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

On Wed, 26 Oct 2005, Phil Tomson wrote:

Cameron McBride <cameron.mcbride@gmail.com> wrote:

On 10/24/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

Actually, it turns our that the one-click installer "team" has only *one*
active member... me! I'm trying change that and get some help, but that
hasn't happened yet.

The best thing would be to get NArray packaged as a binary RubyGem (at least
on Windows), this would make it easy for any user to install.

Curt

···

On 10/26/05, Cameron McBride <cameron.mcbride@gmail.com> wrote:

On 10/26/05, Martin DeMello <martindemello@yahoo.com> wrote:

> Actually, the only popular compilerless platform today is Windows, so
> getting NArray into the one-click installer would get you a fair way
> along.

a great point, Windows is the primary concern.

Unfortunately, it looks like the one-click installer team is a bit
inundated with inclusion requests.
http://rubyforge.org/tracker/?atid=718&group_id=167&func=browse

Actually, it turns our that the one-click installer "team" has only *one*
active member... me! I'm trying change that and get some help, but that
hasn't happened yet.

To be clear, I didn't mean that as a dig. It's a great project. Keep
up the good work! (but alas, I'm not volunteering so I should probably
STFU :wink:

The best thing would be to get NArray packaged as a binary RubyGem (at least
on Windows), this would make it easy for any user to install.

fair advice, thanks.

Cameron

···

On 10/26/05, Curt Hibbs <curt.hibbs@gmail.com> wrote:

> Unfortunately, it looks like the one-click installer team is a bit
> inundated with inclusion requests.
> http://rubyforge.org/tracker/?atid=718&group_id=167&func=browse
>

Actually, it turns our that the one-click installer "team" has only *one*
active member... me! I'm trying change that and get some help, but that
hasn't happened yet.

Curt, is it possible/easy to remaster the One Click Installer? The
idea would be sort of like remastering Knoppix CDs. For which there
are Security ones, Game ones etc. And the instructions are pretty easy
to do so you can
create your own flavor. (Install knoppix, apt-get install somestuff,
remaster, burn CD.)

That way, anyone could create a customized One-Click-Installer for
Windows themselves. Last night you sort of touched on this with the
Instant-Rails package.

Ed

···

On 10/26/05, Curt Hibbs <curt.hibbs@gmail.com> wrote:

On 10/26/05, Cameron McBride <cameron.mcbride@gmail.com> wrote:

Curt

Not to worry, I didn't take it as one. I'm just using every excuse I can
find to solicit help.

Curt

···

On 10/26/05, Cameron McBride <cameron.mcbride@gmail.com> wrote:

On 10/26/05, Curt Hibbs <curt.hibbs@gmail.com> wrote:
> Actually, it turns our that the one-click installer "team" has only
*one*
> active member... me! I'm trying change that and get some help, but that
> hasn't happened yet.

To be clear, I didn't mean that as a dig. It's a great project. Keep
up the good work! (but alas, I'm not volunteering so I should probably
STFU :wink:

Yes and no -- depends on how you you wanted to do it.

If you actually wanted to create an installer, then you'd have to check out
the 1ci's source from CVS on RubyForge and build it yourself. Its a bit of a
pain to get set up, but once it is, doing the build is pretty much a breeze.

If you just wanted to resuse the binary and don't care about an installer,
then its pretty easy. The ruby directory tree is self contained, doesn't
require an environment settings, and doesn't care what directory its run
from. The only thing that contains absolute paths are a few *.bat and *.cmd
files in the ruby\bin directory that are convenient shortcuts for running
certain ruby programs. The installer updates these file with the correct
paths, and my Instant Rails manager does the same thing when it detects that
it is running from a new directory.

Curt

···

On 10/26/05, Ed Howland <ed.howland@gmail.com> wrote:

On 10/26/05, Curt Hibbs <curt.hibbs@gmail.com> wrote:
> On 10/26/05, Cameron McBride <cameron.mcbride@gmail.com> wrote:
> > Unfortunately, it looks like the one-click installer team is a bit
> > inundated with inclusion requests.
> > http://rubyforge.org/tracker/?atid=718&group_id=167&func=browse
> >
>
> Actually, it turns our that the one-click installer "team" has only
*one*
> active member... me! I'm trying change that and get some help, but that
> hasn't happened yet.
>

Curt, is it possible/easy to remaster the One Click Installer? The
idea would be sort of like remastering Knoppix CDs. For which there
are Security ones, Game ones etc. And the instructions are pretty easy
to do so you can
create your own flavor. (Install knoppix, apt-get install somestuff,
remaster, burn CD.)

That way, anyone could create a customized One-Click-Installer for
Windows themselves. Last night you sort of touched on this with the
Instant-Rails package.