Git Product home page Git Product logo

numo-narray's Introduction

Numo::NArray

Binder Build Status

GitHub | RubyGems

Numo::NArray is an Numerical N-dimensional Array class for fast processing and easy manipulation of multi-dimensional numerical data, similar to numpy.ndarray. This project is the successor to Ruby/NArray.

Documentation

All documents are primitive.

Related Projects

Installation

Requirement

Ruby ver 2.2 and later.

Ubuntu, Debian, Bash on Windows

apt install -y git ruby gcc ruby-dev rake make
gem install specific_install
gem specific_install https://github.com/ruby-numo/numo-narray.git

Quick start

An example

[1] pry(main)> require "numo/narray"
=> true
[2] pry(main)> a = Numo::DFloat.new(3,5).seq
=> Numo::DFloat#shape=[3,5]
[[0, 1, 2, 3, 4],
 [5, 6, 7, 8, 9],
 [10, 11, 12, 13, 14]]
[3] pry(main)> a.shape
=> [3, 5]
[4] pry(main)> a.ndim
=> 2
[5] pry(main)> a.class
=> Numo::DFloat
[6] pry(main)> a.size
=> 15

For more examples, check out the narray version of 100 numpy exercises.

Development

Build

git clone https://github.com/ruby-numo/numo-narray
cd numo-narray
bundle install
bundle exec rake compile

Run tests

bundle exec rake test

Tips: You may run tests defined in a specified line as:

bundle exec ruby test/bit_test.rb --location 27

numo-narray's People

Contributors

ankane avatar bjfish avatar dsisnero avatar icm7216 avatar kojix2 avatar kou avatar kozo2 avatar masa16 avatar metanest avatar mrkn avatar msp-greg avatar naitoh avatar nicolasleger avatar ohai avatar sonots avatar tamuratak avatar thedayisntgray avatar yoshoku 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numo-narray's Issues

Error SFloat is unknown for NMath

SFloat is unknown for NMath

require 'numo/narray'
include Numo

x = SFloat[3.14]
p NMath.sin(x)
# "Numo::SFloat is unknown for Numo::NMath"

# Numo::SFloat#shape=[1]
# [0.00159255]

math.c
15+ EXTERN VALUE numo_mSFloatMath, numo_mDFloatMath, numo_mDComplexMath;
130+ rb_hash_aset(hCast, numo_cSFloat, numo_mSFloatMath);

GVL release

Method?

  • rb_thread_call_without_gvl() ?

Issues?

  • block access from another thread during operation.

Indexing or slicing narray with narray get somewhere else.

Step to reproduce

require 'numo/narray'
include Numo

a = UInt8[0]
# => Numo::UInt8#shape=[1]
# [0]

b = UInt8[1]
# => Numo::UInt8#shape=[1]
# [1]

a[b]
# => Numo::UInt8(view)#shape=[1]
# [103]

Expected behavior

IndexError: index=1 out of shape[0]=1

random glitches in cast

since 0.9.5 (or possibly earlier?) NArray#cast sometimes causes segfault. i tried to pinpoint the case but couldn't because the exact same ruby code in the exact same situation sometimes segfaults and other times not. the glitch didn't happen when i ran the same code in march 2017 and in ruby 2.4.0.

