munkres_ru 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9d5a7d8be0a0bea21da9178e20a6101b580b310
4
- data.tar.gz: 2d3ec35715ccafa1bc24ebbca5034fea4fe58eba
3
+ metadata.gz: 57aeb4d7f66e44074883ade147c4a2620fd6049c
4
+ data.tar.gz: cb677ace1ae5617f387210774775948fce641f45
5
5
  SHA512:
6
- metadata.gz: ebcb44fdfd40c042f862bff2bcad0392fac891cf1faa15f8b7b1b424c8087ae9e7e9097ecf8a7d99ece81fe3db22fec6a6f43e47ae05469356f6a5c709a1e0c0
7
- data.tar.gz: 58e0800b9c3f1e1dba993e7626856aaaec7f19f826d022942bd1ac1f786f5a9e1edf3c01ce4baf5df3983d36cb658dcac30ae799d9725c2636b09001f42aa496
6
+ metadata.gz: 784093d58e12dee58e8c754de8ba23e32ba9b505d1a907ca59b13174d1ccfdb97ea3d0e9df804b89496691c076ded0f1062e34b952791dcfba7746324b29e59d
7
+ data.tar.gz: 76e0a3364dd01447de753b8f210feffa1ee66e427bed9217a5a20bc263bc4a1dbeee458a311db8ee3f13b55ac010e71330364fdc84d65389d4279bd6e6b1e6ee
@@ -28,6 +28,10 @@ module MunkresRu
28
28
  pointer = FFI::MemoryPointer.new :double, flattened.size
29
29
  pointer.autorelease = false # Rust will take ownership of that memory
30
30
  pointer.put_array_of_double 0, flattened
31
- MunkresRu.solve_munkres(array.size, pointer).to_a.each_slice(2).to_a
31
+ solved = MunkresRu.solve_munkres(array.size, pointer).to_a
32
+ if solved == [-1]
33
+ raise 'Solving Munkres problem failed, check if input is valid'
34
+ end
35
+ solved.each_slice(2).to_a
32
36
  end
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module MunkresRu
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -22,15 +22,24 @@ impl Array {
22
22
 
23
23
  #[no_mangle]
24
24
  pub extern fn solve_munkres(n: libc::size_t, array: *mut libc::c_double) -> Array {
25
- let size = n as usize;
26
- let len = size*size;
27
- let vec = unsafe { Vec::from_raw_parts(array, len, len) };
28
- let mut weights: WeightMatrix<libc::c_double> = WeightMatrix::from_row_vec(size, vec);
29
- let matching = solve_assignment(&mut weights);
30
- let mut res = Vec::new();
31
- for &(row, col) in &matching[..] {
32
- res.push(row as libc::c_int);
33
- res.push(col as libc::c_int);
25
+ let res = ::std::panic::catch_unwind(|| {
26
+ let size = n as usize;
27
+ let len = size*size;
28
+ let vec = unsafe { Vec::from_raw_parts(array, len, len) };
29
+ for &v in &vec {
30
+ assert!(!v.is_nan());
31
+ }
32
+ let mut weights: WeightMatrix<libc::c_double> = WeightMatrix::from_row_vec(size, vec);
33
+ let matching = solve_assignment(&mut weights);
34
+ let mut res = Vec::new();
35
+ for &(row, col) in &matching[..] {
36
+ res.push(row as libc::c_int);
37
+ res.push(col as libc::c_int);
38
+ }
39
+ Array::from_vec(res)
40
+ });
41
+ match res {
42
+ Ok(array) => array,
43
+ Err(_) => Array::from_vec(vec![-1]),
34
44
  }
35
- Array::from_vec(res)
36
45
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: munkres_ru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Pirlik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-12 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,8 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project:
100
- rubygems_version: 2.4.5.1
100
+ rubygems_version: 2.4.5.2
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: Kuhn-Munkres implemented in Rust
104
104
  test_files: []
105
+ has_rdoc: