scs 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/scs/solver.rb +15 -7
- data/lib/scs/version.rb +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0383039079716cc0cd7087291d768ed2e9e5f615b78211a96e850e068c89e6bb'
|
4
|
+
data.tar.gz: 0dc5bd791bafcf2846e66e90ba7ac88fa93665e1b024c1041123df4e4c279007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6268655afd2200a7132125d86e4bde71c36325a8741857ed38a3b6e07686a042b310771f84df57e6b1756c00cc1c8ed1bc61b2e604b71133ba98a87471d45931
|
7
|
+
data.tar.gz: fce49c2615c517adb0d13362a053c3dd2534a4579fc9f1bc5a219c21ac471833e61827ac8587ebb8a07001350b93eca5f820166d8a638e47d8e45bc279c83c72
|
data/CHANGELOG.md
CHANGED
data/lib/scs/solver.rb
CHANGED
@@ -2,6 +2,7 @@ module SCS
|
|
2
2
|
class Solver
|
3
3
|
def initialize(indirect: false)
|
4
4
|
@ffi = indirect ? FFI::Indirect : FFI::Direct
|
5
|
+
@refs = []
|
5
6
|
end
|
6
7
|
|
7
8
|
def solve(data, cone, **settings)
|
@@ -10,7 +11,7 @@ module SCS
|
|
10
11
|
ccone = create_cone(cone)
|
11
12
|
|
12
13
|
solution = calloc(ffi::Solution.size) # alloc clear memory
|
13
|
-
info = ffi::Info.malloc
|
14
|
+
info = ffi::Info.malloc(Fiddle::RUBY_FREE)
|
14
15
|
|
15
16
|
ffi.scs(cdata, ccone, settings, solution, info)
|
16
17
|
|
@@ -45,6 +46,8 @@ module SCS
|
|
45
46
|
cone_time: info.cone_time,
|
46
47
|
accel_time: info.accel_time
|
47
48
|
}
|
49
|
+
ensure
|
50
|
+
@refs.clear
|
48
51
|
end
|
49
52
|
|
50
53
|
private
|
@@ -55,7 +58,9 @@ module SCS
|
|
55
58
|
|
56
59
|
def float_array(arr)
|
57
60
|
# SCS float = double
|
58
|
-
Fiddle::Pointer[arr.to_a.pack("d*")]
|
61
|
+
ptr = Fiddle::Pointer[arr.to_a.pack("d*")]
|
62
|
+
@refs << ptr
|
63
|
+
ptr
|
59
64
|
end
|
60
65
|
|
61
66
|
def read_float_array(ptr, size)
|
@@ -65,7 +70,9 @@ module SCS
|
|
65
70
|
|
66
71
|
def int_array(arr)
|
67
72
|
# SCS int = int
|
68
|
-
Fiddle::Pointer[arr.to_a.pack("i!*")]
|
73
|
+
ptr = Fiddle::Pointer[arr.to_a.pack("i!*")]
|
74
|
+
@refs << ptr
|
75
|
+
ptr
|
69
76
|
end
|
70
77
|
|
71
78
|
def read_string(char_ptr)
|
@@ -89,12 +96,13 @@ module SCS
|
|
89
96
|
csc = mtx.to_csc
|
90
97
|
|
91
98
|
# construct matrix
|
92
|
-
matrix = ffi::Matrix.malloc
|
99
|
+
matrix = ffi::Matrix.malloc(Fiddle::RUBY_FREE)
|
93
100
|
matrix.x = float_array(csc[:value])
|
94
101
|
matrix.i = int_array(csc[:index])
|
95
102
|
matrix.p = int_array(csc[:start])
|
96
103
|
matrix.m = mtx.m
|
97
104
|
matrix.n = mtx.n
|
105
|
+
@refs << matrix
|
98
106
|
matrix
|
99
107
|
end
|
100
108
|
|
@@ -112,7 +120,7 @@ module SCS
|
|
112
120
|
|
113
121
|
def create_data(data)
|
114
122
|
m, n = shape(data[:a])
|
115
|
-
cdata = ffi::Data.malloc
|
123
|
+
cdata = ffi::Data.malloc(Fiddle::RUBY_FREE)
|
116
124
|
cdata.m = m
|
117
125
|
cdata.n = n
|
118
126
|
cdata.a = csc_matrix(data[:a])
|
@@ -131,7 +139,7 @@ module SCS
|
|
131
139
|
end
|
132
140
|
|
133
141
|
def create_cone(cone)
|
134
|
-
ccone = ffi::Cone.malloc
|
142
|
+
ccone = ffi::Cone.malloc(Fiddle::RUBY_FREE)
|
135
143
|
ccone.z = cone[:z].to_i
|
136
144
|
ccone.l = cone[:l].to_i
|
137
145
|
ccone.bu = float_array(cone[:bu])
|
@@ -152,7 +160,7 @@ module SCS
|
|
152
160
|
end
|
153
161
|
|
154
162
|
def create_settings(settings)
|
155
|
-
set = ffi::Settings.malloc
|
163
|
+
set = ffi::Settings.malloc(Fiddle::RUBY_FREE)
|
156
164
|
ffi.scs_set_default_settings(set)
|
157
165
|
|
158
166
|
# hack for setting members with []=
|
data/lib/scs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: fiddle
|
@@ -24,7 +23,6 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0'
|
27
|
-
description:
|
28
26
|
email: andrew@ankane.org
|
29
27
|
executables: []
|
30
28
|
extensions:
|
@@ -138,7 +136,6 @@ homepage: https://github.com/ankane/scs-ruby
|
|
138
136
|
licenses:
|
139
137
|
- MIT
|
140
138
|
metadata: {}
|
141
|
-
post_install_message:
|
142
139
|
rdoc_options: []
|
143
140
|
require_paths:
|
144
141
|
- lib
|
@@ -153,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
150
|
- !ruby/object:Gem::Version
|
154
151
|
version: '0'
|
155
152
|
requirements: []
|
156
|
-
rubygems_version: 3.
|
157
|
-
signing_key:
|
153
|
+
rubygems_version: 3.6.7
|
158
154
|
specification_version: 4
|
159
155
|
summary: SCS - the splitting conic solver - for Ruby
|
160
156
|
test_files: []
|