this may not happen in 2.3.x or earlier (i use ruby 2.4.1 now and version 2.4.x doesn't seem to be officially supported yet) but i couldn't confirm that neither as my ruby application requires 2.4.x. i'm still trying to find if this is actually an issue in numo/narray or it's just my ruby app that is the culprit.

Numo::DFloat#max_index

When I use Numo::DFloat, Numo::Int32 instance max_index method, I found difference.
gem version is 0.9.0.7.

Numo::Int32#max_index return value is correct.
But Numo::DFloat#max_index return value is incorrect.

Numo::Int32

> x = Numo::Int32[[1, 2, 3], [4, 5, 6]]
# => Numo::Int32#shape=[2,3]
# [[1, 2, 3],
#  [4, 5, 6]]
> x.max_index
# => 5
> x.max_index(axis=0)
# => Numo::Int32#shape=[3]
# [3, 4, 5]
> x.max_index(axis=1)
# => Numo::Int32#shape=[2]
# [2, 5]

Numo::DFloat

> x = Numo::DFloat[[1, 2, 3], [4, 5, 6]]
# => Numo::DFloat#shape=[2,3]
# [[1, 2, 3],
#  [4, 5, 6]]
> x.max_index
# => 4
> x.max_index(axis=0)
# => Numo::Int32#shape=[3]
# [0, 1, 2]
> x.max_index(axis=1)
# => Numo::Int32#shape=[2]
# [2, 4]

b[:*,:-,:-] can cause a crush.

require 'numo/narray'
a = Numo::Int32.ones(5,5,3)
b = Numo::Int32.new(5,5).fill(2)
p a * b[:*,:*,:-]

# p b[:*,:-,:-]  # [BUG] Segmentation fault

I do not know the correct behavior of this idiom. But it can cause a crush.

3d narray assignment problem

Hello. Thank you for quick update. I have a strange problem.

require 'numo/narray'

a = Numo::Int32.new(3,3).seq
b = Numo::Int32.ones(3,3)

c = Numo::Int32.zeros(2, *a.shape)
p c.shape
# [2, 3, 3]

c[0, true, true] = a
c[1, true, true] = b
p c
# Numo::Int32#shape=[2,3,3]
# [[[1, 1, 1], 
#   [1, 1, 1], 
#   [1, 1, 1]], 
#   [[0, 0, 0], 
#   [0, 0, 0], 
#   [0, 0, 0]]]

p c[1, true, true]
# Numo::Int32(view)#shape=[3,3]
# [[0, 0, 0], 
#  [0, 0, 0], 
#  [0, 0, 0]]

something wrong?

(Scirubyの皆様いつも迅速な対応ありがとうございます。今後は medfreak.info ではなくこちらに報告します。よろしくおねがいします。)

Can't install via gemspec

If I try building from gemspec, I get an error:

$ gem build narray-devel.gemspec 
Invalid gemspec in [narray-devel.gemspec]: cannot load such file -- narray/devel/version
ERROR:  Error loading gemspec. Aborting.

How do I install? Thanks!

The behavior of NArray#dot is weird

Hi,
the current behavior of NArray#dot seems weird. Given NArray with a vector-like shape, NArray#dot returns a certain result, never raise exception. I think, in case (b) and case (c-2), exception should be raised.

require "numo/narray"
include Numo

x = SFloat[1,2,3]
y = SFloat[1,1,1]
# case (a)
p x.dot(y)  #=> 6.0

x1 = x.reshape(1,3)
y1 = y.reshape(1,3)
# case (b)
p x1.dot(y1)  #=> SFloat[[6, 6, 6]]
p y1.dot(x1)  #=> SFloat[[3, 6, 9]]

z = SFloat[[1,2,3],[4,5,6]]
# case (c-1)
p z.dot(x)  #=> SFloat[14, 32]
# case (c-2)
p z.dot(x1) #=> SFloat[[6, 12, 18],  [15, 30, 45]]

Numpy example.

import numpy as np
print(np.version.version) #=> 1.12.0

x = np.asarray([1.0, 2.0, 3.0])
y = np.asarray([1.0, 1.0, 1.0])
# case (a)
print(x.dot(y)) #=> 6.0

x1 = x.reshape([1,3])
y1 = y.reshape([1,3])
# case (b)
print(x1.dot(y1)) #=> error!
print(y1.dot(x1)) #=> error!

z = np.asarray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
# case (c-1)
print(z.dot(x))  #=> [ 14.  32.]
# case (c-2)
print(z.dot(x1)) #=> error!

Versions.

$ gem2.3 list --local numo-narray

*** LOCAL GEMS ***

numo-narray (0.9.0.4)

$ ruby2.3 -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin13]

$ python2.7 --version
Python 2.7.13

I want to emphasize that I am not saying NArray should behave in the same way as numpy. I don't know much about python and numpy. I am just saying the current behavior of NArray#dot is unreasonable.

Regards.

make failed, exit code 2

the log

root@e37544c4a0e4:~/narray# tail -n 30 /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/numo-narray-0.9.0.1/gem_make.out                                                      
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/uint32.rb > types/uint32.c
compiling types/uint32.c
/bin/mkdir -p types types
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/uint64.rb > types/uint64.c
compiling types/uint64.c
/bin/mkdir -p types types
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/sfloat.rb > types/sfloat.c
compiling types/sfloat.c
/bin/mkdir -p types types
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/dfloat.rb > types/dfloat.c
compiling types/dfloat.c
/bin/mkdir -p types types
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/scomplex.rb > types/scomplex.c
compiling types/scomplex.c
/bin/mkdir -p types types
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/dcomplex.rb > types/dcomplex.c
compiling types/dcomplex.c
/bin/mkdir -p types types
ruby gen/cogen.rb -l gen/dtype.erb.c gen/def/robject.rb > types/robject.c
compiling types/robject.c
In file included from ./numo/types/robject.h:8:0,
                 from gen/dtype.erb.c:61:
