nmatrix 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,13 +91,10 @@ $CFLAGS += " -O3 "
91
91
  $CXXFLAGS += " -O3 -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
92
92
  #$CXXFLAGS += " -static -O0 -g -std=#{$CXX_STANDARD} "
93
93
 
94
- CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)
95
- CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
96
- CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
97
-
94
+ if CONFIG.has_key?('warnflags')
95
+ CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)
96
+ CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
97
+ CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
98
+ end
99
+
98
100
  have_func("rb_array_const_ptr", "ruby.h")
99
- have_macro("FIX_CONST_VALUE_PTR", "ruby.h")
100
- have_macro("RARRAY_CONST_PTR", "ruby.h")
101
- have_macro("RARRAY_AREF", "ruby.h")
102
-
103
-
@@ -26,8 +26,6 @@
26
26
  # Ruby core extensions for NMatrix.
27
27
  #++
28
28
 
29
- require 'nmatrix/math'
30
-
31
29
  #######################
32
30
  # Classes and Modules #
33
31
  #######################
@@ -38,9 +36,9 @@ class Array
38
36
  # You must provide a shape for the matrix as the first argument.
39
37
  #
40
38
  # == Arguments:
41
- # <tt>shape</tt> :: Array describing matrix dimensions (or Fixnum for square).
39
+ # <tt>shape</tt> :: Array describing matrix dimensions (or Fixnum for square).
42
40
  # If not provided, will be intuited through #shape.
43
- # <tt>dtype</tt> :: Override data type (e.g., to store a Float as :float32
41
+ # <tt>dtype</tt> :: Override data type (e.g., to store a Float as :float32
44
42
  # instead of :float64) -- optional.
45
43
  # <tt>stype</tt> :: Optional storage type (defaults to :dense)
46
44
  def to_nm(shape = nil, dtype = nil, stype = :dense)
@@ -30,21 +30,32 @@
30
30
  #++
31
31
 
32
32
  # For some reason nmatrix.so ends up in a different place during gem build.
33
- if File.exist?("lib/nmatrix/nmatrix.so") #|| File.exist?("lib/nmatrix/nmatrix.bundle")
34
- # Development
35
- require "nmatrix/nmatrix.so"
36
- else
37
- # Gem
38
- require "nmatrix.so"
33
+
34
+ # Detect java
35
+ def jruby?
36
+ /java/ === RUBY_PLATFORM
39
37
  end
40
38
 
41
- require_relative './io/mat_reader'
42
- require_relative './io/mat5_reader'
43
- require_relative './io/market'
44
- require_relative './io/point_cloud'
39
+ if jruby?
40
+ require_relative 'jruby/nmatrix_java'
41
+ else
42
+ if File.exist?("lib/nmatrix/nmatrix.so") #|| File.exist?("lib/nmatrix/nmatrix.bundle")
43
+ # Development
44
+ require_relative "nmatrix/nmatrix.so"
45
+ else
46
+ # Gem
47
+ require_relative "../nmatrix.so"
48
+ require_relative './io/mat_reader'
49
+ require_relative './io/mat5_reader'
50
+ require_relative './io/market'
51
+ require_relative './io/point_cloud'
52
+
53
+ require_relative './lapack_core.rb'
54
+ require_relative './yale_functions.rb'
55
+ end
56
+ end
45
57
 
46
- require_relative './lapack_core.rb'
47
- require_relative './yale_functions.rb'
58
+ require_relative './math.rb'
48
59
  require_relative './monkeys'
49
60
 
50
61
  # NMatrix is a matrix class that supports both multidimensional arrays
@@ -86,7 +97,7 @@ class NMatrix
86
97
  # * *Returns* :
87
98
  # - A Mat5Reader object.
88
99
  def load_matlab_file(file_path)
89
- NMatrix::IO::Mat5Reader.new(File.open(file_path, 'rb')).to_ruby
100
+ NMatrix::IO::Matlab::Mat5Reader.new(File.open(file_path, 'rb')).to_ruby
90
101
  end
91
102
 
92
103
  # call-seq:
@@ -189,12 +200,14 @@ class NMatrix
189
200
  end
190
201
  end
191
202
  else # dim 2
