Following section (2) here:
http://ruby.gfd-dennou.org/tutorial/gokuraku/index-e.html
Trying to run this part of script I have so far:
require 'narray'
ary1 = NArray.sfloat(3,4)
I get the following error:
C:\Users\Abder-Rahman\Desktop>ruby narray.rb
./narray.rb:2: uninitialized constant NArray (NameError)
from narray.rb:1:in `require'
from narray.rb:1
How can this issue be solved?
Thanks.
on 2010-09-02 17:09
on 2010-09-02 17:20
Abder-Rahman Ali wrote: > Following section (2) here: > http://ruby.gfd-dennou.org/tutorial/gokuraku/index-e.html > > Trying to run this part of script I have so far: > > require 'narray' > ary1 = NArray.sfloat(3,4) > > I get the following error: > > > C:\Users\Abder-Rahman\Desktop>ruby narray.rb > ./narray.rb:2: uninitialized constant NArray (NameError) > from narray.rb:1:in `require' > from narray.rb:1 > > How can this issue be solved? (1) Don't call your own script 'narray.rb', because then Ruby will think it has already loaded the narray library. (2) Install the library narray.rb that you want to use. Probably from here: http://narray.rubyforge.org/
on 2010-09-02 17:34
Looks like you need to install the library
# install from source (requires compiler)
gem install narray
# Windows binary (MinGW version; works also with VC6 mswin32)
gem install narray --platform=x86-mingw32
From here http://narray.rubyforge.org/
PRELOAD:
irb(main):001:0> require 'narray'
LoadError: no such file to load -- narray
from (irb):1:in `require'
from (irb):1
INSTALL:
! gem install narray
Password:
Building native extensions. This could take a while...
Successfully installed narray-0.5.9.7
1 gem installed
Installing RDoc documentation for narray-0.5.9.7...
Usage:
irb(main):004:0> require "rubygems"
=> true
irb(main):005:0> require "narray"
=> true
irb(main):006:0> ary1 = NArray.sfloat(3,4)
=> NArray.sfloat(3,4):
[ [ 0.0, 0.0, 0.0 ],
[ 0.0, 0.0, 0.0 ],
[ 0.0, 0.0, 0.0 ],
[ 0.0, 0.0, 0.0 ] ]
irb(main):007:0>
________________________________
From: Abder-Rahman Ali <abder.rahman.ali@gmail.com>
Reply-To: <ruby-talk@ruby-lang.org>
Date: Thu, 2 Sep 2010 10:09:33 -0500
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Subject: uninitialized constant NArray (Name Error)
Following section (2) here:
http://ruby.gfd-dennou.org/tutorial/gokuraku/index-e.html
Trying to run this part of script I have so far:
require 'narray'
ary1 = NArray.sfloat(3,4)
I get the following error:
C:\Users\Abder-Rahman\Desktop>ruby narray.rb
./narray.rb:2: uninitialized constant NArray (NameError)
from narray.rb:1:in `require'
from narray.rb:1
How can this issue be solved?
Thanks.
on 2010-09-02 17:35
Thanks Brian.
I have renamed the .rb file as: nary.rb
When I run the script, I get the following:
C:\Users\Abder-Rahman\Desktop\Research>ruby nary.rb
nary.rb:1:in `require': no such file to load -- narray (LoadError)
from nary.rb:1
Provided that I have installed the "narray" gem using:
gem install narray
And, just a small thing. When you said: "Don't call your own script
'narray.rb', because then Ruby will think it has already loaded the
narray library."
Can you just clarify this point?
Thanks.
on 2010-09-02 17:46
Thanks Savard. That solved the issue. Seems we had to do: gem install narray TWICE?! @Brian, so the name narray.rb can remain as is. Thanks all.
on 2010-09-02 17:54
@Savard. This works if working through irb.
If I put the script in a .rb file "narray.rb", I get the following:
C:\Users\Abder-Rahman\Desktop\Research>ruby narray.rb
./narray.rb:2: uninitialized constant NArray (NameError)
from narray.rb:1:in `require'
from narray.rb:1
Why is that? Why cannot I get it running as throigh irb?
Of I insert
require "rubygems", I get the following:
C:\Users\Abder-Rahman\Desktop\Research>ruby narray.rb
./narray.rb:3: uninitialized constant NArray (NameError)
from
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
from
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from narray.rb:2
on 2010-09-02 19:18
Abder-Rahman Ali wrote: > Thanks Brian. > > I have renamed the .rb file as: nary.rb > > When I run the script, I get the following: > > C:\Users\Abder-Rahman\Desktop\Research>ruby nary.rb > nary.rb:1:in `require': no such file to load -- narray (LoadError) > from nary.rb:1 > > Provided that I have installed the "narray" gem using: > > gem install narray If you're running ruby 1.8.x, you'll need require "rubygems" # << THIS IS MISSING require "narray" > And, just a small thing. When you said: "Don't call your own script > 'narray.rb', because then Ruby will think it has already loaded the > narray library." > > Can you just clarify this point? Ruby keeps tracks of which libraries it has already loaded - actually in a variable called $LOADED_FEATURES - so that if you require the same library a second time, it doesn't get re-loaded. So when you do require 'narray' it will be skipped if narray.rb has already been loaded. Unfortunately, if your script is called narray.rb, and you run it from the command line, then narray.rb *has* already been loaded, so line 1 of your script is skipped. It then continues to line 2, where it tries to use NArray and finds it undefined. If you rename your script to nary.rb, then line 1 tries to find a file called narray.rb, and gives you a different error. You fix it by installing narray.rb somewhere in the library path (e.g. by installing the narray gem, and doing require 'rubygems')
on 2010-09-02 20:47
@Brian. Thanks a lot. You are correct. It runs now without errors, but the remaining case is, how can I display the result (Array) as the one that appeared when running the program using "irb"?
on 2010-09-02 20:50
It displayed the result when I typed the following in the script: p nary1 Thanks.
on 2010-09-06 16:39
Ali, YW! :-) In the end I agree with Brian, you should not call it narry.rb Cheers, j ________________________________ From: Abder-Rahman Ali <abder.rahman.ali@gmail.com> Reply-To: <ruby-talk@ruby-lang.org> Date: Thu, 2 Sep 2010 10:48:50 -0500 To: ruby-talk ML <ruby-talk@ruby-lang.org> Subject: Re: uninitialized constant NArray (Name Error) Thanks Savard. That solved the issue. Seems we had to do: gem install narray TWICE?! @Brian, so the name narray.rb can remain as is. Thanks all.
on 2010-09-06 16:39
Again, I think Brian explained this and quite accurately.
I named my file gonary.rb
contents
require "rubygems"
require "narray"
ary1 = NArray.sfloat(3,4)
puts ary1.inspect
----------------------------
Results
----------------------------
<MANISH.local:jes> [09-03 07:03] 0 503:3 (0.16 Mb) ? ~/dev/noodle
! ruby gonary.rb
NArray.sfloat(3,4):
[ [ 0.0, 0.0, 0.0 ],
[ 0.0, 0.0, 0.0 ],
[ 0.0, 0.0, 0.0 ],
[ 0.0, 0.0, 0.0 ] ]
See??
Cheers mate,
j
________________________________
From: Abder-Rahman Ali <abder.rahman.ali@gmail.com>
Reply-To: <ruby-talk@ruby-lang.org>
Date: Thu, 2 Sep 2010 10:54:30 -0500
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Subject: Re: uninitialized constant NArray (Name Error)
@Savard. This works if working through irb.
If I put the script in a .rb file "narray.rb", I get the following:
C:\Users\Abder-Rahman\Desktop\Research>ruby narray.rb
./narray.rb:2: uninitialized constant NArray (NameError)
from narray.rb:1:in `require'
from narray.rb:1
Why is that? Why cannot I get it running as throigh irb?
Of I insert
require "rubygems", I get the following:
C:\Users\Abder-Rahman\Desktop\Research>ruby narray.rb
./narray.rb:3: uninitialized constant NArray (NameError)
from
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
from
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from narray.rb:2
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.