./numo/types/robj_macro.h: In function 'f_rms':
./numo/types/robj_macro.h:126:9: error: non-floating-point argument in call to function '__builtin_isnan'
         if (!isnan(x)) {
         ^
Makefile:330: recipe for target 'types/robject.o' failed
make: *** [types/robject.o] Error 1

make failed, exit code 2

how to reploduce this error

  • ubuntu xenial 64bit on docker
apt install -y git ruby gcc ruby-dev rake make
git clone git://github.com/ruby-numo/narray
cd narray
gem build numo-narray.gemspec
gem install numo-narray-0.9.0.1.gem

segmentation fault when empty shape ([]) NArray calls each_with_index.

Hi, Segmentation fault occurs in the following code.

require "numo/narray"
Numo::DFloat.new.seq(1).each_with_index {}

Crash Report

t.rb:2: [BUG] Segmentation fault at 0x00000000000001
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:                    
     * ~/Library/Logs/DiagnosticReports                                     
     * /Library/Logs/DiagnosticReports                                      
   for more details.                                                        
Don't forget to include the above Crash Report log file in bug reports.     

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0010 e:000009 CFUNC  :each_with_index
c:0002 p:0031 s:0006 e:000005 EVAL   t.rb:2 [FINISH]
c:0001 p:0000 s:0003 E:0015b0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
t.rb:2:in `<main>'
t.rb:2:in `each_with_index'

-- Machine register context ------------------------------------------------
 rax: 0x98a7b29f54e80039 rbx: 0x00007fff525e9358 rcx: 0x0000000022220021
 rdx: 0x000000010d916068 rdi: 0x000000010d916068 rsi: 0x000000010d916068
 rbp: 0x00007fff525e8fb0 rsp: 0x00007fff525e8f60  r8: 0x00007fbb160b3c80
  r9: 0x000000010da15f70 r10: 0x0000000000000000 r11: 0x0000000000000000
 r12: 0x00007fff525e8f60 r13: 0x0000000000000000 r14: 0x0000000000000000
 r15: 0x00007fff525e91b0 rip: 0x0000000000000001 rfl: 0x0000000000010246

-- C level backtrace information -------------------------------------------
 Killed: 9

Versions of ruby and numo::narray are

$ gem list --local numo-narray
 
*** LOCAL GEMS ***

numo-narray (0.9.0.9)

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

Regards.

The name of a method corresponding to numpy.maximum

Numpy has confusing two functions: numpy.max and numpy.maximum.
Numo::NArray#max() method is same as numpy.max.
Now I need to define the specification of a method corresponding to numpy.maximum.
Current ideas:

Numo::NArray.max(a,b,...)
Numo::Nanika.max(a,b,...) # Nanika is a module with an appropriate name.
Numo.max(a,b,...)
a.max(b)

How can I convert CvMat to Narray?

Hi, I want to convert CvMat to Narray like Numpy np.asarray(image).
I checked TODO.md and I know there isn't asarray function.
Is there any alternative to convert CvMat to Narray object?

Possible inplace bug

I presume inplace dosen't set the inplace flag while inplace! does, but they seem to work just like the same;

na=Numo::DFloat.new(10).seq
na.inplace
na.inplace?
=> true

I'm not sure if this behaviour is intended, but if so the difference between inplace and inplace! is unclear.

Sparse matrix

Hi, I tried to create a 300k * 300k matrix to find that sparse matrix is not supported in NArray.

Is there a plan to implement ?

The result of subtraction near 0 is different by Numo::SFloat and DFloat.

When I use Numo::SFloat and DFloat, I found difference.
Ruby 2.4.1
gem version is 0.9.1.0.

expect case

> requre 'numo/narray'
> x = Numo::DFloat[[-1000, 1]]
=> Numo::DFloat#shape=[1,2]
[[-1000, 1]]
> log_z = Numo::NMath.log(Numo::NMath.exp(x).sum(axis:1, keepdims:true))
=> Numo::DFloat#shape=[1,1]
[[1]]
> x - log_z
=> Numo::DFloat#shape=[1,2]
[[-1001, 0]]

expect case

> Numo::DFloat[[1]]
=> Numo::DFloat#shape=[1,1]
[[1]]
> x - Numo::DFloat[[1]]
=> Numo::DFloat#shape=[1,2]
[[-1001, 0]]

not expect case

> x = Numo::SFloat[[-1000, 1]]
=> Numo::SFloat#shape=[1,2]
[[-1000, 1]]
> log_z = Numo::NMath.log(Numo::NMath.exp(x).sum(axis:1, keepdims:true))
=> Numo::SFloat#shape=[1,1]
[[1]]
> x - log_z
=> Numo::SFloat#shape=[1,2]
[[-1001, 5.96046e-08]]

I expect the return value to be [[-1001, 0]].
Why return [[-1001, 5.96046e-08]]?

expect case

> Numo::SFloat[[1]]
=> Numo::SFloat#shape=[1,1]
[[1]]
> x - Numo::SFloat[[1]]
=> Numo::SFloat#shape=[1,2]
[[-1001, 0]]

Regards.

Saving NArray easily

I request some means to save Numo::NArray to a binary file.
Like

numpy.save
numpy.savez
numpy.load

(or Marshal.dump?)

gem install fails

as of 10 Apr 2017 gem install fails under ruby2.4.0 with the following error;

sudo gem specific_install https://github.com/ruby-numo/narray.git
/usr/bin/git
git installing from https://github.com/ruby-numo/narray.git
Cloning into '/tmp/d20170410-9697-8cwo6p'...
remote: Counting objects: 4587, done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 4587 (delta 47), reused 0 (delta 0), pack-reused 4481
Receiving objects: 100% (4587/4587), 1.86 MiB | 2.43 MiB/s, done.
Resolving deltas: 100% (2881/2881), done.
Checking connectivity... done.
WARNING:  ext/numo/narray/gen/tmpl_bit/extract_data.c is a symlink, which is not supported on all platforms
WARNING:  See http://guides.rubygems.org/specification-reference/ for help
  Successfully built RubyGem
  Name: numo-narray
  Version: 0.9.0.4
  File: numo-narray-0.9.0.4.gem
Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Ext::BuildError)
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.4.0/gems/numo-narray-0.9.0.4/ext/numo/narray
/usr/bin/ruby2.4 -r ./siteconf20170410-9697-16gbdmq.rb extconf.rb
checking for stdbool.h... yes
checking for stdint.h... yes
checking for bool in stdbool.h... yes
checking for u_int8_t in stdint.h... yes
checking for u_int16_t in stdint.h... yes
checking for int32_t in stdint.h... yes
checking for u_int32_t in stdint.h... yes
checking for int64_t in stdint.h... yes
checking for u_int64_t in stdint.h... yes
checking for exp10()... yes
checking for rb_cComplex... yes
creating numo/extconf.h
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/lib/gems/2.4.0/extensions/x86_64-linux/2.4.0/numo-narray-0.9.0.4/mkmf.log