192
- q.group(0, "\n[\n", "]") do
193
- self.each_row.with_index do |row,i|
194
- q.group(1, " [", "]") do
195
- q.seplist(self.dim > 2 ? row.to_a[0] : row.to_a, lambda { q.text ", " }, :each_with_index) { |v,j| q.text v.inspect.rjust(longest[j]) }
203
+ q.group(0, "\n[\n ", "]") do
204
+ self.each_row.with_index do |row, i|
205
+ q.group(1, " [", "]\n") do
206
+ q.seplist(row.to_a, -> { q.text ", " }, :each_with_index) do |v,j|
207
+ q.text v.inspect.rjust(longest[j])
208
+ end
196
209
  end
197
- q.breakable
210
+ q.breakable unless i + 1 == self.shape[0]
198
211
  end
199
212
  end
200
213
  end
@@ -269,14 +282,14 @@ class NMatrix
269
282
  end
270
283
 
271
284
  # Return the main diagonal or antidiagonal a matrix. Only works with 2D matrices.
272
- #
285
+ #
273
286
  # == Arguments
274
- #
275
- # * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
287
+ #
288
+ # * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
276
289
  # antidiagonal of the matrix.
277
- #
290
+ #
278
291
  # == References
279
- #
292
+ #
280
293
  # * http://en.wikipedia.org/wiki/Main_diagonal
281
294
  def diagonal main_diagonal=true
282
295
  diag_size = [cols, rows].min
@@ -367,9 +380,9 @@ class NMatrix
367
380
 
368
381
  ##
369
382
  # call-seq:
370
- #
383
+ #
371
384
  # object_dtype?() -> Boolean
372
- #
385
+ #
373
386
  # Checks if dtype is a ruby object
374
387
  def object_dtype?
375
388
  dtype == :object
@@ -645,7 +658,15 @@ class NMatrix
645
658
  t
646
659
  else
647
660
  # Call C versions of Yale and List transpose, which do their own copies
648
- self.clone_transpose
661
+ if jruby?
662
+ nmatrix = NMatrix.new :copy
663
+ nmatrix.shape = [@shape[1],@shape[0]]
664
+ twoDMat = self.twoDMat.transpose
665
+ nmatrix.s = ArrayRealVector.new(ArrayGenerator.getArrayDouble(twoDMat.getData(), shape[1],shape[0]))
666
+ return nmatrix
667
+ else
668
+ self.clone_transpose
669
+ end
649
670
  end
650
671
  end
651
672
 
@@ -867,7 +888,17 @@ class NMatrix
867
888
  # - A NMatrix representing the requested layer as a layer vector.
868
889
  #
869
890
  def layer(layer_number, get_by = :copy)
870
- rank(2, layer_number, get_by)
891
+ layer = rank(2, layer_number, get_by)
892
+
893
+ if jruby?
894
+ nmatrix = NMatrix.new :copy
895
+ nmatrix.shape = layer.shape
896
+ nmatrix.s = layer.s
897
+ return nmatrix
898
+ else
899
+ layer
900
+ end
901
+
871
902
  end
872
903
 
873
904
 
@@ -976,9 +1007,9 @@ class NMatrix
976
1007
  return self.map_stored.inject(sym)
977
1008
  end
978
1009
 
979
- # Returns the index of the first occurence of the specified value. Returns
1010
+ # Returns the index of the first occurence of the specified value. Returns
980
1011
  # an array containing the position of the value, nil in case the value is not found.
981
- #
1012
+ #
982
1013
  def index(value)
983
1014
  index = nil
984
1015
 
@@ -988,7 +1019,7 @@ class NMatrix
988
1019
  index = yields
989
1020
  break
990
1021
  end
991
- end
1022
+ end
992
1023
 
993
1024
  index
994
1025
  end
@@ -1011,7 +1042,7 @@ class NMatrix
1011
1042
  #
1012
1043
  # call-seq:
1013
1044
  # repeat(count, axis) -> NMatrix
1014
- #
1045
+ #
1015
1046
  # * *Arguments* :
1016
1047
  # - +count+ -> how many times NMatrix should be repeated
1017
1048
  # - +axis+ -> index of axis along which NMatrix should be repeated
@@ -1137,7 +1168,6 @@ protected
1137
1168
  end
1138
1169
 
1139
1170
  require_relative './shortcuts.rb'
1140
- require_relative './math.rb'
1141
1171
  require_relative './enumerate.rb'
1142
1172
 
1143
1173
  require_relative './version.rb'
@@ -494,11 +494,11 @@ class NMatrix
494
494
  block_sizes << b.shape[0]
495
495
  end
496
496
 
497
- block_diag_mat = NMatrix.zeros(block_sizes.sum, options)
497
+ block_diag_mat = NMatrix.zeros(block_sizes.inject(0,:+), options)
498
498
  (0...params.length).each do |n|
499
499
  # First determine the size and position of the n'th block in the block-diagonal matrix
500
500
  block_size = block_sizes[n]
501
- block_pos = block_sizes[0...n].sum
501
+ block_pos = block_sizes[0...n].inject(0,:+)
502
502
  # populate the n'th block in the block-diagonal matrix
503
503
  (0...block_size).each do |i|
504
504
  (0...block_size).each do |j|
@@ -536,7 +536,12 @@ class NMatrix
536
536
  def random(shape, opts={})
537
537
  scale = opts.delete(:scale) || 1.0
538
538
 
539
- rng = Random.new
539
+ if opts[:seed].nil?
540
+ rng = Random.new
541
+ else
542
+ rng = Random.new(opts[:seed])
543
+ end
544
+
540
545
 
541
546
  random_values = []
542
547
 
@@ -29,7 +29,7 @@ class NMatrix
29
29
  module VERSION #:nodoc:
30
30
  MAJOR = 0
31
31
  MINOR = 2
32
- TINY = 3
32
+ TINY = 4
33
33
  #PRE = "a"
34
34
 
35
35
  STRING = [MAJOR, MINOR, TINY].compact.join(".")
@@ -41,8 +41,71 @@ describe NMatrix do
41
41
  expect { n[0] }.to raise_error(ArgumentError)
42
42
  end
43
43
 
44
- it "calculates exact determinants on small square matrices" do
44
+ it "calculates exact determinants on small dense matrices" do
45
45
  expect(NMatrix.new(2, [1,2,3,4], stype: :dense, dtype: :int64).det_exact).to eq(-2)
