red-arrow-nmatrix 0.0.1 → 0.0.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
  SHA1:
3
- metadata.gz: f3ffe755b9e4e51b7314d91da2c286f92c681d4f
4
- data.tar.gz: d65872943ccf869167e90ddaad2d4593ad50c6fd
3
+ metadata.gz: 57917fdcb774924da3d381bf4412eed4ec0e9bd2
4
+ data.tar.gz: 2ea62014eea605a60a872e46f7632c3562b43279
5
5
  SHA512:
6
- metadata.gz: 952dcdde2b3ae47934b13957e7018e803f3b108f578f02849ee4eeefc1ad860e9f2e56f56e6df19bdfb4d71d06a3d69bba965f8fba723ff0d5bdaa5f8f49212a
7
- data.tar.gz: 4c2d47e6a134271d64e378d43c76d89489dc5a8f8842d11d497b7211b829cef53f2522bf8e08821a8523e9cb728afb184159c28333596bd8319d6cd75b2d3f65
6
+ metadata.gz: be9c3167b15fd4ac0a0923387d3571eb8575beefa72e8da49a3b242a612d5a24ce925b8029f477fb456e500551f65874418aa6b2051b523880a9fe052c963997
7
+ data.tar.gz: 8fcd0b7d185aa92217d933cb6b5d121d29699c796076103cc075593797c54a49105952948f6861c032c0fd50e31be59dc2d2f02f5d7bad0f1e2e8e1e5ea709f5
data/doc/text/news.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # News
2
2
 
3
+ ## 0.0.2 - 2017-05-18
4
+
5
+ ### Fixed
6
+
7
+ * Added missing C source files.
8
+
3
9
  ## 0.0.1 - 2017-05-18
4
10
 
5
11
  Initial release!!!