current directory: /var/lib/gems/2.4.0/gems/numo-narray-0.9.0.4/ext/numo/narray
make "DESTDIR=" clean

current directory: /var/lib/gems/2.4.0/gems/numo-narray-0.9.0.4/ext/numo/narray
make "DESTDIR="
compiling narray.c
compiling array.c
compiling step.c
compiling index.c
compiling ndloop.c
compiling data.c
make: *** No rule to make target '/var/lib/gems/2.4.0/gems/numo-narray-0.9.0.4/ext/numo/narray/gen/tmpl_bit/extract_data.c', needed by 'types/bit.c'.  Stop.

make failed, exit code 2

Gem files will remain installed in /var/lib/gems/2.4.0/gems/numo-narray-0.9.0.4 for inspection.
Results logged to /var/lib/gems/2.4.0/extensions/x86_64-linux/2.4.0/numo-narray-0.9.0.4/gem_make.out

All Values Converge To "Nan"

OS: Ubuntu 17.10 x86_64
**ruby -v : ruby 2.3.3p222 **
Hi
For Some Reason, after some iterations of 'train' all my weight Values are equal to "-Nan"

require "numo/narray"

class NeuralNetwork

  def initialize(inputNodes:0,hiddenNodes:[],outputNodes:0,learningRate: 0.01)
    @nInputs = inputNodes
    @nHidden = hiddenNodes
    @nHiddenLayers = hiddenNodes.length
    @nOutputs = outputNodes
    @learningRate = learningRate
    @hiddenWeights = []
    @hiddenBias = []
    tmp1,tmp2 = @nInputs,@nHidden[0]
    @hiddenWeights[0] = Numo::Float32.new(tmp2,tmp1).rand(-1,1)
    @hiddenBias[0] = Numo::Float32.new(tmp2,1).rand(-1,1)

    for i in (1...@nHiddenLayers)
      tmp1,tmp2 = @nHidden[i-1],@nHidden[i]
      @hiddenWeights[i] = Numo::Float32.new(tmp2,tmp1).rand(-1,1)
      @hiddenBias[i] = Numo::Float32.new(tmp2,1).rand(-1,1)
    end

    @outputWeights = Numo::Float32.new(@nOutputs,@nHidden[@nHiddenLayers-1]).rand(-1,1)
    @outputBias =  Numo::Float32.new(@nOutputs,1).rand(-1,1)

  end

  def train!(data,labels)
    data = data.map{|d| Numo::Float32.cast([d]).transpose}
    data.each.with_index do |x,ind|
      layers_inputs = [x]
      #feed forward
      for i in(0...@nHiddenLayers)
        x1 = relu(@hiddenWeights[i].dot(layers_inputs[-1])+@hiddenBias[i])
        layers_inputs.push(x1)
      end
      output = softmax(@outputWeights.dot(layers_inputs[-1])+@outputBias)

      #backpropagation
      diff = output.clone
      diff[labels[ind]]-= 1
      outdelta = softmax_prime(output).dot(diff) * @learningRate
      @outputBias = @outputBias - outdelta
      @outputWeights = @outputBias - outdelta.dot(layers_inputs[-1].transpose)
      delta = @outputWeights.transpose.dot(outdelta)
      (@nHiddenLayers-1).downto(0) do |i|
        delta = delta*relu_prime(layers_inputs[i+1])
        @hiddenWeights[i] = @hiddenWeights[i] - delta.dot(layers_inputs[i].transpose)
        @hiddenBias[i] = @hiddenBias[i] - delta
        delta = @hiddenWeights[i].transpose.dot(delta)
      end
    end
  end

  def test(data)
    data = data.map{|d| Numo::Float32.cast([d]).transpose}
    out = []
    data.each do |x|
      layers_inputs = [x]
      #feed forward
      for i in(0...@nHiddenLayers)
        x1 = relu(@hiddenWeights[i].dot(layers_inputs[-1])+@hiddenBias[i])
        layers_inputs.push(x1)
      end
      out.push(softmax(@outputWeights.dot(layers_inputs[-1])+@outputBias))
    end
    return out.map{|e| e.max_index}
  end

  private
  def relu(x)
    return (x > 0).cast_to(Numo::Float32) * x
  end

  def relu_prime(x)
    return (x > 0).cast_to(Numo::Float32)
  end

  def softmax(x)
    v = Numo::NMath.exp(x)
    return (v*(v.sum**-1))
  end

  def softmax_prime(y)
    return y.flatten.diag - y.dot(y.transpose)
  end

  def toOneHot(x)
    a = Numo::Float32.zeros(@nOutputs,1)
    a[x] = 1
    return a
  end
  def sigmoid(x)
    return (1+Numo::NMath.exp(-x))**-1
  end

  def sigmoid_prime(y)
    return y*(1-y)
  end
end
 

Project web contents which needs update

以下の場所にあるリンクが、古いリンクになっています。

RObject issues

  1. the code that follows gives a result:
ary=[nil,nil]
Numo::RObject.cast(ary)
=> Numo::RObject#shape=[2]
[0, 0]

where i exepect [,] or [nil,nil].

  1. RObject#[]= raises exception when you give range/array argument:
na=Numo::RObject.new(5).fill(0)
na[0..-1]=1
Numo::NArray::CastError: unknown conversion from Numo::RObject to Numo::RObject

`inplace` flag for Numo::GSL::Sf functions.

inplace flag doesn't seem to work with functions defined in Numo::GSL::Sf.