46
+ expect(NMatrix.new(3, [1,2,3,0,5,6,7,8,0], stype: :dense, dtype: :int64)
47
+ .det_exact).to eq(-69)
48
+ end
49
+
50
+ it "calculates exact determinants on small yale square matrices" do
51
+ expect(NMatrix.new(2, [1,2,3,4], stype: :yale, dtype: :int64).det_exact).to eq(-2)
52
+ expect(NMatrix.new(3, [1,2,3,0,5,6,7,8,0], stype: :yale, dtype: :int64)
53
+ .det_exact).to eq(-69)
54
+ end
55
+
56
+ it "calculates exact determinants on small list square matrices" do
57
+ expect(NMatrix.new(2, [1,2,3,4], stype: :list, dtype: :int64).det_exact).to eq(-2)
58
+ expect(NMatrix.new(3, [1,2,3,0,5,6,7,8,0], stype: :list, dtype: :int64)
59
+ .det_exact).to eq(-69)
60
+ end
61
+
62
+ it "calculates inverse exact determinants on small dense matrices" do
63
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
64
+ a = NMatrix.new(3, [1,2,3,0,1,4,5,6,0], stype: :dense, dtype: :int64)
65
+ inversed = a.method(:__inverse_exact__).call(a.clone, 3, 3)
66
+ b = NMatrix.new(3, [-24,18,5,20,-15,-4,-5,4,1], stype: :dense, dtype: :int64)
67
+ expect(inversed).to eq(b)
68
+
69
+ c = NMatrix.new(3, [1,0,3,0,0,1,0,6,0], stype: :dense, dtype: :int64)
70
+ inversed = c.method(:__inverse_exact__).call(c.clone, 3, 3)
71
+ d = NMatrix.new(3, [1,-3,0,0,0,0,0,1,0], stype: :dense, dtype: :int64)
72
+ expect(inversed).to eq(d)
73
+
74
+ e = NMatrix.new(2, [3,1,2,1], stype: :dense, dtype: :int64)
75
+ inversed = e.method(:__inverse_exact__).call(e.clone, 2, 2)
76
+ f = NMatrix.new(2, [1,-1,-2,3], stype: :dense, dtype: :int64)
77
+ expect(inversed).to eq(f)
78
+ end
79
+
80
+ it "calculates inverse exact determinants on small yale matrices" do
81
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
82
+ a = NMatrix.new(3, [1,2,3,0,1,4,5,6,0], stype: :yale, dtype: :int64)
83
+ inversed = a.method(:__inverse_exact__).call(a.clone, 3, 3)
84
+ b = NMatrix.new(3, [-24,18,5,20,-15,-4,-5,4,1], stype: :yale, dtype: :int64)
85
+ expect(inversed).to eq(b)
86
+
87
+ c = NMatrix.new(3, [1,0,3,0,0,1,0,6,0], stype: :yale, dtype: :int64)
88
+ inversed = c.method(:__inverse_exact__).call(c.clone, 3, 3)
89
+ d = NMatrix.new(3, [1,-3,0,0,0,0,0,1,0], stype: :yale, dtype: :int64)
90
+ expect(inversed).to eq(d)
91
+
92
+ e = NMatrix.new(2, [3,1,2,1], stype: :yale, dtype: :int64)
93
+ inversed = e.method(:__inverse_exact__).call(e.clone, 2, 2)
94
+ f = NMatrix.new(2, [1,-1,-2,3], stype: :yale, dtype: :int64)
95
+ expect(inversed).to eq(f)
96
+ end
97
+
98
+ it "calculates inverse exact determinants on small list matrices" do
99
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
100
+ a = NMatrix.new(3, [1,2,3,0,1,4,5,6,0], stype: :list, dtype: :int64)
101
+ inversed = a.method(:__inverse_exact__).call(a.clone, 3, 3)
102
+ b = NMatrix.new(3, [-24,18,5,20,-15,-4,-5,4,1], stype: :list, dtype: :int64)
103
+ expect(inversed).to eq(b)
104
+
105
+ c = NMatrix.new(2, [3,1,2,1], stype: :list, dtype: :int64)
106
+ inversed = c.method(:__inverse_exact__).call(c.clone, 2, 2)
107
+ d = NMatrix.new(2, [1,-1,-2,3], stype: :list, dtype: :int64)
108
+ expect(inversed).to eq(d)
46
109
  end
47
110
 
48
111
  it "calculates determinants" do
@@ -56,6 +119,7 @@ describe NMatrix do
56
119
  end
57
120
 
58
121
  it "allows casting from Ruby objects" do
122
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
59
123
  m = NMatrix.new(:dense, [3,3], [0,0,1,0,2,0,3,4,5], :object)
60
124
  n = m.cast(:dense, :int64)
61
125
  expect(m).to eq(n)
@@ -78,6 +142,7 @@ describe NMatrix do
78
142
 
79
143
  it "fills dense Ruby object matrix with nil" do
80
144
  n = NMatrix.new([4,3], dtype: :object)
145
+ pending("not yet implemented for object dtype for NMatrix-JRuby") if jruby?
81
146
  expect(n[0,0]).to eq(nil)
82
147
  end
83
148
 
@@ -146,6 +211,7 @@ describe NMatrix do
146
211
 
147
212
  it "dense handles missing initialization value" do
148
213
  n = NMatrix.new(3, dtype: :int8)
214
+ pending("not yet implemented for int dtype for NMatrix-JRuby") if jruby?
149
215
  expect(n.stype).to eq(:dense)
150
216
  expect(n.dtype).to eq(:int8)
151
217
 
@@ -158,6 +224,8 @@ describe NMatrix do
158
224
  context storage_type do
159
225
  it "can be duplicated" do
160
226
  n = NMatrix.new([2,3], 1.1, stype: storage_type, dtype: :float64)
227
+ # FIXME
228
+ pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby? #and storage_type != :dense
161
229
  expect(n.stype).to eq(storage_type)
162
230
 
163
231
  n[0,0] = 0.0
@@ -223,6 +291,7 @@ describe NMatrix do
223
291
  end
224
292
 
225
293
  it "allows storage-based iteration of matrices" do
294
+ pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby? and storage_type != :dense
226
295
  STDERR.puts storage_type.inspect
