cumo 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +18 -37
  3. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +28 -21
  4. data/CHANGELOG.md +28 -0
  5. data/Dockerfile +34 -0
  6. data/cumo.gemspec +1 -1
  7. data/docker-build.sh +4 -0
  8. data/docker-launch.sh +4 -0
  9. data/docs/src-tree.md +1 -1
  10. data/ext/cumo/cuda/cudnn_impl.cpp +25 -3
  11. data/ext/cumo/cuda/driver.c +8 -0
  12. data/ext/cumo/depend.erb +1 -1
  13. data/ext/cumo/extconf.rb +1 -1
  14. data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +14 -7
  15. data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +3 -3
  16. data/ext/cumo/include/cumo/narray.h +2 -0
  17. data/ext/cumo/include/cumo/types/complex.h +2 -2
  18. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +15 -4
  19. data/ext/cumo/include/cumo/types/real_accum_kernel.h +15 -4
  20. data/ext/cumo/include/cumo/types/xint_macro_kernel.h +11 -3
  21. data/ext/cumo/include/cumo.h +2 -2
  22. data/ext/cumo/narray/array.c +5 -3
  23. data/ext/cumo/narray/data.c +25 -26
  24. data/ext/cumo/narray/gen/tmpl/accum.c +2 -2
  25. data/ext/cumo/narray/gen/tmpl/accum_binary.c +1 -1
  26. data/ext/cumo/narray/gen/tmpl/alloc_func.c +4 -1
  27. data/ext/cumo/narray/gen/tmpl/allocate.c +1 -0
  28. data/ext/cumo/narray/gen/tmpl/aref.c +18 -18
  29. data/ext/cumo/narray/gen/tmpl/aset.c +16 -16
  30. data/ext/cumo/narray/gen/tmpl/batch_norm.c +4 -1
  31. data/ext/cumo/narray/gen/tmpl/batch_norm_backward.c +4 -1
  32. data/ext/cumo/narray/gen/tmpl/bincount.c +7 -7
  33. data/ext/cumo/narray/gen/tmpl/clip.c +11 -15
  34. data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +12 -12
  35. data/ext/cumo/narray/gen/tmpl/cum.c +1 -1
  36. data/ext/cumo/narray/gen/tmpl/each.c +4 -2
  37. data/ext/cumo/narray/gen/tmpl/each_with_index.c +5 -2
  38. data/ext/cumo/narray/gen/tmpl/fixed_batch_norm.c +4 -1
  39. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +12 -12
  40. data/ext/cumo/narray/gen/tmpl/logseq.c +6 -5
  41. data/ext/cumo/narray/gen/tmpl/map_with_index.c +5 -6
  42. data/ext/cumo/narray/gen/tmpl/median.c +2 -2
  43. data/ext/cumo/narray/gen/tmpl/minmax.c +1 -1
  44. data/ext/cumo/narray/gen/tmpl/poly.c +4 -4
  45. data/ext/cumo/narray/gen/tmpl/rand.c +8 -6
  46. data/ext/cumo/narray/gen/tmpl/rand_norm.c +18 -16
  47. data/ext/cumo/narray/gen/tmpl/seq.c +5 -4
  48. data/ext/cumo/narray/gen/tmpl/sort.c +2 -2
  49. data/ext/cumo/narray/gen/tmpl/sort_index.c +2 -2
  50. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +1 -0
  51. data/ext/cumo/narray/gen/tmpl_bit/aref.c +26 -32
  52. data/ext/cumo/narray/gen/tmpl_bit/aset.c +18 -30
  53. data/ext/cumo/narray/index.c +1 -1
  54. data/ext/cumo/narray/narray.c +116 -21
  55. data/lib/cumo/narray/extra.rb +160 -156
  56. data/test/cuda/device_test.rb +2 -1
  57. data/test/cudnn_test.rb +2 -2
  58. data/test/narray_test.rb +80 -0
  59. data/test/ractor_test.rb +5 -3
  60. metadata +5 -2
data/test/narray_test.rb CHANGED
@@ -736,10 +736,90 @@ class NArrayTest < Test::Unit::TestCase
736
736
  at.at([0, 1], [0, 1]).inplace - 1
737
737
  assert { at == [[0, 2, 3], [4, 4, 6]] }
738
738
  end
739
+
740
+ sub_test_case "#{dtype}.from_binary" do
741
+ test "frozen string" do
742
+ shape = [2, 5]
743
+ a = dtype.new(*shape)
744
+ a.rand(0, 10)
745
+ original_data = a.to_binary
746
+ data = original_data.dup.freeze
747
+ restored_a = dtype.from_binary(data, shape)
748
+ assert { restored_a == a }
749
+ restored_a[0, 0] += 1
750
+ assert { restored_a != a }
751
+ assert { data == original_data }
752
+ end
753
+
754
+ test "not frozen string" do
755
+ shape = [2, 5]
756
+ a = dtype.new(*shape)
757
+ a.rand(0, 10)
758
+ original_data = a.to_binary
759
+ data = original_data.dup
760
+ restored_a = dtype.from_binary(data, shape)
761
+ assert { restored_a == a }
762
+ restored_a[0, 0] += 1
763
+ assert { restored_a != a }
764
+ assert { data == original_data }
765
+ end
766
+ end
767
+
768
+ sub_test_case "#{dtype}#store_binary" do
769
+ test "frozen string" do
770
+ shape = [2, 5]
771
+ a = dtype.new(*shape)
772
+ a.rand(0, 10)
773
+ original_data = a.to_binary
774
+ data = original_data.dup.freeze
775
+ restored_a = dtype.new(*shape)
776
+ restored_a.store_binary(data)
777
+ assert { restored_a == a }
778
+ restored_a[0, 0] += 1
779
+ assert { restored_a != a }
780
+ assert { data == original_data }
781
+ end
782
+
783
+ test "not frozen string" do
784
+ shape = [2, 5]
785
+ a = dtype.new(*shape)
786
+ a.rand(0, 10)
787
+ original_data = a.to_binary
788
+ data = original_data.dup
789
+ restored_a = dtype.new(*shape)
790
+ restored_a.store_binary(data)
791
+ assert { restored_a == a }
792
+ restored_a[0, 0] += 1
793
+ assert { restored_a != a }
794
+ assert { data == original_data }
795
+ end
796
+ end
739
797
  end
