ruby-gr 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,8 @@ module GRCommons
5
5
  module DefineMethods
6
6
  private
7
7
 
8
- def define_ffi_methods(ffi_class, prefix: '', default_type: :double)
9
- ffi_class.ffi_methods.each do |method|
8
+ def define_ffi_methods(ffi_module, prefix: '', default_type: :double)
9
+ ffi_module.ffi_methods.each do |method|
10
10
  # Use delete_prefix (Ruby >= 2.5)
11
11
  method_name = method.to_s.sub(/^#{prefix}/, '')
12
12
 
@@ -16,14 +16,14 @@ module GRCommons
16
16
  args.map! do |arg|
17
17
  case arg
18
18
  when Array
19
- GRCommons::GRCommonUtils.send(default_type, arg)
19
+ GRCommons::GRCommonUtils.public_send(default_type, arg)
20
20
  when ->(x) { defined?(Numo::NArray) && x.is_a?(Numo::NArray) }
21
- GRCommons::GRCommonUtils.send(default_type, arg)
21
+ GRCommons::GRCommonUtils.public_send(default_type, arg)
22
22
  else
23
23
  arg
24
24
  end
25
25
  end
26
- ffi_class.send(method, *args)
26
+ ffi_module.public_send(method, *args)
27
27
  end
28
28
  end
29
29
  end
@@ -210,7 +210,7 @@ module GRCommons
210
210
  end
211
211
 
212
212
  define_method("put_array_of_int#{bits}") do |offset, ary|
213
- put_bytes(offset, ary.pack(form + '*'))
213
+ put_bytes(offset, ary.pack("#{form}*"))
214
214
  end
215
215
 
216
216
  define_method("write_array_of_int#{bits}") do |ary|
@@ -226,7 +226,7 @@ module GRCommons
226
226
  end
227
227
 
228
228
  define_method("get_array_of_int#{bits}") do |offset, num|
229
- @ptr[offset, bytes * num].unpack(form + '*')
229
+ @ptr[offset, bytes * num].unpack("#{form}*")
230
230
  end
231
231
 
232
232
  define_method("read_array_of_int#{bits}") do |num|
@@ -244,7 +244,7 @@ module GRCommons
244
244
  end
245
245
 
246
246
  define_method("put_array_of_uint#{bits}") do |offset, ary|
247
- put_bytes(offset, ary.pack(form2 + '*'))
247
+ put_bytes(offset, ary.pack("#{form2}*"))
248
248
  end
249
249
 
250
250
  define_method("write_array_of_uint#{bits}") do |ary|
@@ -260,7 +260,7 @@ module GRCommons
260
260
  end
261
261
 
262
262
  define_method("get_array_of_uint#{bits}") do |offset, num|
263
- @ptr[offset, bytes * num].unpack(form2 + '*')
263
+ @ptr[offset, bytes * num].unpack("#{form2}*")
264
264
  end
265
265
 
266
266
  define_method("read_array_of_uint#{bits}") do |num|
@@ -330,12 +330,12 @@ module GRCommons
330
330
 
331
331
  # added
332
332
  define_method('get_array_of_double') do |offset, num|
333
- @ptr[offset, 8 * num].unpack('d' + '*')
333
+ @ptr[offset, 8 * num].unpack('d*')
334
334
  end
335
335
 
336
336
  # added
337
337
  define_method('get_array_of_float') do |offset, num|
338
- @ptr[offset, 4 * num].unpack('f' + '*')
338
+ @ptr[offset, 4 * num].unpack('f*')
339
339
  end
340
340
 
341
341
  # added
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'gr_commons/fiddley'
3
+ require_relative 'fiddley'
4
4
 
5
5
  module GRCommons
6
6
  # This module provides functionality common to GR and GR3.
@@ -43,7 +43,7 @@ module GRCommons
43
43
  if narray?(data)
44
44
  Numo::Int32.cast(data).to_binary
45
45
  else
46
- Fiddley::Utils.array2str(:int32, data.to_a.flatten)
46
+ Fiddley::Utils.array2str(:int32, data.to_a.flatten) # TODO
47
47
  end
48
48
  end
49
49
 
@@ -52,7 +52,7 @@ module GRCommons
52
52
  if narray?(data)
53
53
  Numo::UInt32.cast(data).to_binary
54
54
  else
55
- Fiddley::Utils.array2str(:uint, data.to_a.flatten)
55
+ Fiddley::Utils.array2str(:uint, data.to_a.flatten) # TODO
56
56
  end
57
57
  end
58
58
 
@@ -117,9 +117,9 @@ module GRCommons
117
117
  when Hash
118
118
  typ = type.keys[0]
119
119
  len = type.values[0]
120
- pt.send("read_array_of_#{typ}", len)
120
+ pt.public_send("read_array_of_#{typ}", len)
121
121
  else
122
- pt.send("read_#{type}")
122
+ pt.public_send("read_#{type}")
123
123
  end
124
124
  end
125
125
 
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This script was created primarily for debugging purposes.
4
+ # Note: This script should be isolated.
5
+ # It should not be loaded when gr_commons/gr_commons is loaded.
6
+
7
+ require 'logger'
8
+ require 'rainbow'
9
+ require 'awesome_print'
10
+
11
+ module GRCommons
12
+ class << self
13
+ # Create a new GRLogger
14
+ # @params out [String]
15
+ # @return [GRLogger]
16
+ # @example
17
+ # require 'gr_commons/gr_logger'
18
+ # GRCommons.gr_log("log.txt")
19
+ def gr_log(out = $stderr)
20
+ GRCommons::GRLogger.new(out)
21
+ end
22
+
23
+ # Return the last created GRLogger
24
+ # @return [GRLogger]
25
+ def gr_logger
26
+ GRCommons::GRLogger.logger
27
+ end
28
+ end
29
+
30
+ # Outputs function calls to GR Framework to a log file.
31
+ # Mainly used for debugging.
32
+ # @note This module is for those who want to see low-level function calls in GR.
33
+ #
34
+ # = How it works 
35
+ # prepend a module named Inspector to the singular class
36
+ # of the FFI module. It will inspects the GR function call of the FFI module
37
+ #
38
+ # @example
39
+ # require 'gr_commons/gr_logger'
40
+ # GRCommons.gr_log("log.txt")
41
+ class GRLogger < Logger
42
+ # Return the last created GRLogger
43
+ def self.logger
44
+ @@logger ||= GRCommons::GRLogger.new
45
+ end
46
+
47
+ def initialize(out = $stderr)
48
+ super(out, level: :info)
49
+ @@logger ||= self
50
+ end
51
+ end
52
+ end
53
+
54
+ if Object.const_defined?(:GR)
55
+ module GR
56
+ module FFI
57
+ module Inspector
58
+ GR::FFI.ffi_methods.each do |s|
59
+ define_method(s) do |*args|
60
+ GRCommons.gr_logger.info "GR::FFI.#{s}\n" + args.ai + "\n"
61
+ super(*args)
62
+ end
63
+ end
64
+ end
65
+ class << self
66
+ prepend Inspector
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ if Object.const_defined?(:GR3)
73
+ module GR3
74
+ module FFI
75
+ module Inspector
76
+ GR3::FFI.ffi_methods.each do |s|
77
+ define_method(s) do |*args|
78
+ GRCommons.gr_logger.info "GR3::FFI.#{s}\n" + args.ai + "\n"
79
+ super(*args)
80
+ end
81
+ end
82
+ end
83
+ class << self
84
+ prepend Inspector
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ if Object.const_defined?(:GRM)
91
+ module GRM
92
+ module FFI
93
+ module Inspector
94
+ GRM::FFI.ffi_methods.each do |s|
95
+ define_method(s) do |*args|
96
+ GRCommons.gr_logger.info "GRM::FFI.#{s}\n" + args.ai + "\n"
97
+ super(*args)
98
+ end
99
+ end
100
+ end
101
+ class << self
102
+ prepend Inspector
103
+ end
104
+ end
105
+ end
106
+ end
@@ -19,16 +19,16 @@ module GRCommons
19
19
  type = ENV['GKSwstype']
20
20
  case type
21
21
  when 'svg'
22
- data = File.read(ENV['GKS_FILEPATH'] + '.svg')
22
+ data = File.read("#{ENV['GKS_FILEPATH']}.svg")
23
23
  IRuby.display(data, mime: 'image/svg+xml') if display
24
24
  when 'png', '322', '140'
25
- data = File.read(ENV['GKS_FILEPATH'] + '.png')
25
+ data = File.read("#{ENV['GKS_FILEPATH']}.png")
26
26
  IRuby.display(data, mime: 'image/png') if display
27
27
  when 'jpg', '321', '144'
28
- data = File.read(ENV['GKS_FILEPATH'] + '.jpg')
28
+ data = File.read("#{ENV['GKS_FILEPATH']}.jpg")
29
29
  IRuby.display(data, mime: 'image/jpeg') if display
30
30
  when 'gif', '130'
31
- data = File.read(ENV['GKS_FILEPATH'] + '.gif')
31
+ data = File.read("#{ENV['GKS_FILEPATH']}.gif")
32
32
  IRuby.display(data, mime: 'image/gif') if display
33
33
  when 'webm', 'ogg', 'mp4', 'mov'
34
34
  require 'base64'
@@ -37,7 +37,7 @@ module GRCommons
37
37
  else
38
38
  "video/#{type}"
39
39
  end
40
- data = File.binread(ENV['GKS_FILEPATH'] + '.' + type)
40
+ data = File.binread("#{ENV['GKS_FILEPATH']}.#{type}")
41
41
  if display
42
42
  IRuby.display(
43
43
  "<video autoplay controls><source type=\"#{mimespec}\" " \
@@ -54,10 +54,11 @@ module GRCommons
54
54
 
55
55
  def recursive_search(name, base_dir)
56
56
  Dir.chdir(base_dir) do
57
- if path = Dir["**/#{name}"].first # FIXME
57
+ path = Dir["**/#{name}"].first # FIXME
58
+ if path
58
59
  File.expand_path(path)
59
60
  else
60
- raise StandardError "#{name} not found in #{base_dir}"
61
+ raise "#{name} not found in #{base_dir}"
61
62
  end
62
63
  end
63
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.23'
4
+ VERSION = '0.0.24'
5
5
  end
@@ -42,7 +42,6 @@ module GRM
42
42
  # https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
43
43
  try_extern 'int grm_input(const grm_args_t *input_args)'
44
44
  try_extern 'int grm_get_box(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, int *x, int *y, int *w, int *h)'
45
- try_extern 'grm_input(const grm_args_t *input_args)'
46
45
  try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
47
46
 
48
47
  # https://github.com/sciapp/gr/blob/master/lib/grm/net.h
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-22 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: histogram
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: fiddle
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: pry
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +148,6 @@ files:
162
148
  - lib/gr/ffi.rb
163
149
  - lib/gr/grbase.rb
164
150
  - lib/gr/plot.rb
165
- - lib/gr/plot.rb.md
166
151
  - lib/gr/version.rb
167
152
  - lib/gr3.rb
168
153
  - lib/gr3/ffi.rb
@@ -173,6 +158,7 @@ files:
173
158
  - lib/gr_commons/fiddley.rb
174
159
  - lib/gr_commons/gr_common_utils.rb
175
160
  - lib/gr_commons/gr_commons.rb
161
+ - lib/gr_commons/gr_logger.rb
176
162
  - lib/gr_commons/jupyter_support.rb
177
163
  - lib/gr_commons/search_shared_library.rb
178
164
  - lib/gr_commons/version.rb
@@ -200,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
186
  - !ruby/object:Gem::Version
201
187
  version: '0'
202
188
  requirements: []
203
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.1.4
204
190
  signing_key:
205
191
  specification_version: 4
206
192
  summary: GR for Ruby
@@ -1,172 +0,0 @@
1
- This is a memo to think about the structure of Plot/Figure.
2
-
3
- ````ruby
4
-
5
- module GR
6
- # object oriented way
7
- class PlotBase
8
- end
9
-
10
- class Line < PlotBase
11
- end
12
-
13
- class << self
14
- def set_viewport; end
15
-
16
- def minmax; end
17
-
18
- def set_window; end
19
-
20
- def draw_axes; end
21
-
22
- def draw_polar_axes; end
23
-
24
- def _inqtext; end
25
-
26
- def _text; end
27
-
28
- def draw_legend; end
29
-
30
- def draw_colorbar; end
31
-
32
- def colormap; end
33
-
34
- def to_rgba; end
35
-
36
- # Ruby is object-oriented language.
37
- # Julia is more functional...
38
- # def create_context
39
- # end
40
- # def restore_context
41
- # end
42
- # def figure
43
- # end
44
-
45
- # def hold
46
- # end
47
- # def usecolorscheme
48
- # end
49
-
50
- # Set current subplot index.
51
- def subplot; end
52
-
53
- # draw_grid
54
-
55
- # xticks
56
- # yticks
57
- # zticks
58
-
59
- # xticklabels
60
- # yticklabels
61
-
62
- def plot_img; end # should be private?
63
-
64
- def plot_iso; end # should be private?
65
-
66
- def plot_polar; end # should be private?
67
-
68
- # send_meta
69
-
70
- def plot_data; end # should be private?
71
-
72
- def plot_args; end # should be private?
73
-
74
- # Draw one or more line plots.
75
- def plot; end
76
-
77
- # def plot_line_over oplot_line ?
78
-
79
- # Draw one or more step or staircase plots.
80
- def step; end
81
-
82
- # Draw one or more scatter plots.
83
- def scatter; end
84
-
85
- # Draw a stem plot.
86
- def stem; end
87
-
88
- # Draw a bar plot.
89
- def barplot; end
90
-
91
- def hist; end # should be private?
92
-
93
- # Draw a histogram.
94
- def histgram; end
95
-
96
- # Draw a polar histogram.
97
- def polarhistogram; end
98
-
99
- # Draw a contour plot.
100
- def contour; end
101
- # GR.contour is already defined in GR::FFI class.
102
-
103
- # Draw a filled contour plot.
104
- def contourf; end
105
- # GR.contourf is already defined in GR::FFI class.
106
-
107
- # Draw a hexagon binning plot.
108
- def hexbin; end
109
- # GR.hexbin is already defined in GR::FFI class.
110
-
111
- # Draw a heatmap.
112
- def heatmap; end
113
-
114
- def polarheatmap; end
115
-
116
- # Draw a three-dimensional wireframe plot.
117
- def wireframe; end
118
-
119
- # Draw a three-dimensional surface plot.
120
- def surface; end
121
-
122
- def volume; end
123
-
124
- # Draw one or more three-dimensional line plots.
125
- def plot3; end
126
-
127
- # Draw one or more three-dimensional scatter plots.
128
- def scatter3; end
129
-
130
- def redraw; end
131
-
132
- def title; end
133
-
134
- def xlabel; end
135
-
136
- def ylabel; end
137
-
138
- def legend; end
139
-
140
- def xlim; end
141
-
142
- def ylim; end
143
-
144
- def savefig; end
145
-
146
- def meshgrid; end # should be private ?
147
-
148
- def peaks; end # should be private ?
149
-
150
- def imshow; end
151
-
152
- # Draw an isosurface.
153
- def isosurface; end
154
-
155
- # Draw one or more polar plots.
156
- def polar; end
157
-
158
- # Draw a triangular surface plot.
159
- def trisurf; end
160
-
161
- # Draw a triangular contour plot.
162
- def tricont; end
163
-
164
- def shade; end
165
-
166
- # def set_panzoom ?
167
-
168
- # mainloop
169
- end
170
- end
171
-
172
- ```