rbmetis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/matcher.rb ADDED
@@ -0,0 +1,15 @@
1
+ RSpec::Matchers.define :be_wpart_of do |_expected_|
2
+ match do |actual|
3
+ npart = _expected_.size
4
+ hist = [0]*npart
5
+ actual.each do |i|
6
+ hist[i] += 1
7
+ end
8
+ #p ["hist:",hist]
9
+ nvertex = actual.size
10
+ (0...npart).all? do |i|
11
+ x = _expected_[i] * nvertex
12
+ (x.round - hist[i]) <= 0.5
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ require "rspec"
2
+ dir = File.dirname(File.expand_path(__FILE__))
3
+ require dir+"/matcher.rb"
4
+ require dir+"/../lib/rbmetis"
5
+
6
+ def part_graph(type, *args)
7
+ case type.to_s
8
+ when /^r/i
9
+ RbMetis.part_graph_recursive(*args)
10
+ when /^k/i
11
+ RbMetis.part_graph_kway(*args)
12
+ end
13
+ end
14
+
15
+ describe "Graph[ 0 - 1 - 2 - 3 ]" do
16
+ before do
17
+ @xadj = [0,1,3,5,6]
18
+ @adjncy = [1, 0,2, 1,3, 2]
19
+ #@vwgt = [ [1,0], [1,0], [0,1], [0,1] ]
20
+ @vwgt = [ [1,0], [0,1], [1,0], [0,1] ]
21
+ end
22
+
23
+ %w[recursive kway].each do |tp|
24
+ it "mc_part_graph vwgt=[ [1,0], [1,0], [0,1], [0,1] ]" do
25
+ vwgt = [ [1,0], [1,0], [0,1], [0,1] ].flatten
26
+ part_graph(tp, @xadj, @adjncy, 2, ncon:2, vwgt:vwgt).should be_wpart_of [0.5,0.5]
27
+ end
28
+
29
+ it "mc_part_graph vwgt=[ [1,0], [0,1], [1,0], [0,1] ]" do
30
+ vwgt = [ [1,0], [0,1], [1,0], [0,1] ].flatten
31
+ part_graph(tp, @xadj, @adjncy, 2, ncon:2, vwgt:vwgt).should be_wpart_of [0.5,0.5]
32
+ end
33
+
34
+ it "mc_part_graph vwgt=[ 1,0, 0,1, 1,0, 0,1 ]" do
35
+ vwgt = [ 1,0, 0,1, 1,0, 0,1 ]
36
+ part_graph(tp, @xadj, @adjncy, 2, ncon:2, vwgt:vwgt).should be_wpart_of [0.5,0.5]
37
+ end
38
+ end
39
+
40
+ end
data/spec/part_spec.rb ADDED
@@ -0,0 +1,72 @@
1
+ require "rspec"
2
+ dir = File.dirname(File.expand_path(__FILE__))
3
+ require dir+"/matcher.rb"
4
+ require dir+"/../lib/rbmetis"
5
+
6
+ def part_graph(type, *args)
7
+ case type.to_s
8
+ when /^r/i
9
+ RbMetis.part_graph_recursive(*args)
10
+ when /^k/i
11
+ RbMetis.part_graph_kway(*args)
12
+ end
13
+ end
14
+
15
+ describe "RbMetis.default_options" do
16
+ it do
17
+ RbMetis.default_options.should eq [-1]*40
18
+ end
19
+ end
20
+
21
+ describe "Graph[ 0 - 1 - 2 - 3 ]" do
22
+ before do
23
+ @xadj = [0,1,3,5,6]
24
+ @adjncy = [1, 0,2, 1,3, 2]
25
+ end
26
+
27
+ %w[recursive kway].each do |tp|
28
+ it "part_graph_#{tp} 2:2" do
29
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.5,0.5]).should be_wpart_of [0.5,0.5]
30
+ end
31
+ end
32
+
33
+ %w[recursive].each do |tp|
34
+ it "part_graph_#{tp} 3:1" do
35
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.75,0.25]).should be_wpart_of [0.75,0.25]
36
+ end
37
+
38
+ it "part_graph_#{tp} 1:3" do
39
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.25,0.75]).should be_wpart_of [0.25,0.75]
40
+ end
41
+
42
+ it "part_graph_#{tp} 1:1:2" do
43
+ part_graph(tp, @xadj, @adjncy, 3, tpwgts:[0.25,0.25,0.5]).should be_wpart_of [0.25,0.25,0.5]
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+ describe "Graph[ 0 - 1 - 2 - 3 - 4 ]" do
50
+ before do
51
+ @xadj = [0,1,3,5,7,8]
52
+ @adjncy = [1, 0,2, 1,3, 2,4, 3]
53
+ end
54
+
55
+ %w[recursive].each do |tp|
56
+ it "part_graph_#{tp} 1:4" do
57
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.2,0.8]).should be_wpart_of [0.2,0.8]
58
+ end
59
+
60
+ it "part_graph_#{tp} 2:3" do
61
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.4,0.6]).should be_wpart_of [0.4,0.6]
62
+ end
63
+
64
+ it "part_graph_#{tp} 3:2" do
65
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.6,0.4]).should be_wpart_of [0.6,0.4]
66
+ end
67
+
68
+ it "part_graph_#{tp} 4:1" do
69
+ part_graph(tp, @xadj, @adjncy, 2, tpwgts:[0.8,0.2]).should be_wpart_of [0.8,0.2]
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbmetis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro TANAKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ffi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'FFI wrapper of METIS graph partitioning library version: 5.1.0 http://glaros.dtc.umn.edu/gkhome/metis/metis/overview'
56
+ email:
57
+ - masa16.tanaka@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - ext/extconf.rb
69
+ - lib/rbmetis.rb
70
+ - lib/rbmetis/lib.rb
71
+ - lib/rbmetis/main.rb
72
+ - lib/rbmetis/version.rb
73
+ - rbmetis.gemspec
74
+ - setup.rb
75
+ - spec/matcher.rb
76
+ - spec/mcpart_spec.rb
77
+ - spec/part_spec.rb
78
+ homepage: https://github.com/masa16/rbmetis
79
+ licenses:
80
+ - Apache License 2.0
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: FFI wrapper of METIS graph partitioning library
102
+ test_files:
103
+ - spec/matcher.rb
104
+ - spec/mcpart_spec.rb
105
+ - spec/part_spec.rb
106
+ has_rdoc: