ruby-gr 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/gr.rb +46 -37
- data/lib/gr/grbase.rb +2 -3
- data/lib/gr/plot.rb +81 -50
- data/lib/gr3.rb +45 -38
- data/lib/gr3/gr3base.rb +2 -3
- data/lib/gr_commons/define_methods.rb +2 -2
- data/lib/gr_commons/fiddley.rb +1 -1
- data/lib/gr_commons/gr_common_utils.rb +53 -27
- data/lib/gr_commons/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1884c5391124334045320390f35efd167865a6f1f063e6b763228c707cad400
|
4
|
+
data.tar.gz: '07929d47c8a49344fb625526b34f170b1fd0da2cfbddf538bef39f29ef122ec8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 132db88979be43ca20834522630d5970442a3565b7b14d6dafb5d970b7706b39112f56b83ab223c804e129ec9fcc612812ee691fa181d0dcdf7a86643ab7ba4b
|
7
|
+
data.tar.gz: 7bc7e311d1c22d81afada8611c1775b93a477c80d52b545c665975a8736a4fdb25dfcbde2c44604eb616c8018ab918148ba5b280166d228fae6205aa98b31322
|
data/README.md
CHANGED
@@ -92,6 +92,8 @@ Set environment variable GRDIR.
|
|
92
92
|
export GRDIR="your/path/to/gr"
|
93
93
|
```
|
94
94
|
|
95
|
+
* macOS Catalina and macOS Mojave: See the "How to open an app that hasn’t been notarized or is from an unidentified developer" section of [Safely open apps on your Mac](https://support.apple.com/en-us/HT202491) in the Apple documentation.
|
96
|
+
|
95
97
|
### Homebrew
|
96
98
|
|
97
99
|
```sh
|
@@ -106,9 +108,13 @@ export GRDIR=$(brew --prefix libgr)
|
|
106
108
|
|
107
109
|
If you fail to build libgr using homebrew, Please feel free to [send us your feedback](https://github.com/red-data-tools/GR.rb/issues).
|
108
110
|
|
111
|
+
### Red data tools repository
|
112
|
+
|
113
|
+
Red data tools provides [packages](https://github.com/red-data-tools/packages.red-data-tools.org ) related to our project including `libgr-dev` and `libgr3-dev` for advanced users.
|
114
|
+
|
109
115
|
## Backend for Charty
|
110
116
|
|
111
|
-
GR.rb
|
117
|
+
GR.rb will be the default backend for [Charty](https://github.com/red-data-tools/charty).
|
112
118
|
|
113
119
|
## Contributing
|
114
120
|
|
@@ -116,8 +122,9 @@ GR.rb is expected to be the backend for [Charty](https://github.com/red-data-too
|
|
116
122
|
* Fix bugs and submit pull requests
|
117
123
|
* Write, clarify, or fix documentation
|
118
124
|
* Suggest or add new features
|
125
|
+
* Create visualization library based on GR.rb
|
119
126
|
|
120
127
|
## Acknowledgements
|
121
128
|
|
122
|
-
We would like to thank Josef Heinen, the creator of [GR.jl](https://github.com/jheinen/GR.jl)
|
129
|
+
We would like to thank Josef Heinen, the creator of [GR.jl](https://github.com/jheinen/GR.jl), Florian Rhiem, the creator of [python-gr](https://github.com/sciapp/python-gr), and [GR](https://github.com/sciapp/gr) developers.
|
123
130
|
|
data/lib/gr.rb
CHANGED
@@ -2,40 +2,46 @@
|
|
2
2
|
|
3
3
|
# OverView of GR.rb
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
5
|
+
# +--------------------+ +--------------------+
|
6
|
+
# | GR module | | GR3 module |
|
7
|
+
# | +----------------+ | | +----------------+ |
|
8
|
+
# | | GR::FFI | | | | GR3::FFI | |
|
9
|
+
# | | + libGR.so | | | | + libGR3.so | |
|
10
|
+
# | +----------------+ | | +----------------+ |
|
11
|
+
# | | define_method | | | define_method |
|
12
|
+
# | +----------------+ | | +----------------+ |
|
13
|
+
# | | | GR::GRBase | | | | | GR3::GR3Base | |
|
14
|
+
# | | v (Pri^ate) | | | | v (Pri^ate) | |
|
15
|
+
# | +++--------------+ | | +++--------------+ |
|
16
|
+
# | | Extend | | | Extend |
|
17
|
+
# | v | | v +-------+ |
|
18
|
+
# | +-----------+ | | | Check | |
|
19
|
+
# | | GR::Plot | | | <--+ Error | |
|
20
|
+
# | +-----------+ | | +-------+ |
|
21
|
+
# +--------------------+ +----------+---------+
|
22
|
+
# ^ ^
|
23
|
+
# | +------------------+ |
|
24
|
+
# Extend | | GRCommons module | | Extend
|
25
|
+
# | | +--------------+ | |
|
26
|
+
# | | | Fiddley | | |
|
27
|
+
# | | +--------------+ | |
|
28
|
+
# | | +--------------+ | |
|
29
|
+
# +----+ CommonUtils +----+
|
30
|
+
# | | +--------------+ | |
|
31
|
+
# | | +--------------+ | |
|
32
|
+
# +----+ Version +----+
|
33
|
+
# | | +--------------+ |
|
34
|
+
# | | +--------------+ |
|
35
|
+
# +----+JupyterSupport| |
|
36
|
+
# | +--------------+ |
|
37
|
+
# +------------------+
|
38
|
+
#
|
39
|
+
# (You can edit the above AA diagram with http://asciiflow.com/))
|
40
|
+
#
|
41
|
+
# Fiddley is Ruby-FFI compatible API layer for Fiddle.
|
37
42
|
#
|
38
43
|
# The GR module works without Numo::Narrray.
|
44
|
+
# GR3 and GR::Plot depends on numo-narray.
|
39
45
|
#
|
40
46
|
# This is a procedural interface to the GR plotting library,
|
41
47
|
# https://github.com/sciapp/gr
|
@@ -59,7 +65,7 @@ module GR
|
|
59
65
|
self.ffi_lib = File.expand_path('lib/libGR.so', ENV['GRDIR'])
|
60
66
|
end
|
61
67
|
|
62
|
-
# Change the default encoding to UTF-8
|
68
|
+
# Change the default encoding to UTF-8.
|
63
69
|
ENV['GKS_ENCODING'] ||= 'utf8'
|
64
70
|
|
65
71
|
require_relative 'gr_commons/gr_commons'
|
@@ -67,16 +73,19 @@ module GR
|
|
67
73
|
require_relative 'gr/ffi'
|
68
74
|
require_relative 'gr/grbase'
|
69
75
|
|
76
|
+
# `inquiry` methods etc. are defined here.
|
77
|
+
extend GRCommons::GRCommonUtils
|
78
|
+
|
79
|
+
# Support for Jupyter Notebook / Lab.
|
70
80
|
extend GRCommons::JupyterSupport
|
71
81
|
|
72
|
-
# `double` is the default type in GR
|
82
|
+
# `double` is the default type in GR.
|
73
83
|
# A Ruby array or NArray passed to GR method is automatically converted to
|
74
|
-
# a
|
84
|
+
# a Fiddley::MemoryPointer in the GRBase class.
|
75
85
|
extend GRBase
|
76
86
|
|
77
87
|
# Now you can see a lot of methods just calling super here.
|
78
|
-
#
|
79
|
-
# Yes. They are written to help the yard generate the documentation.
|
88
|
+
# They are written to help the yard generate the documentation.
|
80
89
|
class << self
|
81
90
|
def initgr(*)
|
82
91
|
super
|
data/lib/gr/grbase.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GR
|
4
|
-
# This module automatically converts Ruby arrays and Numo::Narray into
|
4
|
+
# This module automatically converts Ruby arrays and Numo::Narray into
|
5
|
+
# Fiddley::MemoryPointer.
|
5
6
|
module GRBase
|
6
7
|
extend GRCommons::DefineMethods
|
7
8
|
define_ffi_methods(FFI,
|
@@ -9,6 +10,4 @@ module GR
|
|
9
10
|
default_type: :double)
|
10
11
|
end
|
11
12
|
private_constant :GRBase
|
12
|
-
|
13
|
-
extend GRCommons::GRCommonUtils
|
14
13
|
end
|
data/lib/gr/plot.rb
CHANGED
@@ -43,9 +43,9 @@ module GR
|
|
43
43
|
xform xlabel xlim xlog yflip ylabel ylim ylog zflip zlabel zlim
|
44
44
|
zlog clim subplot].freeze
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
@last_plot = nil
|
47
|
+
class << self
|
48
|
+
attr_accessor :last_plot
|
49
49
|
end
|
50
50
|
|
51
51
|
def initialize(*args)
|
@@ -64,14 +64,14 @@ module GR
|
|
64
64
|
|
65
65
|
@args = plot_args(args) # method name is the same as Julia/Python
|
66
66
|
@kvs[:size] ||= [600, 450]
|
67
|
-
@kvs[:ax]
|
67
|
+
@kvs[:ax] = false if @kvs[:ax].nil?
|
68
68
|
@kvs[:subplot] ||= [0, 1, 0, 1]
|
69
|
-
@kvs[:clear]
|
70
|
-
@kvs[:update]
|
69
|
+
@kvs[:clear] = true if @kvs[:clear].nil?
|
70
|
+
@kvs[:update] = true if @kvs[:update].nil?
|
71
71
|
@scheme = 0
|
72
72
|
@background = 0xffffff
|
73
73
|
@handle = nil
|
74
|
-
|
74
|
+
self.class.last_plot = self
|
75
75
|
end
|
76
76
|
attr_accessor :args, :kvs, :scheme
|
77
77
|
|
@@ -582,8 +582,7 @@ module GR
|
|
582
582
|
|
583
583
|
GR.uselinespec(' ')
|
584
584
|
args.each do |x, y, z, c, spec|
|
585
|
-
|
586
|
-
spec ||= ''
|
585
|
+
spec ||= kvs[:spec] ||= ''
|
587
586
|
GR.savestate
|
588
587
|
GR.settransparency(kvs[:alpha]) if kvs.has_key?(:alpha)
|
589
588
|
|
@@ -795,7 +794,9 @@ module GR
|
|
795
794
|
colorbar(0.05)
|
796
795
|
|
797
796
|
when :plot3
|
798
|
-
GR.
|
797
|
+
mask = GR.uselinespec(spec)
|
798
|
+
GR.polyline3d(x, y, z) if hasline(mask)
|
799
|
+
GR.polymarker3d(x, y, z) if hasmarker(mask)
|
799
800
|
draw_axes(kind, 2)
|
800
801
|
|
801
802
|
when :scatter3
|
@@ -858,7 +859,7 @@ module GR
|
|
858
859
|
|
859
860
|
draw_legend if %i[line step scatter stem].include?(kind) && kvs.has_key?(:labels)
|
860
861
|
|
861
|
-
if kvs
|
862
|
+
if kvs[:update]
|
862
863
|
GR.updatews
|
863
864
|
# if GR.isinline()
|
864
865
|
# restore_context()
|
@@ -978,24 +979,31 @@ module GR
|
|
978
979
|
[*0..(num - 1)].collect { |i| low + i.to_f * (high - low) / (num - 1) }
|
979
980
|
end
|
980
981
|
|
981
|
-
def plot_args(args
|
982
|
+
def plot_args(args)
|
982
983
|
# FIXME
|
983
984
|
args = [args] unless args.all? do |i|
|
984
985
|
i.is_a?(Array) && (i[0].is_a?(Array) || narray?(i[0]))
|
985
986
|
end
|
986
987
|
args.map do |xyzc|
|
988
|
+
spec = nil
|
989
|
+
case xyzc.last
|
990
|
+
when String
|
991
|
+
spec = xyzc.pop
|
992
|
+
when Hash
|
993
|
+
spec = xyzc.pop[:spec]
|
994
|
+
end
|
995
|
+
|
987
996
|
x, y, z, c = xyzc.map do |i|
|
988
|
-
if i.is_a?(Array) || narray?(i)
|
997
|
+
if i.is_a?(Array) || narray?(i) || i.nil?
|
989
998
|
i
|
990
999
|
elsif i.respond_to?(:to_a)
|
991
1000
|
# Convert an Array-like class such as Daru::Vector to an Array
|
992
1001
|
i.to_a
|
993
|
-
else
|
994
|
-
# String
|
1002
|
+
else # String
|
995
1003
|
i
|
996
1004
|
end
|
997
1005
|
end
|
998
|
-
[x, y, z, c]
|
1006
|
+
[x, y, z, c, spec]
|
999
1007
|
end
|
1000
1008
|
end
|
1001
1009
|
|
@@ -1185,7 +1193,8 @@ module GR
|
|
1185
1193
|
# (Plot) Draw a heatmap.
|
1186
1194
|
def heatmap(*args)
|
1187
1195
|
# FIXME
|
1188
|
-
|
1196
|
+
args, kv = format_xyzc(*args)
|
1197
|
+
_x, _y, z = args
|
1189
1198
|
ysize, xsize = z.shape
|
1190
1199
|
z = z.reshape(xsize, ysize)
|
1191
1200
|
create_plot(:heatmap, kv) do |plt|
|
@@ -1213,15 +1222,13 @@ module GR
|
|
1213
1222
|
alias _contour_ contour
|
1214
1223
|
# (Plot) Draw a contour plot.
|
1215
1224
|
def contour(*args)
|
1216
|
-
|
1217
|
-
create_plot(:contour, x, y, z, kv)
|
1225
|
+
create_plot(:contour, *format_xyzc(*args))
|
1218
1226
|
end
|
1219
1227
|
|
1220
1228
|
alias _contourf_ contourf
|
1221
1229
|
# (Plot) Draw a filled contour plot.
|
1222
1230
|
def contourf(*args)
|
1223
|
-
|
1224
|
-
create_plot(:contourf, x, y, z, kv)
|
1231
|
+
create_plot(:contourf, *format_xyzc(*args))
|
1225
1232
|
end
|
1226
1233
|
|
1227
1234
|
alias _hexbin_ hexbin
|
@@ -1232,21 +1239,18 @@ module GR
|
|
1232
1239
|
|
1233
1240
|
# (Plot) Draw a triangular contour plot.
|
1234
1241
|
def tricont(*args)
|
1235
|
-
|
1236
|
-
create_plot(:tricont, x, y, z, kv)
|
1242
|
+
create_plot(:tricont, *format_xyzc(*args))
|
1237
1243
|
end
|
1238
1244
|
|
1239
1245
|
# (Plot) Draw a three-dimensional wireframe plot.
|
1240
1246
|
def wireframe(*args)
|
1241
|
-
|
1242
|
-
create_plot(:wireframe, x, y, z, kv)
|
1247
|
+
create_plot(:wireframe, *format_xyzc(*args))
|
1243
1248
|
end
|
1244
1249
|
|
1245
1250
|
# (Plot) Draw a three-dimensional surface plot.
|
1246
1251
|
alias _surface_ surface
|
1247
1252
|
def surface(*args)
|
1248
|
-
|
1249
|
-
create_plot(:surface, x, y, z, kv)
|
1253
|
+
create_plot(:surface, *format_xyzc(*args))
|
1250
1254
|
end
|
1251
1255
|
|
1252
1256
|
# (Plot)
|
@@ -1256,8 +1260,7 @@ module GR
|
|
1256
1260
|
|
1257
1261
|
# (Plot) Draw a triangular surface plot.
|
1258
1262
|
def trisurf(*args)
|
1259
|
-
|
1260
|
-
create_plot(:trisurf, x, y, z, kv)
|
1263
|
+
create_plot(:trisurf, *format_xyzc(*args))
|
1261
1264
|
end
|
1262
1265
|
|
1263
1266
|
# (Plot) Draw one or more three-dimensional line plots.
|
@@ -1326,6 +1329,33 @@ module GR
|
|
1326
1329
|
end
|
1327
1330
|
end
|
1328
1331
|
|
1332
|
+
def hold(flag = true)
|
1333
|
+
plt = GR::Plot.last_plot
|
1334
|
+
plt.kvs.slice(:window, :scale, :xaxis, :yaxis, :zaxis).merge({ ax: flag, clear: !flag })
|
1335
|
+
end
|
1336
|
+
|
1337
|
+
# Set current subplot index.
|
1338
|
+
def subplot(nr, nc, p)
|
1339
|
+
xmin = 1
|
1340
|
+
xmax = 0
|
1341
|
+
ymin = 1
|
1342
|
+
ymax = 0
|
1343
|
+
p = [p] if p.is_a? Integer
|
1344
|
+
p.each do |i|
|
1345
|
+
r = (nr - (i - 1) / nc).to_f
|
1346
|
+
c = ((i - 1) % nc + 1).to_f
|
1347
|
+
xmin = [xmin, (c - 1) / nc].min
|
1348
|
+
xmax = [xmax, c / nc].max
|
1349
|
+
ymin = [ymin, (r - 1) / nr].min
|
1350
|
+
ymax = [ymax, r / nr].max
|
1351
|
+
end
|
1352
|
+
{
|
1353
|
+
subplot: [xmin, xmax, ymin, ymax],
|
1354
|
+
clear: p[0] == 1,
|
1355
|
+
update: p[-1] == nr * nc
|
1356
|
+
}
|
1357
|
+
end
|
1358
|
+
|
1329
1359
|
# (Plot) Save the current figure to a file.
|
1330
1360
|
def savefig(filename, kv = {})
|
1331
1361
|
GR.beginprint(filename)
|
@@ -1337,40 +1367,41 @@ module GR
|
|
1337
1367
|
|
1338
1368
|
private
|
1339
1369
|
|
1340
|
-
def create_plot(type, *args
|
1370
|
+
def create_plot(type, *args)
|
1341
1371
|
plt = GR::Plot.new(*args)
|
1342
1372
|
plt.kvs[:kind] = type
|
1343
|
-
|
1373
|
+
yield(plt) if block_given?
|
1344
1374
|
plt.plot_data
|
1345
1375
|
plt
|
1346
1376
|
end
|
1347
1377
|
|
1348
|
-
def
|
1378
|
+
def format_xyzc(*args)
|
1349
1379
|
kv = if args[-1].is_a? Hash
|
1350
1380
|
args.pop
|
1351
1381
|
else
|
1352
1382
|
{}
|
1353
1383
|
end
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1384
|
+
|
1385
|
+
args = [args] unless args.all? do |i|
|
1386
|
+
i.is_a?(Array) && (i[0].is_a?(Array) || narray?(i[0]))
|
1387
|
+
end
|
1388
|
+
args.map! do |xyzc|
|
1389
|
+
if xyzc.size == 1
|
1390
|
+
if xyzc[0].is_a? Array
|
1391
|
+
z = Numo::DFloat.cast(xyzc[0])
|
1392
|
+
elsif narray?(xyzc[0])
|
1393
|
+
z = xyzc[0]
|
1394
|
+
end
|
1395
|
+
xsize, ysize = z.shape
|
1396
|
+
x = (1..ysize).to_a * xsize
|
1397
|
+
y = (1..xsize).map { |i| Array.new(ysize, i) }.flatten
|
1398
|
+
[x, y, z]
|
1399
|
+
else
|
1400
|
+
|
1401
|
+
xyzc
|
1359
1402
|
end
|
1360
|
-
xsize, ysize = z.shape
|
1361
|
-
# NOTE:
|
1362
|
-
# See
|
1363
|
-
# https://github.com/jheinen/GR.jl/pull/246
|
1364
|
-
# https://github.com/jheinen/GR.jl/issues/241
|
1365
|
-
x = (1..ysize).to_a * xsize
|
1366
|
-
y = (1..xsize).map { |i| Array.new(ysize, i) }.flatten
|
1367
|
-
|
1368
|
-
elsif args.size == 3
|
1369
|
-
x, y, z = args
|
1370
|
-
else
|
1371
|
-
raise
|
1372
1403
|
end
|
1373
|
-
[
|
1404
|
+
[*args, kv]
|
1374
1405
|
end
|
1375
1406
|
|
1376
1407
|
def hist(x, nbins = 0)
|
data/lib/gr3.rb
CHANGED
@@ -2,43 +2,48 @@
|
|
2
2
|
|
3
3
|
# OverView of GR.rb
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
5
|
+
# +--------------------+ +--------------------+
|
6
|
+
# | GR module | | GR3 module |
|
7
|
+
# | +----------------+ | | +----------------+ |
|
8
|
+
# | | GR::FFI | | | | GR3::FFI | |
|
9
|
+
# | | + libGR.so | | | | + libGR3.so | |
|
10
|
+
# | +----------------+ | | +----------------+ |
|
11
|
+
# | | define_method | | | define_method |
|
12
|
+
# | +----------------+ | | +----------------+ |
|
13
|
+
# | | | GR::GRBase | | | | | GR3::GR3Base | |
|
14
|
+
# | | v (Pri^ate) | | | | v (Pri^ate) | |
|
15
|
+
# | +++--------------+ | | +++--------------+ |
|
16
|
+
# | | Extend | | | Extend |
|
17
|
+
# | v | | v +-------+ |
|
18
|
+
# | +-----------+ | | | Check | |
|
19
|
+
# | | GR::Plot | | | <--+ Error | |
|
20
|
+
# | +-----------+ | | +-------+ |
|
21
|
+
# +--------------------+ +----------+---------+
|
22
|
+
# ^ ^
|
23
|
+
# | +------------------+ |
|
24
|
+
# Extend | | GRCommons module | | Extend
|
25
|
+
# | | +--------------+ | |
|
26
|
+
# | | | Fiddley | | |
|
27
|
+
# | | +--------------+ | |
|
28
|
+
# | | +--------------+ | |
|
29
|
+
# +----+ CommonUtils +----+
|
30
|
+
# | | +--------------+ | |
|
31
|
+
# | | +--------------+ | |
|
32
|
+
# +----+ Version +----+
|
33
|
+
# | | +--------------+ |
|
34
|
+
# | | +--------------+ |
|
35
|
+
# +----+JupyterSupport| |
|
36
|
+
# | +--------------+ |
|
37
|
+
# +------------------+
|
38
|
+
#
|
39
|
+
# (You can edit the above AA diagram with http://asciiflow.com/)
|
40
|
+
#
|
41
|
+
# Fiddley is Ruby-FFI compatible API layer for Fiddle.
|
37
42
|
#
|
38
43
|
# Why not GR::GR3?
|
39
44
|
# * kojix2 did not want to force gr3 to be loaded when gr is loaded.
|
40
45
|
# * kojix2 did not want to write `GR3 = GR::GR3` or something.
|
41
|
-
# * This is a opinion of kojix2 and may be changed
|
46
|
+
# * This is a opinion of kojix2 and may be changed by future maintainers.
|
42
47
|
#
|
43
48
|
# GR3 uses Numo::Narrray.
|
44
49
|
# * It is difficult to write GR3 modules with only Ruby arrays.
|
@@ -68,7 +73,7 @@ module GR3
|
|
68
73
|
self.ffi_lib = File.expand_path('lib/libGR3.so', ENV['GRDIR'])
|
69
74
|
end
|
70
75
|
|
71
|
-
# change the default encoding to UTF-8
|
76
|
+
# change the default encoding to UTF-8.
|
72
77
|
ENV['GKS_ENCODING'] ||= 'utf8'
|
73
78
|
|
74
79
|
require_relative 'gr_commons/gr_commons'
|
@@ -76,9 +81,12 @@ module GR3
|
|
76
81
|
require_relative 'gr3/ffi'
|
77
82
|
require_relative 'gr3/gr3base'
|
78
83
|
|
79
|
-
# `
|
84
|
+
# `inquiry` methods etc. are defined here.
|
85
|
+
extend GRCommons::GRCommonUtils
|
86
|
+
|
87
|
+
# `float` is the default type in GR3.
|
80
88
|
# A Ruby array or NArray passed to GR3 method is automatically converted to
|
81
|
-
# a
|
89
|
+
# a Fiddley::MemoryPointer in the GR3Base class.
|
82
90
|
extend GR3Base
|
83
91
|
|
84
92
|
# This module is for adding error checking to all methods in GR3.
|
@@ -113,8 +121,7 @@ module GR3
|
|
113
121
|
extend CheckError
|
114
122
|
|
115
123
|
# Now you can see a lot of methods just calling super here.
|
116
|
-
#
|
117
|
-
# Yes. They are written to help the yard generate the documentation.
|
124
|
+
# They are written to help the yard generate the documentation.
|
118
125
|
class << self
|
119
126
|
# This method initializes the gr3 context.
|
120
127
|
# @return [Integer]
|
data/lib/gr3/gr3base.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GR3
|
4
|
-
# This module automatically converts Ruby arrays and Numo::Narray into
|
4
|
+
# This module automatically converts Ruby arrays and Numo::Narray into
|
5
|
+
# Fiddley::MemoryPointer.
|
5
6
|
module GR3Base
|
6
7
|
extend GRCommons::DefineMethods
|
7
8
|
define_ffi_methods(FFI,
|
@@ -15,6 +16,4 @@ module GR3
|
|
15
16
|
default_type: :double)
|
16
17
|
end
|
17
18
|
private_constant :GR3Base
|
18
|
-
|
19
|
-
extend GRCommons::GRCommonUtils
|
20
19
|
end
|
@@ -16,9 +16,9 @@ module GRCommons
|
|
16
16
|
args.map! do |arg|
|
17
17
|
case arg
|
18
18
|
when Array
|
19
|
-
send(default_type, arg)
|
19
|
+
GRCommons::GRCommonUtils.send(default_type, arg)
|
20
20
|
when ->(x) { defined?(Numo::NArray) && x.is_a?(Numo::NArray) }
|
21
|
-
send(default_type, arg)
|
21
|
+
GRCommons::GRCommonUtils.send(default_type, arg)
|
22
22
|
else
|
23
23
|
arg
|
24
24
|
end
|
data/lib/gr_commons/fiddley.rb
CHANGED
@@ -5,7 +5,7 @@ require 'gr_commons/fiddley'
|
|
5
5
|
module GRCommons
|
6
6
|
# This module provides functionality common to GR and GR3.
|
7
7
|
module GRCommonUtils
|
8
|
-
|
8
|
+
module_function
|
9
9
|
|
10
10
|
def equal_length(*args)
|
11
11
|
lengths = args.map(&:length)
|
@@ -17,34 +17,60 @@ module GRCommons
|
|
17
17
|
lengths[0]
|
18
18
|
end
|
19
19
|
|
20
|
+
# This constants is used in the test.
|
20
21
|
SUPPORTED_TYPES = %i[uint8 uint16 int uint double float].freeze
|
21
22
|
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
23
|
+
# convert Ruby Array or NArray into packed string.
|
24
|
+
def uint8(data)
|
25
|
+
if narray?(data)
|
26
|
+
Numo::UInt8.cast(data).to_binary
|
27
|
+
else
|
28
|
+
Fiddley::Utils.array2str(:uint8, data.to_a.flatten)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# convert Ruby Array or NArray into packed string.
|
33
|
+
def uint16(data)
|
34
|
+
if narray?(data)
|
35
|
+
Numo::UInt16.cast(data).to_binary
|
36
|
+
else
|
37
|
+
Fiddley::Utils.array2str(:uint16, data.to_a.flatten)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# convert Ruby Array or NArray into packed string.
|
42
|
+
def int(data)
|
43
|
+
if narray?(data)
|
44
|
+
Numo::Int32.cast(data).to_binary
|
45
|
+
else
|
46
|
+
Fiddley::Utils.array2str(:int32, data.to_a.flatten)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# convert Ruby Array or NArray into packed string.
|
51
|
+
def uint(data)
|
52
|
+
if narray?(data)
|
53
|
+
Numo::UInt32.cast(data).to_binary
|
54
|
+
else
|
55
|
+
Fiddley::Utils.array2str(:uint, data.to_a.flatten)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# convert Ruby Array or NArray into packed string.
|
60
|
+
def double(data)
|
61
|
+
if narray?(data)
|
62
|
+
Numo::DFloat.cast(data).to_binary
|
63
|
+
else
|
64
|
+
Fiddley::Utils.array2str(:double, data.to_a.flatten)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# convert Ruby Array or NArray into packed string.
|
69
|
+
def float(data)
|
70
|
+
if narray?(data)
|
71
|
+
Numo::SFloat.cast(data).to_binary
|
72
|
+
else
|
73
|
+
Fiddley::Utils.array2str(:float, data.to_a.flatten)
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|
data/lib/gr_commons/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|