@@ -0,0 +1,214 @@
1
+ /*
2
+ * Copyright 2017 Kouhei Sutou <kou@clear-code.com>
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include <arrow-glib/arrow-glib.h>
18
+
19
+ #include <rbgobject.h>
20
+
21
+ #include <nmatrix.h>
22
+
23
+ /* TODO: NMatrix should extern them. */
24
+ extern const size_t DTYPE_SIZES[NM_NUM_DTYPES];
25
+ /* extern size_t nm_storage_count_max_elements(const STORAGE* storage); */
26
+
27
+ void Init_arrow_nmatrix(void);
28
+
29
+ static nm_dtype_t
30
+ garrow_type_to_nmatrix_dtype(GArrowType arrow_type)
31
+ {
32
+ nm_dtype_t nmatrix_type = (nm_dtype_t)-1;
33
+
34
+ switch (arrow_type) {
35
+ case GARROW_TYPE_UINT8:
36
+ nmatrix_type = BYTE;
37
+ break;
38
+ case GARROW_TYPE_INT8:
39
+ nmatrix_type = INT8;
40
+ break;
41
+ case GARROW_TYPE_INT16:
42
+ nmatrix_type = INT16;
43
+ break;
44
+ case GARROW_TYPE_INT32:
45
+ nmatrix_type = INT32;
46
+ break;
47
+ case GARROW_TYPE_INT64:
48
+ nmatrix_type = INT64;
49
+ break;
50
+ case GARROW_TYPE_FLOAT:
51
+ nmatrix_type = FLOAT32;
52
+ break;
53
+ case GARROW_TYPE_DOUBLE:
54
+ nmatrix_type = FLOAT64;
55
+ break;
56
+ case GARROW_TYPE_NA:
57
+ case GARROW_TYPE_BOOL:
58
+ case GARROW_TYPE_UINT16:
59
+ case GARROW_TYPE_UINT32:
60
+ case GARROW_TYPE_UINT64:
61
+ case GARROW_TYPE_HALF_FLOAT:
62
+ case GARROW_TYPE_STRING:
63
+ case GARROW_TYPE_BINARY:
64
+ case GARROW_TYPE_DATE32:
65
+ case GARROW_TYPE_DATE64:
66
+ case GARROW_TYPE_TIMESTAMP:
67
+ case GARROW_TYPE_TIME32:
68
+ case GARROW_TYPE_TIME64:
69
+ case GARROW_TYPE_INTERVAL:
70
+ case GARROW_TYPE_DECIMAL:
71
+ case GARROW_TYPE_LIST:
72
+ case GARROW_TYPE_STRUCT:
73
+ case GARROW_TYPE_UNION:
74
+ case GARROW_TYPE_DICTIONARY:
75
+ default:
76
+ break;
77
+ }
78
+
79
+ return nmatrix_type;
80
+ }
81
+
82
+ static VALUE
83
+ rb_arrow_tensor_to_nmatrix(VALUE self)
84
+ {
85
+ GArrowTensor *tensor;
86
+ GArrowType value_type;
87
+ nm_dtype_t nmatrix_data_type;
88
+ gint64 *shape;
89
+ gint n_dimensions;
90
+ GArrowBuffer *buffer;
91
+ GBytes *data;
92
+ gconstpointer data_raw;
93
+ gsize data_size;
94
+ VALUE rb_nmatrix = Qnil;
95
+
96
+ tensor = RVAL2GOBJ(self);
97
+ value_type = garrow_tensor_get_value_type(tensor);
98
+ nmatrix_data_type = garrow_type_to_nmatrix_dtype(value_type);
99
+ if (nmatrix_data_type == (nm_dtype_t)-1) {
100
+ GArrowDataType *data_type;
101
+ VALUE rb_data_type;
102
+ data_type = garrow_tensor_get_value_data_type(tensor);
103
+ rb_data_type = GOBJ2RVAL(data_type);
104
+ g_object_unref(data_type);
105
+ rb_raise(rb_eArgError,
106
+ "Arrow::Tensor data type must be uint8, int*, float or double: "
107
+ "<%" PRIsVALUE ">",
108
+ rb_data_type);
109
+ }
110
+
111
+ shape = garrow_tensor_get_shape(tensor, &n_dimensions);
112
+ buffer = garrow_tensor_get_buffer(tensor);
113
+ data = garrow_buffer_get_data(buffer);
114
+ data_raw = g_bytes_get_data(data, &data_size);
115
+
116
+ rb_nmatrix = rb_nmatrix_dense_create(nmatrix_data_type,
117
+ (size_t *)shape,
118
+ n_dimensions,
119
+ (void *)data_raw,
120
+ data_size);
121
+ g_bytes_unref(data);
122
+ g_object_unref(buffer);
123
+ g_free(shape);
124
+
125
+ return rb_nmatrix;
126
+ }
127
+
128
+ static GArrowDataType *
129
+ nmatrix_dtype_to_garrow_data_type(nm_dtype_t nmatrix_type)
130
+ {
131
+ GArrowDataType *arrow_data_type = NULL;
132
+
133
+ switch (nmatrix_type) {
134
+ case BYTE:
135
+ arrow_data_type = garrow_uint8_data_type_new();
136
+ break;
137
+ case INT8:
138
+ arrow_data_type = garrow_int8_data_type_new();
139
+ break;
140
+ case INT16:
141
+ arrow_data_type = garrow_int16_data_type_new();
142
+ break;
143
+ case INT32:
144
+ arrow_data_type = garrow_int32_data_type_new();
145
+ break;
146
+ case INT64:
147
+ arrow_data_type = garrow_int64_data_type_new();
148
+ break;
149
+ case FLOAT32:
150
+ arrow_data_type = garrow_float_data_type_new();
151
+ break;
152
+ case FLOAT64:
153
+ arrow_data_type = garrow_double_data_type_new();
154
+ break;
155
+ case COMPLEX64:
156
+ case COMPLEX128:
157
+ case RUBYOBJ:
158
+ default:
159
+ break;
160
+ }
161
+
162
+ return arrow_data_type;
163
+ }
164
+
165
+ static VALUE
166
+ rb_nmatrix_to_arrow(VALUE self)
167
+ {
168
+ GArrowDoubleDataType *data_type;
169
+ GArrowBuffer *data;
170
+ GArrowTensor *tensor;
171
+ VALUE rb_tensor;
172
+
173
+ data_type = nmatrix_dtype_to_garrow_data_type(NM_DTYPE(self));
174
+ if (!data_type) {
175
+ rb_raise(rb_eArgError,
176
+ "NMatrix data type must be "
177
+ ":byte, :int8, :int16, :int32, :int64, :float32 or :float64: "
178
+ "<%" PRIsVALUE ">",
179
+ self);
180
+ }
181
+ data = garrow_buffer_new((const guint8 *)NM_DENSE_ELEMENTS(self),
182
+ NM_SIZEOF_DTYPE(self) * NM_DENSE_COUNT(self));
183
+ tensor = garrow_tensor_new(GARROW_DATA_TYPE(data_type),
184
+ data,
185
+ (gint64 *)(NM_STORAGE(self)->shape),
186
+ NM_DIM(self),
187
+ NULL,
188
+ 0,
189
+ NULL,
190
+ 0);
191
+ g_object_unref(data);
192
+ g_object_unref(data_type);
193
+
194
+ rb_tensor = GOBJ2RVAL(tensor);
195
+ g_object_unref(tensor);
196
+
197
+ return rb_tensor;
198
+ }
199
+
200
+ void
201
+ Init_arrow_nmatrix(void)
202
+ {
203
+ VALUE rb_Arrow;
204
+ VALUE rb_ArrowTensor;
205
+
206
+ rb_Arrow = rb_const_get(rb_cObject, rb_intern("Arrow"));
207
+ rb_ArrowTensor = rb_const_get(rb_Arrow, rb_intern("Tensor"));
208
+
209
+ rb_define_method(rb_ArrowTensor, "to_nmatrix",
210
+ rb_arrow_tensor_to_nmatrix, 0);
211
+
212
+ rb_define_method(cNMatrix, "to_arrow",
213
+ rb_nmatrix_to_arrow, 0);
214
+ }
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module ArrowNMatrix
16
- VERSION = "0.0.1"
16
+ VERSION = "0.0.2"
17
17
  end
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"]
39
39
  spec.files += [".yardopts"]
40
40
  spec.files += Dir.glob("lib/**/*.rb")
41
+ spec.files += Dir.glob("ext/**/*.c")
41
42
  spec.files += Dir.glob("doc/text/*")
42
43
  spec.extensions = ["ext/arrow-nmatrix/extconf.rb"]
43
44
  spec.test_files += Dir.glob("test/**/*")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red-arrow-nmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -140,6 +140,7 @@ files:
140
140
  - Rakefile
141
141
  - doc/text/apache-2.0.txt
142
142
  - doc/text/news.md
143
+ - ext/arrow-nmatrix/arrow-nmatrix.c
143
144
  - ext/arrow-nmatrix/extconf.rb
144
145
  - lib/arrow-nmatrix.rb
145
146
  - lib/arrow-nmatrix/version.rb
@@ -174,7 +175,7 @@ specification_version: 4
174
175
  summary: Red Arrow NMatrix is a library that provides converters between Apache Arrow's
175
176
  tensor data (`Arrow::Tensor`) and NMatrix's matrix data (`NMatrix`).
176
177
  test_files:
177
- - test/test-to-arrow.rb
178
- - test/helper.rb
179
- - test/run-test.rb
180
178
  - test/test-to-nmatrix.rb
179
+ - test/run-test.rb
180
+ - test/helper.rb
181
+ - test/test-to-arrow.rb