227
296
  STDERR.puts dtype.inspect
228
297
  n = NMatrix.new([3,3], 0, stype: storage_type, dtype: dtype)
@@ -263,6 +332,7 @@ describe NMatrix do
263
332
  # dense and list, not yale
264
333
  context "(storage: #{storage_type})" do
265
334
  it "gets default value" do
335
+ pending("not yet implemented for sparse matrices for NMatrix-JRuby") if jruby?
266
336
  expect(NMatrix.new(3, 0, stype: storage_type)[1,1]).to eq(0)
267
337
  expect(NMatrix.new(3, 0.1, stype: storage_type)[1,1]).to eq(0.1)
268
338
  expect(NMatrix.new(3, 1, stype: storage_type)[1,1]).to eq(1)
@@ -321,12 +391,16 @@ describe NMatrix do
321
391
 
322
392
  context "dense" do
323
393
  it "should return the matrix being iterated over when each is called with a block" do
394
+ # FIXME
395
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
324
396
  a = NMatrix.new(2, 1)
325
397
  val = (a.each { })
326
398
  expect(val).to eq(a)
327
399
  end
328
400
 
329
401
  it "should return the matrix being iterated over when each_stored_with_indices is called with a block" do
402
+ # FIXME
403
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
330
404
  a = NMatrix.new(2,1)
331
405
  val = (a.each_stored_with_indices { })
332
406
  expect(val).to eq(a)
@@ -336,12 +410,14 @@ describe NMatrix do
336
410
  [:list, :yale].each do |storage_type|
337
411
  context storage_type do
338
412
  it "should return the matrix being iterated over when each_stored_with_indices is called with a block" do
413
+ pending("not yet implemented for Complex dtype for NMatrix-JRuby") if jruby?
339
414
  n = NMatrix.new([2,3], 1.1, stype: storage_type, dtype: :float64, default: 0)
340
415
  val = (n.each_stored_with_indices { })
341
416
  expect(val).to eq(n)
342
417
  end
343
418
 
344
419
  it "should return an enumerator when each_stored_with_indices is called without a block" do
420
+ pending("not yet implemented for Complex dtype for NMatrix-JRuby") if jruby?
345
421
  n = NMatrix.new([2,3], 1.1, stype: storage_type, dtype: :float64, default: 0)
346
422
  val = n.each_stored_with_indices
347
423
  expect(val).to be_a Enumerator
@@ -405,11 +481,15 @@ describe 'NMatrix' do
405
481
 
406
482
  context "#reshape" do
407
483
  it "should change the shape of a matrix without the contents changing" do
484
+ # FIXME
485
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
408
486
  n = NMatrix.seq(4)+1
409
487
  expect(n.reshape([8,2]).to_flat_array).to eq(n.to_flat_array)
410
488
  end
411
489
 
412
490
  it "should permit a change of dimensionality" do
491
+ # FIXME
492
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
413
493
  n = NMatrix.seq(4)+1
414
494
  expect(n.reshape([8,1,2]).to_flat_array).to eq(n.to_flat_array)
415
495
  end
@@ -425,6 +505,8 @@ describe 'NMatrix' do
425
505
  end
426
506
 
427
507
  it "should do the reshape operation in place, changing dimension" do
508
+ # FIXME
509
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
428
510
  n = NMatrix.seq(4)
429
511
  a = n.reshape!([4,2,2])
430
512
  expect(n).to eq(NMatrix.seq([4,2,2]))
@@ -432,6 +514,8 @@ describe 'NMatrix' do
432
514
  end
433
515
 
434
516
  it "reshape and reshape! must produce same result" do
517
+ # FIXME
518
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
435
519
  n = NMatrix.seq(4)+1
436
520
  a = NMatrix.seq(4)+1
437
521
  expect(n.reshape!([8,2])==a.reshape(8,2)).to eq(true) # because n itself changes
@@ -481,6 +565,8 @@ describe 'NMatrix' do
481
565
  [:dense].each do |stype| # list storage transpose not yet implemented
482
566
  context(stype) do # yale support only 2-dim matrix
483
567
  it "should work like vector product on a #{stype} (1-dimensional)" do
568
+ # FIXME
569
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
484
570
  m = NMatrix.new([3], [1,2,3], stype: stype)