na = Numo::DFloat.new(3).fill 100
Numo::GSL::Sf.log_abs na.inplace
p na # => [100.0, 100.0, 100.0]

Numo::RObject fails by CastError.

  • numo/narray: 0.9.0.3
  • ruby: 2.3.2
require 'numo/narray'
Numo::RObject.new(3).store [:a, :b, :c]
# => Numo::NArray::CastError: unknown conversion from Numo::RObject to Numo::RObject

Some gem build warnings

$> gem build numo-narray.gemspec
WARNING: open-ended dependency on rake-compiler (>= 1.0.1, development) is not recommended
if rake-compiler is semantically versioned, use:
add_development_dependency 'rake-compiler', '> 1.0', '>= 1.0.1'
WARNING: open-ended dependency on rake-compiler-dock (>= 0, development) is not recommended
if rake-compiler-dock is semantically versioned, use:
add_development_dependency 'rake-compiler-dock', '
> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: numo-narray
Version: 0.9.0.3
File: numo-narray-0.9.0.3.gem

Numo::DFloat#nearly_eq

When I use Numo::DFloat instance nearly_eq method, I found difference.
Ruby 2.3.0/2.4.1
gem version is 0.9.0.9.

expect case

> x = Numo::NArray[[[ -0.36133200184253111420, -0.26743056922401642339 , -0.15902724402321133379],
                    [ -1.19318994409269407697, -1.44963239638332885839, -1.91713985336221814926]],
                   [[ -0.64073243053171402561, -1.16473945661181144118, -0.71543932177509761416],
                    [ -0.74846194046881686646, -0.37397217072783262015, -0.67134116188410564163]]]
> y = Numo::NArray[[[ -0.36133200184253122522, -0.26743056922401642339, -0.15902724402321133379],
                    [ -1.19318994409269407697, -1.44963239638332885839, -1.91713985336221814926]],
                   [[ -0.64073243053171424766, -1.16473945661181144118, -0.71543932177509761416],
                    [ -0.74846194046881708850, -0.37397217072783262015, -0.67134116188410564163]]]
> p x - y
Numo::DFloat#shape=[2,2,3]
[[[1.11022e-16, 0, 0], 
  [0, 0, 0]], 
 [[2.22045e-16, 0, 0], 
  [2.22045e-16, 0, 0]]]
> p x.nearly_eq(y)
Numo::Bit#shape=[2,2,3]
 [[[1, 1, 1], 
   [1, 1, 1]], 
  [[1, 1, 1], 
   [1, 1, 1]]]

not expect case

> x = Numo::NArray[[[ -1.40903182174134045113, -0.35526599480177556423, -1.70191687578730643793],
                    [ -0.28021637271697175109, -1.20726809289862258012, -0.20130094472294335350]],
                   [[ -1.06148519722576439861, -1.51812278479952222909, -0.82032336416972229109],
                    [ -0.42455869150749364627, -0.24733742939520531046, -0.58033516033345322604]]]
> y = Numo::NArray[[[ -1.40903182174134067317, -0.35526599480177545320, -1.70191687578730643793],
                    [ -0.28021637271697186211, -1.20726809289862258012, -0.20130094472294324248]],
                   [[ -1.06148519722576439861, -1.51812278479952267318, -0.82032336416972218007],
                    [ -0.42455869150749375729, -0.24733742939520553250, -0.58033516033345311502]]]
> p x - y
Numo::DFloat#shape=[2,2,3]
[[[2.22045e-16, -1.11022e-16, 0], 
  [1.11022e-16, 0, -1.11022e-16]], 
 [[0, 4.44089e-16, -1.11022e-16], 
  [1.11022e-16, 2.22045e-16, -1.11022e-16]]]
> p x.nearly_eq(y)
Numo::Bit#shape=[2,2,3]
[[[1, 1, 1], 
  [1, 1, 1]], 
 [[1, 1, 1], 
  [1, 0, 1]]]

I expect all 1.

> x = Numo::DFloat[ -0.24733742939520531046]
> y = Numo::DFloat[ -0.24733742939520553250]
> p x - y
Numo::DFloat#shape=[1]
[2.22045e-16]
> p x.nearly_eq(y)
Numo::Bit#shape=[1]
[0]

Why return [0]?

Method name corresponding to numpy.zeros_like

Numo::NArray needs to have a method corresponding to:

numpy.zeros_like(a)

In Ruby, the standard way is

a.zeros_like

This is wrong order if we regard this as an English phrase.
Currently the name of this method is new_zeros but it seems not good name.
Any idea?

Interfacing with FFI. Pointer access.

Dear NArray developers,

I am the developer of opencl_ruby_ffi, OpenCL bindings for ruby.
In order to interface the previous version of NArray with FFI based library I have hacked a small gem:
narray_ffi.

It mainly adds a to_ptr method to instances of NArray. This method returns an instance of FFI::Pointer with the address set as the NArray ptr field.

This allows to directly copy NArray content to GPU memory and from GPU memory to NArray.

The reciprocal functionality is also implemented as to_na and to_narray are enriched to create a NArray from a FFI::Pointer rather than a String. The ref field of the NArray struct is used to store the Pointer and mark it for garbage collection.

This allows to map arbitrary memory inside an NArray and then access this memory content from ruby.

Using this mechanisms I can allocate memory using a MemoryPointer and get an aligned slice to use for mapping on the GPU and still access it in ruby land using NArray.

Today one of my users asked if I could support the new version of NArray. While I could again hack a gem that provides those functionalities I thought that as this version of NArray is maintained and could change in the future maybe it was better to discuss the issue with you first.

Adding a dependency on FFI inside the main gem doesn't seem appealing to me, but maybe you would be interested in having a Numo gem that interfaces the new NArray with FFI. It could certainly be better implemented than my first gem if some support from the main NArray gem is provided. It could also mean easy usage of your NArray package with external C or FORTRAN scientific libraries using FFI for bindings.

Sorry for the huge post.

Best regards,

Brice Videau

"undefined symbol: rb_get_kwargs" crash for ruby 2.1 and numo-narray >= 0.9.0.5

Is ruby 2.1 still supported?

Crash on ruby 2.1 with numo-narray version >= 0.9.0.5

Using docker with ruby 2.1

FROM debian:jessie

RUN apt-get update \
 && apt-get install -y ruby ruby-dev make gcc \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

RUN gem install numo-narray

Simple code example

ruby -v
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

irb
require 'numo/narray'
=> true

Numo::NArray::VERSION
=> "0.9.0.8"

a = Numo::DFloat[1, 2, 3]
=> Numo::DFloat#shape=[3]
[1, 2, 3]

a.sum

Crashes with the following message

irb: symbol lookup error: /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/numo-narray-0.9.0.8/numo/narray.so: undefined symbol: rb_get_kwargs

Works fine on ruby 2.1 with numo-narray version=0.9.0.4

Using docker with ruby 2.1

FROM debian:jessie

RUN apt-get update \
 && apt-get install -y ruby ruby-dev make gcc \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

RUN gem install numo-narray --version=0.9.0.4

Same code example

ruby -v
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

irb
require 'numo/narray'
=> true

Numo::NArray::VERSION
=> "0.9.0.4"

a = Numo::DFloat[1, 2, 3]
=> Numo::DFloat#shape=[3]
[1, 2, 3]

a.sum
=> 6.0

Works fine on ruby 2.3 with latest numo-narray version

Using docker with ruby 2.3

FROM debian:stretch

RUN apt-get update \
 && apt-get install -y ruby ruby-dev make gcc \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

RUN gem install numo-narray

Same code example

ruby -v
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]

irb
require 'numo/narray'
=> true

Numo::NArray::VERSION
=> "0.9.0.8"

a = Numo::DFloat[1, 2, 3]
=> Numo::DFloat#shape=[3]
[1, 2, 3]

a.sum
=> 6.0

weird result and segmentation fault when using Numo::Bit as an argument

weird result when giving as an argument Numo::Bit with all elments set to 0 to Numo::NArray.

example:
nar1=Numo::Int64[1,2,3,4,5]
nar2=Numo::Bit.zeros(5)
p nar1[nar2]
=> Numo::Int64(view)#shape=[0][]

besides, the following code causes segfault (or ruby stalls);
p nar1[nar2].min

confirmed in Ruby 2.4.0 & linux mint 18.1 64bit

mean method for int types

Hello. I realize that the mean method can not be used in int types.

require 'numo/narray'
a = Numo::Int32.new(10).seq
puts a.mean
# undefined method `mean' for "Numo::Int32

Although it may be trivial, I feel this is a little inconvenient.
I would be happy if I could use mean method with int types.
As in the numpy example below.

import numpy as np

a = np.arange(10, dtype=np.int32)
print(a.mean())
# 4.5

where2 can cause a crash.

require 'numo/narray'
a = Numo::SFloat.zeros(2,2,2,2,2)
a[1,1,1,1,1] = 1
b = a.ne(0)
b.where2
#*** Error in `ruby': free(): invalid next size (fast): 0x00007f67671fe8d0 ***

I do not know the expected behavior of this idiom.
But it can cause a crush on my local machine.

require 'numo/narray'
a = Numo::SFloat.zeros(2,2,2,2)
a[1,1,1,1] = 1
b = a.ne(0)
b.where
# Numo::Int32#shape=[1]
# [15]
b.where2
#*** Error in `ruby': free(): invalid next size (fast): 0x00007f29e412ffa0 ***

↑sometimes work and at other times not work.

Ubuntu 14.04 ruby 2.3.1p112

segmentation fault when nil value NArray calls cast / NMath calls exp.

Hi, Segmentation fault occurs in the following code.

require 'numo/narray'
Numo::NArray.cast(nil)

or

require 'numo/narray'
Numo::NMath.exp(nil)

Crash Report with Numo::NArray.cast(nil)

/Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray/extra.rb:159: [BUG] invalid type for md-array: NilClass
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:                    
     * ~/Library/Logs/DiagnosticReports                                     
     * /Library/Logs/DiagnosticReports                                      
   for more details.                                                        
Don't forget to include the above Crash Report log file in bug reports.     

-- Control frame information -----------------------------------------------
c:0004 p:---- s:0016 e:000015 CFUNC  :array_type
c:0003 p:0034 s:0011 e:000010 METHOD /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray/extra.rb:159
c:0002 p:0024 s:0006 e:000005 EVAL   test10.rb:2 [FINISH]
c:0001 p:0000 s:0003 E:001ef0 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
test10.rb:2:in `<main>'
/Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray/extra.rb:159:in `cast'
/Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray/extra.rb:159:in `array_type'

-- C level backtrace information -------------------------------------------
0   ruby                                0x000000010dfd34f4 rb_vm_bugreport + 132
1   ruby                                0x000000010de725d6 rb_bug + 470
2   narray.bundle                       0x000000010e25641a na_composition3 + 954
3   narray.bundle                       0x000000010e2566c3 na_s_array_type + 35
4   ruby                                0x000000010dfc7530 vm_call_cfunc + 272
5   ruby                                0x000000010dfb1fa0 vm_exec_core + 11456
6   ruby                                0x000000010dfc22d4 vm_exec + 116
7   ruby                                0x000000010de7b5f8 ruby_exec_internal + 136
8   ruby                                0x000000010de7b516 ruby_run_node + 54
9   ruby                                0x000000010de0e2ff main + 79

-- Other runtime information -----------------------------------------------

* Loaded script: test10.rb

* Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/x86_64-darwin16/enc/encdb.bundle
    5 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/x86_64-darwin16/enc/trans/transdb.bundle
    6 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/unicode_normalize.rb
    7 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/x86_64-darwin16/rbconfig.rb
    8 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/compatibility.rb
    9 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/defaults.rb
   10 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/deprecate.rb
   11 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/errors.rb
   12 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/version.rb
   13 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/requirement.rb
   14 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/platform.rb
   15 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/basic_specification.rb
   16 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/stub_specification.rb
   17 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/util/list.rb
   18 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/x86_64-darwin16/stringio.bundle
   19 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/specification.rb
   20 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/exceptions.rb
   21 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/dependency.rb
   22 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_gem.rb
   23 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/monitor.rb
   24 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb
   25 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems.rb
   26 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/path_support.rb
   27 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/version.rb
   28 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/core_ext/name_error.rb
   29 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/levenshtein.rb
   30 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/jaro_winkler.rb
   31 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/spell_checker.rb
   32 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/2.4.0/delegate.rb
   33 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
   34 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
   35 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/spell_checkers/name_error_checkers.rb
   36 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/spell_checkers/method_name_checker.rb
   37 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/spell_checkers/null_checker.rb
   38 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean/formatter.rb
   39 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/did_you_mean-1.1.0/lib/did_you_mean.rb
   40 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray.bundle
   41 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray/extra.rb
   42 /Users/naitoh/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/numo-narray-0.9.1.0/lib/numo/narray.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

[IMPORTANT]
Don't forget to include the Crash Report log file under
DiagnosticReports directory in bug reports.

Abort trap: 6

Regards.

About the behavior of the sum method (not the sum()) of Numo::NArray)

It is the environment of Mac OS Sierra.

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

$ gem list numo-narray
*** LOCAL GEMS ***
numo-narray (0.9.0.6)

$ irb
irb(main):001:0> require 'numo/narray'
=> true
irb(main):002:0> Numo::NArray[1, 1].sum()
=> 2
irb(main):003:0> Numo::NArray[1, 1].sum() - 1
=> 1
irb(main):004:0> Numo::NArray[1, 1].sum() -1
=> 1
irb(main):005:0> Numo::NArray[1, 1].sum() + 1
=> 3
irb(main):006:0> Numo::NArray[1, 1].sum() +1
=> 3
irb(main):007:0> Numo::NArray[1, 1].sum - 1
=> 1

This is the result as expected.

irb(main):008:0> Numo::NArray[1, 1].sum -1
=> 2

I expect 1 here.

irb(main):009:0> Numo::NArray[1, 1].sum + 1
=> 3
irb(main):010:0> Numo::NArray[1, 1].sum +1
Numo::NArray::DimensionError: dimension is out of range
	from (irb):10:in `sum'
	from (irb):10
	from /Users/naitoh/.rbenv/versions/2.4.1/bin/irb:11:in `<main>'

Is this behavior specification or bug?

int2binary does not return array

From narray exercise

Bit conversion does not return an array unlike in numpy

Python:
# Author: Daniel T. McDonald

I = np.array([0, 1, 2, 3, 15, 16, 32, 64, 128], dtype=np.uint8)
bin = np.unpackbits(I[:, np.newaxis], axis=1)

print bin[0] returns
array([0, 0, 0, 0, 0, 0, 0, 0], dtype=uint8)

Ruby:

i = Numo::UInt8[0, 1, 2, 3, 15, 16, 32, 64, 128]
bin = Numo::Bit.from_binary(i.to_binary,[i.size,8]).reverse(1)

print bin[0] returns
0
It should be an array and not just an element at a particular index.

Integration/synergies with SciRuby

Hi all,

Nice to see that NArray is finally being developed again. However, it concerns me that a lot of the development here mirrors the development at SciRuby (http://sciruby.com/), and so users will need to make the choice between two different scientific ruby frameworks. Have you considered aiming for compatibility/integration with SciRuby?

Thanks,

Edmund

"sort_index" does not work for narrays with one element.

Thank you so much for your quick response.
I'm sorry to trouble you, but I must report another bug today.

Step to reproduce.

require 'numo/narray'
a = Numo::UInt8[1]
a.sort_index
# 浮動小数点例外(floating point exception)

Expected behavior

=> Numo::Int32#shape=[1]
[0]

segmentation fault when empty NArray calls flatten.

Hi,
Segmentation fault occurs in the following code.

require "numo/narray"
Numo::SFloat[].flatten

Crash Report

$ ruby2.3 t.rb
t.rb:3: [BUG] na_flaten_dim: start_dim (0) out of range
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin13]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/CrashReporter
     * /Library/Logs/CrashReporter
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0007 e:000006 CFUNC  :flatten
c:0002 p:0026 s:0004 E:000d40 EVAL   t.rb:3 [FINISH]
c:0001 p:0000 s:0002 E:000370 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
t.rb:3:in `<main>'
t.rb:3:in `flatten'

-- C level backtrace information -------------------------------------------
0   libruby.2.3.0.dylib                 0x0000000106cfedca rb_print_backtrace + 29
1   libruby.2.3.0.dylib                 0x0000000106cfefa5 rb_vm_bugreport + 368
2   libruby.2.3.0.dylib                 0x0000000106be26ce rb_bug + 207
3   narray.bundle                       0x0000000106f65d96 na_flatten + 0
4   libruby.2.3.0.dylib                 0x0000000106cfd16c vm_call_cfunc + 345
5   libruby.2.3.0.dylib                 0x0000000106cfc82a vm_call_method_each_type + 104
6   libruby.2.3.0.dylib                 0x0000000106cfe198 vm_call_general + 240
7   libruby.2.3.0.dylib                 0x0000000106ce6d87 vm_exec_core + 9368
8   libruby.2.3.0.dylib                 0x0000000106cf2a68 vm_exec + 122
9   libruby.2.3.0.dylib                 0x0000000106be7772 ruby_exec_internal + 148
10  libruby.2.3.0.dylib                 0x0000000106be76af ruby_run_node + 78
11  ruby2.3                             0x0000000106babf26 main + 79

Versions of ruby and numo::narray are

$ gem2.3 list --local numo-narray

*** LOCAL GEMS ***

numo-narray (0.9.0.4)
$ ruby2.3 -v  
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin13]

Regards.

more RObject issues

thanks for your recent fixes to RObject issues. unfortunately other issues arise (perhaps previous fixes were not enough?)

  1. the following assignment raises exception
na=Numo::RObject.new(3).fill("a")
na[0..-1]="b"
=>Numo::NArray::CastError: unknown conversion from NilClass to Numo::RObject

this happens no matter what type of values you try to put, only exception being Numeric

  1. Numo::RObject#eq (or ne) raises exception
na=Numo::RObject.new(3).fill("a")
na.eq "a"
=>NoMethodError: undefined method `cast' for nil:NilClass
na.eq :a
=>NoMethodError: undefined method `cast' for nil:NilClass

na2=Numo::RObject.new(3).fill(0)
na2.eq 0
=>NoMethodError: undefined method `eq' for 0:Integer