740
798
 
741
799
  test "Cumo::DFloat.cast(Cumo::RObject[1, nil, 3])" do
742
800
  assert_equal(Cumo::DFloat[1, Float::NAN, 3].format_to_a,
743
801
  Cumo::DFloat.cast(Cumo::RObject[1, nil, 3]).format_to_a)
744
802
  end
803
+
804
+ test "single element array" do
805
+ assert { Cumo::SFloat[1].mean == 1.0 }
806
+ assert { Cumo::DFloat[1].mean == 1.0 }
807
+ assert { Cumo::SComplex[1].mean == 1.0 }
808
+ assert { Cumo::DComplex[1].mean == 1.0 }
809
+
810
+ assert { Cumo::SFloat[1].var.to_f.nan? }
811
+ assert { Cumo::DFloat[1].var.to_f.nan? }
812
+ assert { Cumo::SComplex[1].var.to_f.nan? }
813
+ assert { Cumo::DComplex[1].var.to_f.nan? }
814
+
815
+ assert { Cumo::SFloat[1].stddev.to_f.nan? }
816
+ assert { Cumo::DFloat[1].stddev.to_f.nan? }
817
+ assert { Cumo::SComplex[1].stddev.to_f.nan? }
818
+ assert { Cumo::DComplex[1].stddev.to_f.nan? }
819
+
820
+ assert { Cumo::SFloat[1].rms == 1.0 }
821
+ assert { Cumo::DFloat[1].rms == 1.0 }
822
+ assert { Cumo::SComplex[1].rms == 1.0 }
823
+ assert { Cumo::DComplex[1].rms == 1.0 }
824
+ end
745
825
  end
data/test/ractor_test.rb CHANGED
@@ -10,7 +10,7 @@ class NArrayRactorTest < CumoTestBase
10
10
  dtype = data.fetch(:dtype)
11
11
  ary = random_array(dtype)
12
12
  r = Ractor.new(ary) { |x| x }
13
- ary2 = r.take
13
+ ary2 = r.respond_to?(:take) ? r.take : r.value
14
14
  assert_equal(ary, ary2)
15
15
  assert_not_same(ary, ary2)
16
16
  end
@@ -22,7 +22,7 @@ class NArrayRactorTest < CumoTestBase
22
22
  r = Ractor.new(ary1) do |ary2|
23
23
  [ary2, ary2 * 10]
24
24
  end
25
- ary2, res = r.take
25
+ ary2, res = r.respond_to?(:take) ? r.take : r.value
26
26
  assert_equal((dtype != Cumo::RObject),
27
27
  ary1.equal?(ary2))
28
28
  assert_equal(ary1 * 10, res)
@@ -37,7 +37,9 @@ class NArrayRactorTest < CumoTestBase
37
37
  r2 = Ractor.new(ary1) do |ary4|
38
38
  ary4 * 10
39
39
  end
40
- assert_equal(r1.take, r2.take)
40
+ result1 = r1.respond_to?(:take) ? r1.take : r1.value
41
+ result2 = r2.respond_to?(:take) ? r2.take : r2.value
42
+ assert_equal(result1, result2)
41
43
  end
42
44
 
43
45
  def random_array(dtype, n=1000)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cumo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
@@ -35,6 +35,7 @@ files:
35
35
  - 3rd_party/mkmf-cu/test/test_mkmf-cu.rb
36
36
  - CHANGELOG.md
37
37
  - CODE_OF_CONDUCT.md
38
+ - Dockerfile
38
39
  - Gemfile
39
40
  - LICENSE.txt
40
41
  - README.md
@@ -46,6 +47,8 @@ files:
46
47
  - bin/console
47
48
  - bin/setup
48
49
  - cumo.gemspec
50
+ - docker-build.sh
51
+ - docker-launch.sh
49
52
  - docs/src-tree.md
50
53
  - ext/cumo/cuda/cublas.c
51
54
  - ext/cumo/cuda/cudnn.c
@@ -328,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
331
  - !ruby/object:Gem::Version
329
332
  version: '0'
330
333
  requirements: []
331
- rubygems_version: 3.7.2
334
+ rubygems_version: 4.0.4
332
335
  specification_version: 4
333
336
  summary: Cumo is CUDA aware numerical library whose interface is highly compatible
334
337
  with Ruby Numo