485
571
  expect(m.dot(m)).to eq (NMatrix.new([1],[14]))
486
572
  end
@@ -538,6 +624,8 @@ describe 'NMatrix' do
538
624
  end
539
625
 
540
626
  it "should permit depth concatenation on tensors" do
627
+ # FIXME
628
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
541
629
  n = NMatrix.new([1,3,1], [1,2,3])
542
630
  expect(n.dconcat(n)).to eq(NMatrix.new([1,3,2], [1,1,2,2,3,3]))
543
631
  end
@@ -548,6 +636,8 @@ describe 'NMatrix' do
548
636
  m = N[[7],
549
637
  [8]]
550
638
 
639
+ # FIXME
640
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
551
641
  expect(n.hconcat(m)).to eq N[[1, 2, 3, 7], [4, 5, 6, 8]]
552
642
  expect(m.hconcat(n)).to eq N[[7, 1, 2, 3], [8, 4, 5, 6]]
553
643
  end
@@ -558,6 +648,8 @@ describe 'NMatrix' do
558
648
 
559
649
  m = N[[7, 8, 9]]
560
650
 
651
+ # FIXME
652
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
561
653
  expect(n.vconcat(m)).to eq N[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
562
654
  expect(m.vconcat(n)).to eq N[[7, 8, 9], [1, 2, 3], [4, 5, 6]]
563
655
  end
@@ -582,6 +674,7 @@ describe 'NMatrix' do
582
674
  context(stype) do
583
675
  it "should work in-place for complex dtypes" do
584
676
  pending("not yet implemented for list stype") if stype == :list
677
+ pending("not yet implemented for Complex dtype for NMatrix-JRuby") if jruby?
585
678
  n = NMatrix.new([2,3], [Complex(2,3)], stype: stype, dtype: :complex128)
586
679
  n.complex_conjugate!
587
680
  expect(n).to eq(NMatrix.new([2,3], [Complex(2,-3)], stype: stype, dtype: :complex128))
@@ -590,6 +683,7 @@ describe 'NMatrix' do
590
683
  [:object, :int64].each do |dtype|
591
684
  it "should work in-place for non-complex dtypes" do
592
685
  pending("not yet implemented for list stype") if stype == :list
686
+ pending("not yet implemented for Complex dtype for NMatrix-JRuby") if jruby?
593
687
  n = NMatrix.new([2,3], 1, stype: stype, dtype: dtype)
594
688
  n.complex_conjugate!
595
689
  expect(n).to eq(NMatrix.new([2,3], [1], stype: stype, dtype: dtype))
@@ -604,6 +698,7 @@ describe 'NMatrix' do
604
698
  context(stype) do
605
699
  it "should work out-of-place for complex dtypes" do
606
700
  pending("not yet implemented for list stype") if stype == :list
701
+ pending("not yet implemented for Complex dtype for NMatrix-JRuby") if jruby?
607
702
  n = NMatrix.new([2,3], [Complex(2,3)], stype: stype, dtype: :complex128)
608
703
  expect(n.complex_conjugate).to eq(NMatrix.new([2,3], [Complex(2,-3)], stype: stype, dtype: :complex128))
609
704
  end
@@ -611,6 +706,7 @@ describe 'NMatrix' do
611
706
  [:object, :int64].each do |dtype|
612
707
  it "should work out-of-place for non-complex dtypes" do
613
708
  pending("not yet implemented for list stype") if stype == :list
709
+ pending("not yet implemented for Complex dtype for NMatrix-JRuby") if jruby?
614
710
  n = NMatrix.new([2,3], 1, stype: stype, dtype: dtype)
615
711
  expect(n.complex_conjugate).to eq(NMatrix.new([2,3], [1], stype: stype, dtype: dtype))
616
712
  end
@@ -677,7 +773,7 @@ describe 'NMatrix' do
677
773
 
678
774
  context "#diagonal" do
679
775
  ALL_DTYPES.each do |dtype|
680
- before do
776
+ before do
681
777
  @square_matrix = NMatrix.new([3,3], [
682
778
  23,11,23,
683
779
  44, 2, 0,
@@ -723,11 +819,14 @@ describe 'NMatrix' do
723
819
  end
724
820
 
725
821
  it "returns repeated matrix" do
822
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
726
823
  expect(@sample_matrix.repeat(2, 0)).to eq(NMatrix.new([4, 2], [1, 2, 3, 4, 1, 2, 3, 4]))
727
824
  expect(@sample_matrix.repeat(2, 1)).to eq(NMatrix.new([2, 4], [1, 2, 1, 2, 3, 4, 3, 4]))
728
825
  end
729
826
 
730
827
  it "preserves dtype" do
828
+ # FIXME
829
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
731
830
  expect(@sample_matrix.repeat(2, 0).dtype).to eq(@sample_matrix.dtype)
732
831
  expect(@sample_matrix.repeat(2, 1).dtype).to eq(@sample_matrix.dtype)
733
832
  end
@@ -742,42 +841,50 @@ describe 'NMatrix' do
742
841
  @expected_for_ij = [NMatrix.new([3, 2], [1, 1, 2, 2, 3, 3]), NMatrix.new([3, 2], [4, 5, 4, 5, 4, 5])]
743
842
  @expected_for_sparse = [NMatrix.new([1, 3], [1, 2, 3]), NMatrix.new([2, 1], [4, 5])]
744
843
  @expected_for_sparse_ij = [NMatrix.new([3, 1], [1, 2, 3]), NMatrix.new([1, 2], [4, 5])]
844
+ # FIXME
745
845
  @expected_3dim = [NMatrix.new([1, 3, 1], [1, 2, 3]).repeat(2, 0).repeat(2, 2),
746
846
  NMatrix.new([2, 1, 1], [4, 5]).repeat(3, 1).repeat(2, 2),
747
- NMatrix.new([1, 1, 2], [6, 7]).repeat(2, 0).repeat(3, 1)]
847
+ NMatrix.new([1, 1, 2], [6, 7]).repeat(2, 0).repeat(3, 1)] unless jruby?
748
848
  @expected_3dim_sparse_ij = [NMatrix.new([3, 1, 1], [1, 2, 3]),
749
849
  NMatrix.new([1, 2, 1], [4, 5]),
750
850
  NMatrix.new([1, 1, 2], [6, 7])]
751
851
  end
752
852
 
753
853
  it "checks arrays count" do
854
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
754
855
  expect{NMatrix.meshgrid([@x])}.to raise_error(ArgumentError)
755
856
  expect{NMatrix.meshgrid([])}.to raise_error(ArgumentError)
756
857
  end
757
858
 
758
859
  it "flattens input arrays before use" do
860
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
759
861
  expect(NMatrix.meshgrid([@two_dim, @two_dim_array])).to eq(NMatrix.meshgrid([@two_dim.to_flat_array, @two_dim_array.flatten]))
760
862
  end
761
863
 
762
864
  it "returns new NMatrixes" do
865
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
763
866
  expect(NMatrix.meshgrid([@x, @y])).to eq(@expected_result)
764
867
  end
765
868
 
766
869
  it "has option :sparse" do
870
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
767
871
  expect(NMatrix.meshgrid([@x, @y], sparse: true)).to eq(@expected_for_sparse)
768
872
  end
769
873
 
770
874
  it "has option :indexing" do
875
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
771
876
  expect(NMatrix.meshgrid([@x, @y], indexing: :ij)).to eq(@expected_for_ij)
772
877
  expect(NMatrix.meshgrid([@x, @y], indexing: :xy)).to eq(@expected_result)
773
878
  expect{NMatrix.meshgrid([@x, @y], indexing: :not_ij_not_xy)}.to raise_error(ArgumentError)
774
879
  end
775
880
 
776
881
  it "works well with both options set" do
882
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
777
883
  expect(NMatrix.meshgrid([@x, @y], sparse: true, indexing: :ij)).to eq(@expected_for_sparse_ij)
778
884
  end
779
885
 
780
886
  it "is able to take more than two arrays as arguments and works well with options" do
887
+ pending("Not yet implemented for NMatrix JRuby") if jruby?
781
888
  expect(NMatrix.meshgrid([@x, @y, @z])).to eq(@expected_3dim)
782
889
  expect(NMatrix.meshgrid([@x, @y, @z], sparse: true, indexing: :ij)).to eq(@expected_3dim_sparse_ij)
783
890
  end