numo-narray 0.9.0.8 → 0.9.0.9
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 +4 -4
- data/ext/numo/narray/extconf.rb +5 -0
- data/ext/numo/narray/kwargs.c +153 -0
- data/ext/numo/narray/numo/intern.h +8 -0
- data/ext/numo/narray/numo/narray.h +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09918199887bb7a9559b43147fd5174245bd8889'
|
4
|
+
data.tar.gz: 801ffe2b5cdc10afa543987c1862a5ae4eae27f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac932f2ad8b580607d05a86da8a6f22c17c2ec1afbde5b0f48a751c7c6b374bd8119173b104bf6e3b674716b38bf3a9a33294f8456833a2483099d9838c23def
|
7
|
+
data.tar.gz: ecd2bf05f24dc79100c28fbd66d5af556dc7b410bbed1a8a5bf0e06d2cd2175ecc6ee556e1c277e5e333c464039f56dbc6dfbdf441323d6042ffe8b2126756bf
|
data/ext/numo/narray/extconf.rb
CHANGED
@@ -0,0 +1,153 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
|
3
|
+
Function to extract Keyword argument for ruby-2.1.x
|
4
|
+
Copied from class.c in ruby-2.4.2
|
5
|
+
|
6
|
+
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
7
|
+
|
8
|
+
**********************************************************************/
|
9
|
+
#include <ruby.h>
|
10
|
+
#define rb_hash_tbl_raw(hash) rb_hash_tbl(hash)
|
11
|
+
|
12
|
+
/* from internal.h */
|
13
|
+
struct RBasicRaw {
|
14
|
+
VALUE flags;
|
15
|
+
VALUE klass;
|
16
|
+
};
|
17
|
+
|
18
|
+
#define RBASIC_SET_CLASS(obj, cls) do { \
|
19
|
+
VALUE _obj_ = (obj); \
|
20
|
+
RB_OBJ_WRITE(_obj_, &((struct RBasicRaw *)(_obj_))->klass, cls); \
|
21
|
+
} while (0)
|
22
|
+
|
23
|
+
/* from class.c */
|
24
|
+
VALUE
|
25
|
+
rb_keyword_error_new(const char *error, VALUE keys)
|
26
|
+
{
|
27
|
+
const char *msg = "";
|
28
|
+
VALUE error_message;
|
29
|
+
|
30
|
+
if (RARRAY_LEN(keys) == 1) {
|
31
|
+
keys = RARRAY_AREF(keys, 0);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
keys = rb_ary_join(keys, rb_usascii_str_new2(", "));
|
35
|
+
msg = "s";
|
36
|
+
}
|
37
|
+
|
38
|
+
error_message = rb_sprintf("%s keyword%s: %"PRIsVALUE, error, msg, keys);
|
39
|
+
|
40
|
+
return rb_exc_new_str(rb_eArgError, error_message);
|
41
|
+
}
|
42
|
+
|
43
|
+
NORETURN(static void rb_keyword_error(const char *error, VALUE keys));
|
44
|
+
static void
|
45
|
+
rb_keyword_error(const char *error, VALUE keys)
|
46
|
+
{
|
47
|
+
rb_exc_raise(rb_keyword_error_new(error, keys));
|
48
|
+
}
|
49
|
+
|
50
|
+
NORETURN(static void unknown_keyword_error(VALUE hash, const ID *table, int keywords));
|
51
|
+
static void
|
52
|
+
unknown_keyword_error(VALUE hash, const ID *table, int keywords)
|
53
|
+
{
|
54
|
+
st_table *tbl = rb_hash_tbl_raw(hash);
|
55
|
+
VALUE keys;
|
56
|
+
int i;
|
57
|
+
for (i = 0; i < keywords; i++) {
|
58
|
+
st_data_t key = ID2SYM(table[i]);
|
59
|
+
st_delete(tbl, &key, NULL);
|
60
|
+
}
|
61
|
+
keys = rb_funcallv(hash, rb_intern("keys"), 0, 0);
|
62
|
+
if (!RB_TYPE_P(keys, T_ARRAY)) rb_raise(rb_eArgError, "unknown keyword");
|
63
|
+
rb_keyword_error("unknown", keys);
|
64
|
+
}
|
65
|
+
|
66
|
+
static int
|
67
|
+
separate_symbol(st_data_t key, st_data_t value, st_data_t arg)
|
68
|
+
{
|
69
|
+
VALUE *kwdhash = (VALUE *)arg;
|
70
|
+
|
71
|
+
if (!SYMBOL_P(key)) kwdhash++;
|
72
|
+
if (!*kwdhash) *kwdhash = rb_hash_new();
|
73
|
+
rb_hash_aset(*kwdhash, (VALUE)key, (VALUE)value);
|
74
|
+
return ST_CONTINUE;
|
75
|
+
}
|
76
|
+
|
77
|
+
VALUE
|
78
|
+
rb_extract_keywords(VALUE *orighash)
|
79
|
+
{
|
80
|
+
VALUE parthash[2] = {0, 0};
|
81
|
+
VALUE hash = *orighash;
|
82
|
+
|
83
|
+
if (RHASH_EMPTY_P(hash)) {
|
84
|
+
*orighash = 0;
|
85
|
+
return hash;
|
86
|
+
}
|
87
|
+
st_foreach(rb_hash_tbl_raw(hash), separate_symbol, (st_data_t)&parthash);
|
88
|
+
*orighash = parthash[1];
|
89
|
+
if (parthash[1] && RBASIC_CLASS(hash) != rb_cHash) {
|
90
|
+
RBASIC_SET_CLASS(parthash[1], RBASIC_CLASS(hash));
|
91
|
+
}
|
92
|
+
return parthash[0];
|
93
|
+
}
|
94
|
+
|
95
|
+
int
|
96
|
+
rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
|
97
|
+
{
|
98
|
+
int i = 0, j;
|
99
|
+
int rest = 0;
|
100
|
+
VALUE missing = Qnil;
|
101
|
+
st_data_t key;
|
102
|
+
|
103
|
+
#define extract_kwarg(keyword, val) \
|
104
|
+
(key = (st_data_t)(keyword), values ? \
|
105
|
+
st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) : \
|
106
|
+
st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val)))
|
107
|
+
|
108
|
+
if (NIL_P(keyword_hash)) keyword_hash = 0;
|
109
|
+
|
110
|
+
if (optional < 0) {
|
111
|
+
rest = 1;
|
112
|
+
optional = -1-optional;
|
113
|
+
}
|
114
|
+
if (values) {
|
115
|
+
for (j = 0; j < required + optional; j++) {
|
116
|
+
values[j] = Qundef;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
if (required) {
|
120
|
+
for (; i < required; i++) {
|
121
|
+
VALUE keyword = ID2SYM(table[i]);
|
122
|
+
if (keyword_hash) {
|
123
|
+
st_data_t val;
|
124
|
+
if (extract_kwarg(keyword, &val)) {
|
125
|
+
if (values) values[i] = (VALUE)val;
|
126
|
+
continue;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
if (NIL_P(missing)) missing = rb_ary_tmp_new(1);
|
130
|
+
rb_ary_push(missing, keyword);
|
131
|
+
}
|
132
|
+
if (!NIL_P(missing)) {
|
133
|
+
rb_keyword_error("missing", missing);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
j = i;
|
137
|
+
if (optional && keyword_hash) {
|
138
|
+
for (i = 0; i < optional; i++) {
|
139
|
+
st_data_t val;
|
140
|
+
if (extract_kwarg(ID2SYM(table[required+i]), &val)) {
|
141
|
+
if (values) values[required+i] = (VALUE)val;
|
142
|
+
j++;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
if (!rest && keyword_hash) {
|
147
|
+
if (RHASH_SIZE(keyword_hash) > (unsigned int)(values ? 0 : j)) {
|
148
|
+
unknown_keyword_error(keyword_hash, table, required+optional);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return j;
|
152
|
+
#undef extract_kwarg
|
153
|
+
}
|
@@ -106,4 +106,12 @@ int nary_get_result_dimension(VALUE self, int argc, VALUE *argv, ssize_t stride,
|
|
106
106
|
#define na_aref_main nary_aref_main
|
107
107
|
VALUE nary_aref_main(int nidx, VALUE *idx, VALUE self, int keep_dim, int nd);
|
108
108
|
|
109
|
+
#include "ruby/version.h"
|
110
|
+
|
111
|
+
#if RUBY_API_VERSION_CODE == 20100 // 2.1.0
|
112
|
+
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *);
|
113
|
+
VALUE rb_extract_keywords(VALUE *orighash);
|
114
|
+
#endif
|
115
|
+
|
116
|
+
|
109
117
|
#endif /* ifndef INTERN_H */
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-narray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0.
|
4
|
+
version: 0.9.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- ext/numo/narray/gen/tmpl_bit/where.c
|
205
205
|
- ext/numo/narray/gen/tmpl_bit/where2.c
|
206
206
|
- ext/numo/narray/index.c
|
207
|
+
- ext/numo/narray/kwargs.c
|
207
208
|
- ext/numo/narray/math.c
|
208
209
|
- ext/numo/narray/narray.c
|
209
210
|
- ext/numo/narray/ndloop.c
|
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
267
|
version: '0'
|
267
268
|
requirements: []
|
268
269
|
rubyforge_project:
|
269
|
-
rubygems_version: 2.6.
|
270
|
+
rubygems_version: 2.6.13
|
270
271
|
signing_key:
|
271
272
|
specification_version: 4
|
272
273
|
summary: alpha release of Numo::NArray - New NArray class library in Ruby/Numo (NUmerical
|