numo-narray-alt 0.10.6 → 0.10.7
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9897dbc5b94aa16af082880fe4085b341b628664ae6abc27e2ffa9e989e88451
|
|
4
|
+
data.tar.gz: d1d53a63934a8a51ee74cf64093b2b3869e03e75bea6070830230e14d9e91b91
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 165941e9d06b5cd9e59ae591ab5666f9cb9924786d5253ce889da809de69b72c1893faef2a4c1e8f2d875021596415496802b8fb1bcf0b523b82c4cde231fb32
|
|
7
|
+
data.tar.gz: fd52d794a7c41344534a07e726b1f13bf0af8003d8e428a0c4f133a17efd5c9721e029a2365fc4a0f4cc04b21f9255897d4927f19500eeaeb51e2cdeb94018f1
|
|
@@ -13,10 +13,10 @@ extern "C" {
|
|
|
13
13
|
#endif
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
#define NARRAY_VERSION "0.10.
|
|
16
|
+
#define NARRAY_VERSION "0.10.7"
|
|
17
17
|
#define NARRAY_VERSION_MAJOR 0
|
|
18
18
|
#define NARRAY_VERSION_MINOR 10
|
|
19
|
-
#define NARRAY_VERSION_PATCH
|
|
19
|
+
#define NARRAY_VERSION_PATCH 7
|
|
20
20
|
#define NARRAY_VERSION_CODE \
|
|
21
21
|
(NARRAY_VERSION_MAJOR * 10000 + NARRAY_VERSION_MINOR * 100 + NARRAY_VERSION_PATCH)
|
|
22
22
|
|
|
@@ -68,13 +68,6 @@
|
|
|
68
68
|
|
|
69
69
|
#define m_mulsum_init INT2FIX(0)
|
|
70
70
|
|
|
71
|
-
#define m_sprintf(s, x) robj_sprintf(s, x)
|
|
72
|
-
|
|
73
|
-
static inline int robj_sprintf(char* s, VALUE x) {
|
|
74
|
-
VALUE v = rb_funcall(x, rb_intern("to_s"), 0);
|
|
75
|
-
return sprintf(s, "%s", StringValuePtr(v));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
71
|
#define m_sqrt(x) \
|
|
79
72
|
rb_funcall(rb_const_get(rb_mKernel, rb_intern("Math")), rb_intern("sqrt"), 1, x);
|
|
80
73
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#ifndef NUMO_NARRAY_MH_FORMAT_H
|
|
2
2
|
#define NUMO_NARRAY_MH_FORMAT_H 1
|
|
3
3
|
|
|
4
|
-
#define
|
|
4
|
+
#define DEF_NARRAY_FORMAT_ELEMENT_FUNC(tDType) \
|
|
5
5
|
static VALUE format_##tDType(VALUE fmt, tDType* x) { \
|
|
6
6
|
if (NIL_P(fmt)) { \
|
|
7
7
|
char s[48]; \
|
|
@@ -9,8 +9,22 @@
|
|
|
9
9
|
return rb_str_new(s, n); \
|
|
10
10
|
} \
|
|
11
11
|
return rb_funcall(fmt, '%', 1, m_data_to_num(*x)); \
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* robject formats its element without the fixed buffer above: the element is an
|
|
15
|
+
arbitrary Ruby object, so the length of its to_s is not bounded by anything
|
|
16
|
+
this side controls. */
|
|
17
|
+
#define DEF_NARRAY_ROBJ_FORMAT_ELEMENT_FUNC() \
|
|
18
|
+
static VALUE format_robject(VALUE fmt, robject* x) { \
|
|
19
|
+
if (NIL_P(fmt)) { \
|
|
20
|
+
VALUE v = rb_funcall(*x, id_to_s, 0); \
|
|
21
|
+
StringValue(v); \
|
|
22
|
+
return rb_str_new(RSTRING_PTR(v), RSTRING_LEN(v)); \
|
|
23
|
+
} \
|
|
24
|
+
return rb_funcall(fmt, '%', 1, m_data_to_num(*x)); \
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#define DEF_NARRAY_FORMAT_LOOP_METHOD_FUNC(tDType) \
|
|
14
28
|
static void iter_##tDType##_format(na_loop_t* const lp) { \
|
|
15
29
|
size_t n; \
|
|
16
30
|
char* p1; \
|
|
@@ -52,4 +66,12 @@
|
|
|
52
66
|
return na_ndloop(&ndf, 2, self, fmt); \
|
|
53
67
|
}
|
|
54
68
|
|
|
69
|
+
#define DEF_NARRAY_FORMAT_METHOD_FUNC(tDType) \
|
|
70
|
+
DEF_NARRAY_FORMAT_ELEMENT_FUNC(tDType) \
|
|
71
|
+
DEF_NARRAY_FORMAT_LOOP_METHOD_FUNC(tDType)
|
|
72
|
+
|
|
73
|
+
#define DEF_NARRAY_ROBJ_FORMAT_METHOD_FUNC() \
|
|
74
|
+
DEF_NARRAY_ROBJ_FORMAT_ELEMENT_FUNC() \
|
|
75
|
+
DEF_NARRAY_FORMAT_LOOP_METHOD_FUNC(robject)
|
|
76
|
+
|
|
55
77
|
#endif /* NUMO_NARRAY_MH_FORMAT_H */
|
|
@@ -321,9 +321,9 @@ static inline void swapfunc(char* a, char* b, size_t n, int swaptype) {
|
|
|
321
321
|
rb_funcall(idx, rb_intern("seq"), 0); \
|
|
322
322
|
size_t size = na->size * sizeof(void*); \
|
|
323
323
|
VALUE tmp; \
|
|
324
|
-
char* buf =
|
|
324
|
+
char* buf = RB_ALLOCV(tmp, size); \
|
|
325
325
|
VALUE res = na_ndloop3(&ndf, buf, 3, self, idx, reduce); \
|
|
326
|
-
|
|
326
|
+
RB_ALLOCV_END(tmp); \
|
|
327
327
|
return res; \
|
|
328
328
|
}
|
|
329
329
|
|
|
@@ -475,9 +475,9 @@ static inline void swapfunc(char* a, char* b, size_t n, int swaptype) {
|
|
|
475
475
|
rb_funcall(idx, rb_intern("seq"), 0); \
|
|
476
476
|
size_t size = na->size * sizeof(void*); \
|
|
477
477
|
VALUE tmp; \
|
|
478
|
-
char* buf =
|
|
478
|
+
char* buf = RB_ALLOCV(tmp, size); \
|
|
479
479
|
VALUE res = na_ndloop3(&ndf, buf, 3, self, idx, reduce); \
|
|
480
|
-
|
|
480
|
+
RB_ALLOCV_END(tmp); \
|
|
481
481
|
return res; \
|
|
482
482
|
}
|
|
483
483
|
|
|
@@ -50,6 +50,7 @@ static ID id_reciprocal;
|
|
|
50
50
|
static ID id_round;
|
|
51
51
|
static ID id_square;
|
|
52
52
|
static ID id_to_a;
|
|
53
|
+
static ID id_to_s;
|
|
53
54
|
static ID id_truncate;
|
|
54
55
|
|
|
55
56
|
#include <numo/types/robject.h>
|
|
@@ -146,7 +147,7 @@ DEF_NARRAY_ASET_METHOD_FUNC(robject)
|
|
|
146
147
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(robject)
|
|
147
148
|
DEF_NARRAY_TO_A_METHOD_FUNC(robject)
|
|
148
149
|
DEF_NARRAY_FILL_METHOD_FUNC(robject)
|
|
149
|
-
|
|
150
|
+
DEF_NARRAY_ROBJ_FORMAT_METHOD_FUNC()
|
|
150
151
|
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(robject)
|
|
151
152
|
DEF_NARRAY_ROBJ_INSPECT_METHOD_FUNC()
|
|
152
153
|
DEF_NARRAY_EACH_METHOD_FUNC(robject)
|
|
@@ -370,6 +371,7 @@ void Init_numo_robject(void) {
|
|
|
370
371
|
id_round = rb_intern("round");
|
|
371
372
|
id_square = rb_intern("square");
|
|
372
373
|
id_to_a = rb_intern("to_a");
|
|
374
|
+
id_to_s = rb_intern("to_s");
|
|
373
375
|
id_truncate = rb_intern("truncate");
|
|
374
376
|
|
|
375
377
|
/**
|
data/lib/numo/narray/extra.rb
CHANGED
|
@@ -137,6 +137,10 @@ module Numo
|
|
|
137
137
|
# # [[2, -3, 5],
|
|
138
138
|
# # [4, 9, 7],
|
|
139
139
|
# # [2, -1, 6]]
|
|
140
|
+
# @example
|
|
141
|
+
# a = Numo::NArray.parse('true false nil')
|
|
142
|
+
# # => Numo::Bit#shape=[1,3]
|
|
143
|
+
# # [[1, 0, 0]]
|
|
140
144
|
|
|
141
145
|
def self.parse(str, split1d: /\s+/, split2d: /;?$|;/,
|
|
142
146
|
split3d: /\s*\n(\s*\n)+/m)
|
|
@@ -151,7 +155,8 @@ module Numo
|
|
|
151
155
|
|
|
152
156
|
c = []
|
|
153
157
|
line.split(split1d).each do |item|
|
|
154
|
-
|
|
158
|
+
item = item.strip
|
|
159
|
+
c << parse_token(item) unless item.empty?
|
|
155
160
|
end
|
|
156
161
|
b << c unless c.empty?
|
|
157
162
|
end
|
|
@@ -164,6 +169,42 @@ module Numo
|
|
|
164
169
|
end
|
|
165
170
|
end
|
|
166
171
|
|
|
172
|
+
# Convert one token of {parse} input into a value.
|
|
173
|
+
#
|
|
174
|
+
# Only the literals that describe an element are accepted: integer, float
|
|
175
|
+
# and complex numbers, and +true+, +false+ and +nil+, which {cast} turns
|
|
176
|
+
# into a {Numo::Bit}. Anything else -- an expression, a method call, a bare
|
|
177
|
+
# word -- raises ArgumentError, so text handed to {parse} is never executed
|
|
178
|
+
# as Ruby code.
|
|
179
|
+
#
|
|
180
|
+
# @param item [String] one whitespace-delimited token, already stripped
|
|
181
|
+
# @return [Integer, Float, Complex, true, false, nil] the parsed value
|
|
182
|
+
# @raise [ArgumentError] if the token is not one of those literals
|
|
183
|
+
def self.parse_token(item)
|
|
184
|
+
case item
|
|
185
|
+
when 'true' then return true
|
|
186
|
+
when 'false' then return false
|
|
187
|
+
when 'nil' then return nil
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
v = Integer(item, exception: false)
|
|
191
|
+
return v if v
|
|
192
|
+
|
|
193
|
+
v = Float(item, exception: false)
|
|
194
|
+
return v if v
|
|
195
|
+
|
|
196
|
+
if item.end_with?('i')
|
|
197
|
+
begin
|
|
198
|
+
return Complex(item)
|
|
199
|
+
rescue ArgumentError, TypeError
|
|
200
|
+
nil
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
raise ArgumentError, "invalid literal: #{item.inspect}"
|
|
205
|
+
end
|
|
206
|
+
private_class_method :parse_token
|
|
207
|
+
|
|
167
208
|
# Iterate over an axis
|
|
168
209
|
# @example
|
|
169
210
|
# > a = Numo::DFloat.new(2,2,2).seq
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: numo-narray-alt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yoshoku
|
|
@@ -214,7 +214,7 @@ licenses:
|
|
|
214
214
|
metadata:
|
|
215
215
|
homepage_uri: https://github.com/yoshoku/numo-narray-alt
|
|
216
216
|
changelog_uri: https://github.com/yoshoku/numo-narray-alt/blob/main/CHANGELOG.md
|
|
217
|
-
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.10.
|
|
217
|
+
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.10.7/
|
|
218
218
|
rubygems_mfa_required: 'true'
|
|
219
219
|
post_install_message: |
|
|
220
220
|
===
|