ruby-gr 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -0
- data/README.md +12 -10
- data/lib/gr.rb +339 -292
- data/lib/gr/ffi.rb +188 -180
- data/lib/gr/grbase.rb +1 -0
- data/lib/gr/plot.rb +1344 -0
- data/lib/gr/plot.rb.md +207 -0
- data/lib/gr3.rb +99 -81
- data/lib/gr3/ffi.rb +114 -78
- data/lib/gr3/gr3base.rb +5 -0
- data/lib/gr_commons.rb +1 -1
- data/lib/gr_commons/define_methods.rb +3 -1
- data/lib/gr_commons/extern.rb +16 -0
- data/lib/gr_commons/fiddley.rb +419 -0
- data/lib/gr_commons/gr_common_utils.rb +19 -48
- data/lib/gr_commons/jupyter_support.rb +5 -2
- data/lib/gr_commons/version.rb +1 -1
- metadata +37 -20
- data/lib/gr_commons/attach_function.rb +0 -15
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'gr_commons/fiddley'
|
4
|
+
|
3
5
|
module GRCommons
|
4
6
|
# This module provides functionality common to GR and GR3.
|
5
7
|
module GRCommonUtils
|
@@ -7,45 +9,23 @@ module GRCommons
|
|
7
9
|
|
8
10
|
def equal_length(*args)
|
9
11
|
lengths = args.map(&:length)
|
10
|
-
|
12
|
+
unless lengths.all? { |l| l == lengths[0] }
|
13
|
+
raise ArgumentError,
|
14
|
+
'Sequences must have same length.'
|
15
|
+
end
|
11
16
|
|
12
17
|
lengths[0]
|
13
18
|
end
|
14
19
|
|
15
|
-
|
16
|
-
data = data.to_a.flatten
|
17
|
-
pt = ::FFI::MemoryPointer.new(:uint8, data.size)
|
18
|
-
pt.write_array_of_uint8 data
|
19
|
-
end
|
20
|
-
|
21
|
-
def uint16(data)
|
22
|
-
data = data.to_a.flatten
|
23
|
-
pt = ::FFI::MemoryPointer.new(:uint16, data.size)
|
24
|
-
pt.write_array_of_uint16 data
|
25
|
-
end
|
26
|
-
|
27
|
-
def int(data)
|
28
|
-
data = data.to_a.flatten
|
29
|
-
pt = ::FFI::MemoryPointer.new(:int, data.size)
|
30
|
-
pt.write_array_of_int data
|
31
|
-
end
|
32
|
-
|
33
|
-
def uint(data)
|
34
|
-
data = data.to_a.flatten
|
35
|
-
pt = ::FFI::MemoryPointer.new(:uint, data.size)
|
36
|
-
pt.write_array_of_uint data
|
37
|
-
end
|
38
|
-
|
39
|
-
def double(data)
|
40
|
-
data = data.to_a.flatten
|
41
|
-
pt = ::FFI::MemoryPointer.new(:double, data.size)
|
42
|
-
pt.write_array_of_double data
|
43
|
-
end
|
20
|
+
SUPPORTED_TYPES = %i[uint8 uint16 int uint double float].freeze
|
44
21
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
22
|
+
# NOTE: The following method converts Ruby Array or NArray into packed string.
|
23
|
+
SUPPORTED_TYPES.each do |type|
|
24
|
+
define_method(type) do |data|
|
25
|
+
# FIXME: Use NArray#to_string
|
26
|
+
data = data.to_a.flatten
|
27
|
+
Fiddley::Utils.array2str(type, data)
|
28
|
+
end
|
49
29
|
end
|
50
30
|
|
51
31
|
def inquiry_int(&block)
|
@@ -63,9 +43,9 @@ module GRCommons
|
|
63
43
|
def inquiry(types)
|
64
44
|
case types
|
65
45
|
when Hash, Symbol
|
66
|
-
|
67
|
-
yield(
|
68
|
-
read_ffi_pointer(
|
46
|
+
ptr = create_ffi_pointer(types)
|
47
|
+
yield(ptr)
|
48
|
+
read_ffi_pointer(ptr, types)
|
69
49
|
when Array
|
70
50
|
pts = types.map { |type| create_ffi_pointer(type) }
|
71
51
|
yield(*pts)
|
@@ -80,9 +60,9 @@ module GRCommons
|
|
80
60
|
when Hash
|
81
61
|
typ = type.keys[0]
|
82
62
|
len = type.values[0]
|
83
|
-
::
|
63
|
+
Fiddley::MemoryPointer.new(typ, len)
|
84
64
|
else
|
85
|
-
::
|
65
|
+
Fiddley::MemoryPointer.new(type)
|
86
66
|
end
|
87
67
|
end
|
88
68
|
|
@@ -102,12 +82,3 @@ module GRCommons
|
|
102
82
|
end
|
103
83
|
end
|
104
84
|
end
|
105
|
-
|
106
|
-
# Ruby 2.4.0 introduces Comparable#clamp
|
107
|
-
if RUBY_VERSION.to_f <= 2.3
|
108
|
-
class Numeric
|
109
|
-
def clamp(min, max)
|
110
|
-
[[self, max].min, min].max
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -24,8 +24,11 @@ module GRCommons
|
|
24
24
|
when 'webm', 'ogg', 'mp4', 'mov'
|
25
25
|
require 'base64'
|
26
26
|
data = File.binread(ENV['GKS_FILEPATH'] + '.' + type)
|
27
|
-
IRuby.display(
|
28
|
-
|
27
|
+
IRuby.display(
|
28
|
+
"<video controls autoplay type=\"video/#{type}\" " \
|
29
|
+
"src=\"data:video/#{type};base64,#{Base64.encode64(data)}\">",
|
30
|
+
mime: 'text/html'
|
31
|
+
)
|
29
32
|
end
|
30
33
|
nil
|
31
34
|
end
|
data/lib/gr_commons/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-gr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: ffi
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +25,7 @@ dependencies:
|
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '2.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: histogram
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
@@ -108,6 +94,34 @@ dependencies:
|
|
108
94
|
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: test-unit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: wavefile
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,18 +147,21 @@ files:
|
|
133
147
|
- lib/gr.rb
|
134
148
|
- lib/gr/ffi.rb
|
135
149
|
- lib/gr/grbase.rb
|
150
|
+
- lib/gr/plot.rb
|
151
|
+
- lib/gr/plot.rb.md
|
136
152
|
- lib/gr/version.rb
|
137
153
|
- lib/gr3.rb
|
138
154
|
- lib/gr3/ffi.rb
|
139
155
|
- lib/gr3/gr3base.rb
|
140
156
|
- lib/gr3/version.rb
|
141
157
|
- lib/gr_commons.rb
|
142
|
-
- lib/gr_commons/attach_function.rb
|
143
158
|
- lib/gr_commons/define_methods.rb
|
159
|
+
- lib/gr_commons/extern.rb
|
160
|
+
- lib/gr_commons/fiddley.rb
|
144
161
|
- lib/gr_commons/gr_common_utils.rb
|
145
162
|
- lib/gr_commons/jupyter_support.rb
|
146
163
|
- lib/gr_commons/version.rb
|
147
|
-
homepage: https://github.com/
|
164
|
+
homepage: https://github.com/red-data-tools/GR.rb
|
148
165
|
licenses:
|
149
166
|
- MIT
|
150
167
|
metadata: {}
|
@@ -156,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
173
|
requirements:
|
157
174
|
- - ">="
|
158
175
|
- !ruby/object:Gem::Version
|
159
|
-
version: '2.
|
176
|
+
version: '2.4'
|
160
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
178
|
requirements:
|
162
179
|
- - ">="
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GRCommons
|
4
|
-
# This module modifies the behavior of the attach_function method.
|
5
|
-
module AttachFunction
|
6
|
-
# Remember added method name
|
7
|
-
def attach_function(name, *args)
|
8
|
-
@ffi_methods ||= []
|
9
|
-
@ffi_methods << name
|
10
|
-
super(name, *args)
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :ffi_methods
|
14
|
-
end
|
15
|
-
end
|