Giter Club home page Giter Club logo

narray's Introduction

This package is OLD version, maintenance only.

New version is under development -> Ruby/Numo::NArray

Ruby/NArray

NArray Features:

  • Fast and easy calculation for large numerical array.

  • Accepting Elements: 8,16,32 bit integer, single/double float/complex, Ruby Object.

  • Easy extraction/substitution of array subset, using assignment with number, range, array index.

  • Operator: +, -, *, /, %, **, etc.

  • NMath: Mathematics functions.

  • FFTW version 2 or 3 is separately supported.

  • Ruby/PGPLOT: Graphics library interface (separately distributed) X-Y Graph, Histogram, Contour map, Image map, etc.

  • NArray is similar to:

    • Python/NumPy, Perl/PDL, Yorick, IDL
  • NArray is far from completed!

    • Experimental! Specification may be changed.
    • Far from completed.
    • Bugs may be included.
    • No document.

Installation

ruby extconf.rb
make
make install

Tested Platform

  • ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  • gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)

License

This program is free software.
You can distribute/modify this program
under the same terms as Ruby itself.
NO WARRANTY.

Author

Masahiro TANAKA

narray's People

Contributors

david-macmahon avatar geoffyoungs avatar ktns avatar masa16 avatar ohai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

narray's Issues

Equality specification

I think it would be natural and 'Ruby-like' if tests of equality behaves the same for an NArray as for a Ruby Array. Today this seems to be the case for == and equal?, but not for eql?

# Arrays used as demonstration:
Array[1]
=> [1]
NArray[1]
=> NArray.int(1):
[ 1 ]

# Testing == (works as expected):   
Array[1] == Array[1]
=> true
NArray[1] == NArray[1]
=> true

# Testing equal? (works as expected):
Array[1].equal? Array[1]
=> false
NArray[1].equal? NArray[1]
=> false

# Testing eql? (UNEXPECTED RESULT):
Array[1].eql? Array[1]
=> true
NArray[1].eql? NArray[1]
=> false

Would it be possible to change the NArray specification so that comparisons behave as for an ordinary Ruby Array?

need way to link to narray.so

Hi,

I am the main author of the shogun machine learning toolbox (http://www.shogun-toolbox.org) and we have a ruby interface that utilizes narray. Problem is that I would need some kind of interface/library to link with. While I could simply link to narray.so on linux - I cannot link to narray.bundle on osx.

Do you have any ideas what I could do?

Thanks,
Soeren

NArray fail to install on Windows with DevKit

I recently tried to install the NArray gem on Windows XP using the DevKit, which enables you to compile the native gem just like on linux instead of using precompiled windows binaries.

It seems there is an issue with NArray which makes it fail the compilation on windows. The issue, as well as a proposed fix, is discussed in this thread on the ruby forum:
http://www.ruby-forum.com/topic/1357179#new

It seems the problem is with the following code, which if commented out, will make the install succeed on windows:
https://github.com/masa16/narray/blob/master/extconf.rb#L55-66

Would you be interested to have a look at this issue, and try to make the necessary changes so that narray will install on windows as well?

Tested with:
Windows XP 32 bit
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
Rubygems 1.6.2
Latest DevKit version
narray-0.5.9.9.gem

Thanks,
Chris

Limit of 16 dimensions to transpose

I am not sure if this is an issue so please bear with me.

There seems to be a limit in the number of dimensions that the NArray handles. Specifically, when transposing an NArray of more than 16 dimensions (axes, ranks). To replicate this issue:

require 'NArray'

arr = Array.new(16){1}

na_ok = NArray.float(*arr).random!(1.0)
na_ok.transpose(-1,0) # => works ok

# we now do the same but with one axis more
na_fail = NArray.float(1, *arr).random!(1.0)
na_fail.transpose(-1,0) # => Error in `transpose': rank doublebooking (ArgumentError)

I was able to create NArrays of more than 16 dimensions (only limited to memory constraints). But the transpose operation does not allow more than 16.

Make each return an Enumerator object if not given a block to iterate with

It would be useful if NArray provided a standard ruby Enumerator interface. All that would be required is for my_narray.each to return an Enumerator object, like my_array.each does when called without a block.

This would enable use cases such as my_narray.each.each_with_index { ... } or my_narray.each.map { ... } etc.

The follow monkey patch provides this functionality but I'm sure a better solution is possible.

class NArray
  alias_method :native_each, :each

  def each
    return enum_for :each unless block_given?
    native_each { |item| yield item }
  end
end

to_na instance method

After subclassing NArray, I have discovered that NArray is missing a similar feature compared to Ruby's Array where you easily convert back to an Array.

With Array I can do this:

a = Array.new(3)
=> [nil, nil, nil]
a.class
=> Array
a.to_a.class
=> Array

class M < Array
end
=> nil
m = M.new(3)
=> [nil, nil, nil]
m.class
=> M
m.to_a.class
=> Array

I propose we add a to_na instance method to NArray, similar as the to_a instance method for Array. The documentation for Ruby's to_a method says:

Returns self. If called on a subclass of Array, converts the receiver to an Array object.

We can then do:

n = NArray.new(1,3)
=> NArray.byte(3):
[ 0, 0, 0 ]
n.class
=> NArray
n.to_na.class
=> NArray

class C < NArray
end
=> nil
c = C.new(1,3)
=> C.byte(3):
[ 0, 0, 0 ]
c.class
=> C
c.to_na.class
=> NArray

Is this possible?

Strange initialization?

Here's what I try (in an irb console):

ruby-1.9.2-p290 :001 > NArray.int(100,100,100).size
 => 1000000 # OK
ruby-1.9.2-p290 :002 > NArray.int(100,100,100,100).size
 => 100000000 # OK 
ruby-1.9.2-p290 :003 > NArray.int(100,100,100,100,100).size
 => 1410065408 # Seems to be limited to big-int precision
ruby-1.9.2-p290 :004 > NArray.int(100,100,100,100,100,100).size
 => 0 # ???
ruby-1.9.2-p290 :005 > NArray.int(100,100,100,100,100,100,1000).size
 => 0 # Ok, now I assume I can give up ... but ...
ruby-1.9.2-p290 :006 > NArray.int(100,100,100,100,100,100,100).size
 => 276447232 # Works with 7 dimensions, but limits to int precision???
ruby-1.9.2-p290 :007 > NArray.int(100,100,100,100,100,100,100,100).size
NoMemoryError: negative allocation size (or too big)
    from (irb):14:in `int'
    from (irb):14
    from /home/dim/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
ruby-1.9.2-p290 :008 > NArray.int(100,100,100,100,100,100,100,100,100).size
 => 0 

Any idea? Many thanks!

0.6.0.3 is slower than 0.6.0.1

I updated my radio project to use the newer gem and performance went down substantially. Operations that took 0.14-0.16 seconds now take 0.20-0.22 seconds.

You can see this in test/test.rb from the following project:
https://github.com/AE9RB/radio

This is because of the ancestry checking change. I built the latest master with that change backed out and performance was good again.

mul! behaves different to *=

It seems #mul! and #*= behave different when using ranges.
#*= correctly modifies the original array, #mul! does not.

Is this desired? (if yes -- it is not mentioned in the spec here http://narray.rubyforge.org/SPEC.en)

irb(main):017:0> a
=> NArray.float(5):
[ 0.0253152, 0.88346, 0.792297, 0.498892, 0.374336 ]

irb(main):018:0> a[1...3].mul!(-1.0)
=> NArray.float(2):
[ -0.88346, -0.792297 ]

irb(main):019:0> a
=> NArray.float(5):
[ 0.0253152, 0.88346, 0.792297, 0.498892, 0.374336 ]

but

irb(main):020:0> a[1...3] *= (-1.0)
=> NArray.float(2):
[ -0.88346, -0.792297 ]

irb(main):021:0> a
=> NArray.float(5):
[ 0.0253152, -0.88346, -0.792297, 0.498892, 0.374336 ]

narray fail to build in windows with mingw tool

The Makefile generate with current extconf.rb file not able to build in Windows with mingw tool. The following modification will make it build and install in windows with mingw.(tested in Windows 7 64 bit ruby 1.9.2)

@@ -54,7 +54,7 @@

 if /cygwin|mingw/ =~ RUBY_PLATFORM
   if RUBY_VERSION > '1.8.0'
-    $DLDFLAGS << ",--out-implib=libnarray.a"
+    $DLDFLAGS << " -Wl,--out-implib=libnarray.a"
   elsif RUBY_VERSION > '1.8'
     CONFIG["DLDFLAGS"] << ",--out-implib=libnarray.a"
     system("touch libnarray.a")  

Element-wise power and root methods

Hi!

I really like NArray and I use it to do exercises for several courses at University that cover linear algebra.

Could you please introduce methods to do element-wise power and root operations on an NArray.

Eg:
a = NArray.int(5).indgen!
=> [1, 2, 3, 4, 5]

b = a.pow(2)
=> [1, 4, 9, 16, 25]

b.sqrt
=> [1, 2, 3, 4, 5]

with #sqrt accepting a parameter n for the n^th root which defaults to 2.

I currently have extended the NArray class and added methods for this, but advantage over a ruby implementation is surely the higher performance of native C code root/power operations.

Thanks in advance!

Best way to get a column vector?

If I have an NMatrix, and I want to get a column as a vector, what's the best way to do it? The best I can come up with is:

matrix = NMatrix.float(5, 3).indgen
column = matrix[0, true]
column_vector = NVector[*column.to_a.flatten]

What I really want to do is make the column a unit vector, which means I have to do:

norm = Math.sqrt(column_vector * column_vector)
matrix[0, true] = column_vector / norm

This seems like a lot of code to do something simple! With Ruby's Matrix class, I can make all columns unit vectors with:

Matrix.columns matrix.column_vectors.map(&:normalize)

With the gsl gem, it's even nicer:

matrix.each_col(&:normalize!)

Both Ruby's Matrix and the gsl gem return a vector when you slice a column or row from the Matrix. For whatever reason, NArray returns a matrix if you slice a row or column.

Histogram function

I think it would be nice to have a histogram function for NArray.

Let's say you have an NArray of integer values:

a = NArray.to_na([1,1,1,1,2,2,2,2,2,3,3,3,4])

You would like to know the distribution of data in your NArray. Having a histogram function would be useful:

h = a.histogram
=> {1=>4, 2=>5, 3=>3, 4=>1}

Perhaps there are other ideas for how to return the result, but one way would be to return it in a hash with value (bin) as key and occurances (frequency) as value.

Do you think it is a good idea for NArray?

NArray overflow warning

I just wasted a lot of time tracking down a mistake I made: overflowing a byte NArray. Narray overflows without raising any errors - a typical C thing. Can we have an overflow warning? If this impairs performance, perhaps we can invoke some debug pragma?

median(1) returns Numeric instead of NArray

AFAICT median(1) is behaving incorrectly, because it returns a Numeric instead of NArray:

irb(main):001:0> a = NArray[[1,2],[4,5]].to_f
=> NArray.sfloat(2,2): 
[ [ 1.0, 2.0 ], 
  [ 4.0, 5.0 ] ]
irb(main):002:0> a.mean
=> 3.0
irb(main):003:0> a.median
=> 3.0
irb(main):004:0> a.mean 0
=> NArray.sfloat(2): 
[ 1.5, 4.5 ]
irb(main):005:0> a.median 0
=> NArray.sfloat(2): 
[ 1.5, 4.5 ]
irb(main):006:0> a.mean 1
=> NArray.sfloat(2): 
[ 2.5, 3.5 ]
irb(main):007:0> a.median 1
=> 3.0

My work-around is to use rot90.median(0), which returns what I'd expect median(1) to return:

irb(main):008:0> a.rot90.median(0)
=> NArray.sfloat(2): 
[ 2.5, 3.5 ]

Mirror and rotate

Hello

NArray is a wonderful tool in Ruby. However, one thing that I miss with it is a convenient way of rotating or mirroring an array. It might be that I have missed something in the documentation of course, but as far as I can see, there's no (super-easy) way of doing it. I guess I would like to have convenient NArray#rotate and NArray#mirror methods. Then you could do something like this:


Proposed method 1:
NArray#mirror(dim=0)
This would be principal method (it would work just fine on arrays of any dimension).

a = NArray.int(3,3).indgen!
=> NArray.int(3,3):
[ [ 0, 1, 2 ],
  [ 3, 4, 5 ],
  [ 6, 7, 8 ] ]

a.mirror
=> NArray.int(3,3):
[ [ 2, 1, 0 ],
  [ 5, 4, 3 ],
  [ 8, 7, 6 ] ]

a.mirror(1)
=> NArray.int(3,3):
[ [ 6, 7, 8 ],
  [ 3, 4, 5 ],
  [ 0, 1, 2 ] ]

Proposed method 2:
NArray#rotate(steps)
This would be harder to make principal (it's primarily wanted for two dimensional arrays ('images'), and gets more complicated with vectors or multi-dimensional arrays)

a = NArray.int(3,3).indgen!
=> NArray.int(3,3):
[ [ 0, 1, 2 ],
  [ 3, 4, 5 ],
  [ 6, 7, 8 ] ]

a.rotate(1)
=> NArray.int(3,3):
[ [ 6, 3, 0 ],
  [ 7, 4, 1 ],
  [ 8, 5, 2 ] ]

a.rotate(-1)
=> NArray.int(3,3):
[ [ 2, 5, 8 ],
  [ 1, 4, 7 ],
  [ 0, 3, 6 ] ]

NArray.int(3).indgen!.rotate(1)
=> exception?!

NArray.int(3,3,3).indgen!.rotate(1)
=> exception?!

Thanks for your consideration.

Regards,
Chris

narray 0.6.0.8 test fails

With ruby 1.8.7 (2012-10-12 patchlevel 371) [x86_64-linux] I'm getting the following test failure:

..... the next will fail .....
$a.rot90                       
test/testreverse.rb:5:in `px': ./lib/narray_ext.rb:267:in `rot90': must be >= 2 dimensional array (RuntimeError)
    from (eval):1:in `px'
    from test/testreverse.rb:26:in `eval'
    from test/testreverse.rb:5:in `px'
    from test/testreverse.rb:26

** only responds to 2 for NVector

I'm just wondering why this is, and if it might be fixed. Would it be possible to just have NVector pass along any others to NArray, since NArray seems to work?

I've fixed this in my own code with this method:

    def ** r
      if r == 2
        super
      else
        ::NArray.instance_method(:**).bind(self).call(r)
      end
    end

mean/median absolute deviation

Please consider adding functions:
Mean absolute deviation
Median absolute deviation

The scbi_math gem does this as a wrapper around narray.

[0.6.0.5] u_int16_t causing install failure on mingw

usage of u_int16_t in na_random.c:274 in v0.6.0.5 is causing gem build/install failures on Win7 32bit using mingw-w64 gcc 4.7.2

I haven't tried patching narray.h or narray_local.h to test, but in other code I often use the following:

#ifdef _WIN32
#include <stdint.h>
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
#endif

For reference, I see the following in my mingw.org 4.6.2 and mingw-w64 4.7.2 32bit toolchains:

// mingw.org 4.6.2 - include/stdint.h:30
typedef unsigned short  uint16_t;

// mingw-w64 4.7.2 - i686-w64-mingw32/include/stdint.h:38
typedef unsigned short  uint16_t;

Array#to_na

Let's say we have a Ruby Array of numbers that we would like to convert to an NArray:

a = [1, 2, 3, 4, 5]

Currently, it is somewhat cumbersome to convert a Ruby Array to a NArray. It requires many characters to type:

na = NArray.to_na(a)

A possible simplification would be for the NArray library to extend the Array class with an NArray conversion method:

class Array
  def to_na
    NArray.to_na(self)
  end
end

Then, we would have a pleasant way of converting Ruby Array to NArray:

na = a.to_na

Do you think this would be a good idea?

destructive non-bang methods

There is a misconception with the following instance methods:

fill vs fill! and indgen vs indgen!

In current implementation the former ones are just aliases to the latter, which is quite confusing and against not only basic ruby naming conventions but also in contradiction to other NArray methods naming like collect/collect!, newdim/newdim!, newrank/newrank! or flatten/flatten!.

I'd suggest fill and indgen have to either call their non-destructive function versions or be rather completely removed.

Feature request: Delete element/vector/plane/etc

Thanks for the work you do with this very useful Ruby gem!

Recently I came across the need to delete specific rows/columns or planes from my NArrays. I have searched the documentation, but couldnt find a method for this. Please excuse me if I have missed it. I wonder if you think a method like this would be useful for NArray?

Example of what I would like:
self.delete(dim, index_or_indices)

# Delete column 1 from a two-dimensional array:
a = NArray.int(2,3).indgen!
[ [ 0, 1 ],
  [ 2, 3 ],
  [ 4, 5 ] ]
a.delete(0, 1)
[ [ 0 ],
  [ 2 ],
  [ 4 ] ]

# Delete rows 1 and 3 from a two-dimensional array:
b = NArray.int(2,4).indgen!
[ [ 0, 1 ],
  [ 2, 3 ],
  [ 4, 5 ],
  [ 6, 7 ] ]
b.delete(1, [1,3])
[ [ 0, 1 ],
  [ 4, 5 ] ]

# Delete a plane from a three-dimensional array:
c = NArray.int(2,2,3).indgen!
[ [ [ 0, 1 ],
    [ 2, 3 ] ],
  [ [ 4, 5 ],
    [ 6, 7 ] ],
  [ [ 8, 9 ],
    [ 10, 11 ] ] ]
c.delete(2, 2)
[ [ [ 0, 1 ],
    [ 2, 3 ] ],
  [ [ 4, 5 ],
    [ 6, 7 ] ] ]

I am aware that it is possible to extract specific elements/vectors/planes/etc from an NArray, but in some cases it is easier and more desireable to be able to remove specific indices from your array, rather than extract the others.

Best regards,
Chris

Ruby 2.0 compatibility?

Hello

I just tried to install NArray on the newly released Ruby 2.0.0 on Windows (using the DevKit). There seems to be some warnings related to encoding, which I guess is because Ruby 2.0 has switched from ASCII-8BIT to UTF-8 as its default encoding. Note that in spite of the warnings given during install, NArray still seems to work fine after the install. However, for our peace of mind, I guess it would be best to get rid of these warnings. Here is the log:

C:\Ruby200\bin>gem install narray --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed narray-0.6.0.7
Parsing documentation for narray-0.6.0.7
unable to convert "\x90" from ASCII-8BIT to UTF-8 for narray.so, skipping
unable to convert "\xC6" from ASCII-8BIT to UTF-8 for src/libnarray.a, skipping
unable to convert "\x98" from ASCII-8BIT to UTF-8 for src/na_array.o, skipping
unable to convert "\xDE" from ASCII-8BIT to UTF-8 for src/na_func.o, skipping
unable to convert "\x90" from ASCII-8BIT to UTF-8 for src/na_index.o, skipping
unable to convert "\xBC" from ASCII-8BIT to UTF-8 for src/na_linalg.o, skipping
unable to convert "\xE6" from ASCII-8BIT to UTF-8 for src/na_math.o, skipping
unable to convert "\xBA" from ASCII-8BIT to UTF-8 for src/na_op.o, skipping
unable to convert "\xEE" from ASCII-8BIT to UTF-8 for src/na_random.o, skipping
unable to convert "\xB0" from ASCII-8BIT to UTF-8 for src/narray.o, skipping
unable to convert "\x90" from ASCII-8BIT to UTF-8 for src/narray.so, skipping
Installing ri documentation for narray-0.6.0.7
Done installing documentation for narray (2 sec).
1 gem installed

'lib/complex.rb is deprecated' warning

I think this warning comes from narray - at least I only see it with warnings enabled and requiring narray.

maasha@mel:~$ ruby -wr narray -e ''
lib/complex.rb is deprecated

maasha@mel:$ ruby --version
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin11]
maasha@mel:
$ gem --version
1.8.23

maasha@mel:~$ gem list --local | grep narray
narray (0.6.0.7)

"array size is too large" error based on hardcoded limit -- increase for 64-bit platforms?

If I initialize a very large NArray, I get "ArgumentError: array size is too large", example:

> NArray.int(50_000, 50_000)
ArgumentError: array size is too large

From following this down into the code in narray.c, I see this is triggered by a check that the total size is > 2147483647 (i.e., 2**31 - 1), which is the maximum positive value for a 32-bit signed binary integer. Ref: http://en.wikipedia.org/wiki/2147483647

On 64-bit platforms, should this size limit be upped to the 64-bit signed integer limit (2**63 -1) ?

Error installing gem on OS X Mavericks and ruby 2.1.3

$ gem install narray -v '0.6.0.1'
Building native extensions.  This could take a while...
ERROR:  Error installing narray:
    ERROR: Failed to build gem native extension.

    /Users/elsurudo/.rbenv/versions/2.1.3/bin/ruby extconf.rb
checking for stdint.h... yes
checking for u_int8_t... yes
checking for uint8_t... yes
checking for int16_t... yes
checking for int32_t... yes
checking for u_int32_t... yes
checking for uint32_t... yes
creating narray_config.h
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling narray.c
narray.c:185:36: error: no member named 'm_tbl' in 'struct RClass'
    if (v == cNArray || RCLASS(v)->m_tbl == RCLASS(cNArray)->m_tbl)
                        ~~~~~~~~~  ^
narray.c:185:62: error: no member named 'm_tbl' in 'struct RClass'
    if (v == cNArray || RCLASS(v)->m_tbl == RCLASS(cNArray)->m_tbl)
                                            ~~~~~~~~~~~~~~~  ^
2 errors generated.
make: *** [narray.o] Error 1

make failed, exit code 2

Anyone know of a workaround?

Extremely slow NArray element access

Somehow NArray appears extremely slow for me. I'm doing the following bench:

require 'benchmark'
require 'narray'

n = 500_000

x = Array.new(27) { nil }
y = Array.new(3)   { Array.new(3) { Array.new(3) { nil } } }
z = NArray.byte(3, 3, 3)

Benchmark.bm do |a|
  a.report { n.times { x[26] } }
  a.report { n.times { y[2][2][2] } }
  a.report { n.times { z[2, 2, 2] } }
end

And the results are:

ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]:

    user     system      total        real
0.070000   0.000000   0.070000 (  0.073885)
0.110000   0.000000   0.110000 (  0.109633)
0.210000   0.000000   0.210000 (  0.205711)

I was looking forward to the library in order to increase performance of my application, which rely on huge 3d array (200k+ elements), but somehow NArray shows huge performance gap over even Array of Arrays (access to elements of which is the bottleneck of my application), no even mentioning a plain array.

So am I missing something? Could the gem have been compiled incorrectly (while compiling native extensions) on my local machine (although there was no errors during compiling)? I'm using the latest Ubuntu 11.04 with all the updates (just saying).

I tried the benchmark in ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux]. Same situation.

narray 0.6.0.2 fails test suite

Trying to run the test suite with ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux] I get the following failure:

test/ld.rb:1: undefined method `absolute_path' for File:Class (NoMethodError)

This looks like a ruby 1.9 only call, but the gemspec does not indicate that ruby 1.9 is mandatory.

Feature request: Element multiplication

First of all, thanks for your work on this great Ruby gem!

On one of my recent projects, I needed to multiply all the elements of my NArray. I searched the documentation, hoping to find an equivalent to the .sum method, but it seems to me there is none. I think it would be useful to have such a method included in the NArray library. Below I will paste the solution I used, extending the narray class and converting to a ruby array and finally multiplying the elements:

# Multiplies all elements in the array and returns the resulting number:
class NArray
  def multiply
    self.to_a.inject(:*)
  end
end

a = NArray[2,3,7]
a.sum
=> 12
a.multiply
=> 42

Best regards,
Chris

Failure in test/testrandom.rb for narray 0.6.0.0

When trying to run test/testrandom.rb I get a floating point error. This happens with ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]. Please let me know if you need more information.

$ ruby -I lib test/testrandom.rb 
NArray.float(5).random(10) #=> NArray.float(5): 
[ 1.66376, 5.85494, 2.44993, 1.78281, 2.86057 ]

NArray.float(5).random #=> NArray.float(5): 
[ 0.27736, 0.0492679, 0.506406, 0.921329, 0.945954 ]

NArray.int(5).random(10) #=> NArray.int(5): 
[ 3, 1, 5, 5, 0 ]

NArray.int(1000).random(10) #=> NArray.int(1000): 
[ 6, 1, 3, 4, 2, 3, 1, 2, 5, 0, 9, 5, 1, 5, 1, 0, 4, 1, 0, 7, 1, 6, 5, 0, ... ]

a.eq 0  :: n=101
Floating point exception

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.