Error in Matrix multiplication

Hello, I tried to multiply two matrices, transposed matrix and original matrix to find that it causes a SEGV.

I paste my executing result bellow.

[10] pry(main)> require 'numo/narray'
=> true
[11] pry(main)> require 'numo/linalg'
=> true
[12] pry(main)> mat = Numo::Float64.new(10, 10).rand
=> Numo::DFloat#shape=[10,10]
[[0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032, 0.539948, ...],
 [0.108065, 0.0687079, 0.904121, 0.478644, 0.342969, 0.164541, 0.74603, ...],
 [0.869421, 0.0854984, 0.688965, 0.159977, 0.279215, 0.625155, 0.676329, ...],
 [0.369764, 0.288783, 0.9145, 0.82901, 0.095754, 0.000766433, 0.172175, ...],
 [0.27822, 0.281593, 0.911101, 0.419566, 0.472129, 0.481009, 0.801525, ...],
 [0.654895, 0.198015, 0.860828, 0.171934, 0.360198, 0.151675, 0.490398, ...],
 [0.469158, 0.01212, 0.343877, 0.462687, 0.24158, 0.159517, 0.667622, ...],
 [0.304461, 0.71522, 0.817172, 0.881758, 0.299291, 0.226071, 0.00270188, ...],
 [0.484259, 0.421706, 0.951618, 0.0557716, 0.981335, 0.132525, 0.921849, ...],
 [0.576599, 0.708519, 0.574167, 0.978737, 0.30185, 0.335933, 0.132421, ...]]
[13] pry(main)> a = mat[0, true]
=> Numo::DFloat(view)#shape=[10]
[0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032, 0.539948, ...]
[14] pry(main)> a.transpose.dot(a)
=> 1.8127238649476016
[16] pry(main)> mat.transpose.dot(mat)
(pry):11: [BUG] Segmentation fault at 0x00000000000000

First, I thought that view object cannot '.dot' operation, but according to [13] and [14], it can do.

So, I think this error occurs when matrix object's shape is not [x, 1](-> not vector).

My environment is bellow.

Ruby: 2.3
numo-narray: 0.9.0.2
Ubuntu: 16.04 LTS

thanks.

Convention for abbreviation

a = Numo::DFloat.new(20,30).seq

This style is right as a Ruby code, but I prefer less typing.

First idea:

include Numo
a = DFloat.new(20,30).seq

In this case, you can omit Numo module name.
However, Numo module functions like Numo.max(a,b) become top-level methods.

Another idea:

DF = Numo::DFloat
a = DF.new(20,30).seq

It is able to write more shortly. But it requires assignment. Collision of constant name may happen.

What is Numo-convension for abbreviaton corresponding to import numpy as np ?

New method for constructor is possible.
Old NArray style:

a = Numo.dfloat(20,30).indgen!

Numpy style:

a = Numo.arange(600).reshape!(20,30)

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.