numo-narray-alt 0.11.1 → 0.11.2
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: 62b615bb540e3a9d9783fa984943437f42ad5bbcf93041dead8d770317d8fcf6
|
|
4
|
+
data.tar.gz: 895c80b9b6544f09d04412a6a96439999752a9636d1b243127d96007f2574ba5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d6b5ac1dbfd8bb0f448a8c073de8f7951a9f571b20c9f88b864549f31dd828209cd67c4e7b629f2756ece9e98de6ad26a5b37a8f6131f836de259e25895bfd23
|
|
7
|
+
data.tar.gz: eea7716214274464d8e4fb4874d4415cf49a97ad7e0f15c15211257cb531604c7822913cf15d7a5ebba49df58de845b788a8558b04ac98ec3d5540fc62b527b3
|
|
@@ -13,10 +13,10 @@ extern "C" {
|
|
|
13
13
|
#endif
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
#define NARRAY_VERSION "0.11.
|
|
16
|
+
#define NARRAY_VERSION "0.11.2"
|
|
17
17
|
#define NARRAY_VERSION_MAJOR 0
|
|
18
18
|
#define NARRAY_VERSION_MINOR 11
|
|
19
|
-
#define NARRAY_VERSION_PATCH
|
|
19
|
+
#define NARRAY_VERSION_PATCH 2
|
|
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 */
|
|
@@ -45,6 +45,7 @@ static ID id_reciprocal;
|
|
|
45
45
|
static ID id_round;
|
|
46
46
|
static ID id_square;
|
|
47
47
|
static ID id_to_a;
|
|
48
|
+
static ID id_to_s;
|
|
48
49
|
static ID id_truncate;
|
|
49
50
|
|
|
50
51
|
#include <numo/types/robject.h>
|
|
@@ -141,7 +142,7 @@ DEF_NARRAY_ASET_METHOD_FUNC(robject)
|
|
|
141
142
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(robject)
|
|
142
143
|
DEF_NARRAY_TO_A_METHOD_FUNC(robject)
|
|
143
144
|
DEF_NARRAY_FILL_METHOD_FUNC(robject)
|
|
144
|
-
|
|
145
|
+
DEF_NARRAY_ROBJ_FORMAT_METHOD_FUNC()
|
|
145
146
|
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(robject)
|
|
146
147
|
DEF_NARRAY_ROBJ_INSPECT_METHOD_FUNC()
|
|
147
148
|
DEF_NARRAY_EACH_METHOD_FUNC(robject)
|
|
@@ -365,6 +366,7 @@ void Init_numo_robject(void) {
|
|
|
365
366
|
id_round = rb_intern("round");
|
|
366
367
|
id_square = rb_intern("square");
|
|
367
368
|
id_to_a = rb_intern("to_a");
|
|
369
|
+
id_to_s = rb_intern("to_s");
|
|
368
370
|
id_truncate = rb_intern("truncate");
|
|
369
371
|
|
|
370
372
|
/**
|
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.11.
|
|
4
|
+
version: 0.11.2
|
|
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.11.
|
|
217
|
+
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.11.2/
|
|
218
218
|
rubygems_mfa_required: 'true'
|
|
219
219
|
post_install_message: |
|
|
220
220
|
===
|