red-arrow-gsl 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d738527d4a3a387d47b5bfde71917b04ecf35155
4
- data.tar.gz: 1f479d39fc061e182d1b4ed6ecda1562e8aa9bd1
3
+ metadata.gz: 86305e7717efea7bed524b4ee6ca9dc2e375b614
4
+ data.tar.gz: 9fff5efeb72766da41cea41d0d852bdaaf2af6fe
5
5
  SHA512:
6
- metadata.gz: 8884bea5f852ccc0fe3e51ca739f24d9a2acdfc5d1d8c7db0eae8b1b0cb61fd5f4f096e0272f64b1ad5e169fe038b7e9654784aa9f0dc23848c0887c60866bd7
7
- data.tar.gz: 71455e037efa9a0ced82397c3595eadaa447b7029ca797b84c8274fe57228d88e1c4e9dd1f451f840745c6e54ac5ff04dce7f3acf00f3e113292a0170ed64629
6
+ metadata.gz: 5bb6d9e2e4cb4174d506a9460d17461565d612e1a73651b634167c30125579fc21bb26ad16ef232ebca48a11356ee2d8cd44b0f1f5e9b531ac3ad9c7e78bf9e9
7
+ data.tar.gz: 5ce4857529adad9559941eb9731fdb1ad1b18b1a2c1d3cde753dc5f1141b913c477f607160339e9a050dc5bb160defd099f2a42f02ca335aa1aee6195ac68a9e
@@ -1,5 +1,11 @@
1
1
  # News
2
2
 
3
+ ## 0.0.2 - 2017-05-18
4
+
5
+ ### Fixes
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,221 @@
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 <rb_gsl.h>
22
+
23
+ void Init_arrow_gsl(void);
24
+
25
+ static VALUE
26
+ rb_arrow_int32_array_to_gsl(VALUE self)
27
+ {
28
+ /*
29
+ GArrowInt32Array *arrow_array;
30
+ gint64 length;
31
+ GArrowBuffer *buffer;
32
+ GBytes *data;
33
+ gconstpointer data_raw;
34
+ gsize data_size;
35
+ gsl_vector_int *gsl_vector;
36
+
37
+ arrow_array = RVAL2GOBJ(self);
38
+ length = garrow_array_get_length(GARROW_ARRAY(arrow_array));
39
+ gsl_vector = gsl_vector_int_alloc(length);
40
+
41
+ buffer = garrow_primary_array_get_buffer(GARROW_PRIMARY_ARRAY(arrow_array));
42
+ data = garrow_buffer_get_data(buffer);
43
+ data_raw = g_bytes_get_data(data, &data_size);
44
+ memcpy(gsl_vector->data, data_raw, data_size);
45
+ g_object_unref(buffer);
46
+
47
+ return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, gsl_vector);
48
+ */
49
+ return Qnil;
50
+ }
51
+
52
+ static VALUE
53
+ rb_arrow_tensor_to_gsl(VALUE self)
54
+ {
55
+ GArrowTensor *tensor;
56
+ gint64 *shape;
57
+ gint n_dimensions;
58
+ GArrowType value_type;
59
+ VALUE rb_matrix = Qnil;
60
+
61
+ tensor = RVAL2GOBJ(self);
62
+ shape = garrow_tensor_get_shape(tensor, &n_dimensions);
63
+ if (n_dimensions != 2) {
64
+ g_free(shape);
65
+ rb_raise(rb_eArgError,
66
+ "the number of dimensions must be 2: <%d>", n_dimensions);
67
+ }
68
+
69
+ value_type = garrow_tensor_get_value_type(tensor);
70
+ if (value_type == GARROW_TYPE_INT32) {
71
+ gsl_matrix_int *matrix;
72
+ GArrowBuffer *buffer;
73
+ GBytes *data;
74
+ gconstpointer data_raw;
75
+ gsize data_size;
76
+
77
+ matrix = gsl_matrix_int_alloc(shape[0], shape[1]);
78
+ buffer = garrow_tensor_get_buffer(tensor);
79
+ data = garrow_buffer_get_data(buffer);
80
+ data_raw = g_bytes_get_data(data, &data_size);
81
+ memcpy(matrix->data, data_raw, data_size);
82
+ g_bytes_unref(data);
83
+ g_object_unref(buffer);
84
+
85
+ rb_matrix = Data_Wrap_Struct(cgsl_matrix_int,
86
+ NULL,
87
+ gsl_matrix_int_free,
88
+ matrix);
89
+ } else if (value_type == GARROW_TYPE_DOUBLE) {
90
+ gsl_matrix *matrix;
91
+ GArrowBuffer *buffer;
92
+ GBytes *data;
93
+ gconstpointer data_raw;
94
+ gsize data_size;
95
+
96
+ matrix = gsl_matrix_alloc(shape[0], shape[1]);
97
+ buffer = garrow_tensor_get_buffer(tensor);
98
+ data = garrow_buffer_get_data(buffer);
99
+ data_raw = g_bytes_get_data(data, &data_size);
100
+ memcpy(matrix->data, data_raw, data_size);
101
+ g_bytes_unref(data);
102
+ g_object_unref(buffer);
103
+
104
+ rb_matrix = Data_Wrap_Struct(cgsl_matrix,
105
+ NULL,
106
+ gsl_matrix_free,
107
+ matrix);
108
+ } else {
109
+ GArrowDataType *value_data_type;
110
+ VALUE rb_value_data_type;
111
+
112
+ g_free(shape);
113
+ value_data_type = garrow_tensor_get_value_data_type(tensor);
114
+ rb_value_data_type = GOBJ2RVAL(value_data_type);
115
+ g_object_unref(value_data_type);
116
+ rb_raise(rb_eArgError,
117
+ "value data type must be int32 or double: <%" PRIsVALUE ">",
118
+ rb_value_data_type);
119
+ }
120
+
121
+ g_free(shape);
122
+
123
+ return rb_matrix;
124
+ }
125
+
126
+ static VALUE
127
+ rb_gsl_matrix_int_to_arrow(VALUE self)
128
+ {
129
+ gsl_matrix_int *matrix = NULL;
130
+ GArrowInt32DataType *data_type;
131
+ GArrowBuffer *data;
132
+ gint64 shape[2];
133
+ GArrowTensor *tensor;
134
+ VALUE rb_tensor;
135
+
136
+ Data_Get_Struct(self, gsl_matrix_int, matrix);
137
+
138
+ data_type = garrow_int32_data_type_new();
139
+ data = garrow_buffer_new((const guint8 *)(matrix->data),
140
+ sizeof(gint32) * matrix->size1 * matrix->size2);
141
+ shape[0] = matrix->size1;
142
+ shape[1] = matrix->size2;
143
+ tensor = garrow_tensor_new(GARROW_DATA_TYPE(data_type),
144
+ data,
145
+ shape,
146
+ 2,
147
+ NULL,
148
+ 0,
149
+ NULL,
150
+ 0);
151
+ g_object_unref(data);
152
+ g_object_unref(data_type);
153
+
154
+ rb_tensor = GOBJ2RVAL(tensor);
155
+ g_object_unref(tensor);
156
+
157
+ return rb_tensor;
158
+ }
159
+
160
+ static VALUE
161
+ rb_gsl_matrix_to_arrow(VALUE self)
162
+ {
163
+ gsl_matrix *matrix = NULL;
164
+ GArrowDoubleDataType *data_type;
165
+ GArrowBuffer *data;
166
+ gint64 shape[2];
167
+ GArrowTensor *tensor;
168
+ VALUE rb_tensor;
169
+
170
+ Data_Get_Struct(self, gsl_matrix, matrix);
171
+
172
+ data_type = garrow_double_data_type_new();
173
+ data = garrow_buffer_new((const guint8 *)(matrix->data),
174
+ sizeof(gdouble) * matrix->size1 * matrix->size2);
175
+ shape[0] = matrix->size1;
176
+ shape[1] = matrix->size2;
177
+ tensor = garrow_tensor_new(GARROW_DATA_TYPE(data_type),
178
+ data,
179
+ shape,
180
+ 2,
181
+ NULL,
182
+ 0,
183
+ NULL,
184
+ 0);
185
+ g_object_unref(data);
186
+ g_object_unref(data_type);
187
+
188
+ rb_tensor = GOBJ2RVAL(tensor);
189
+ g_object_unref(tensor);
190
+
191
+ return rb_tensor;
192
+ }
193
+
194
+ void
195
+ Init_arrow_gsl(void)
196
+ {
197
+ VALUE rb_Arrow;
198
+ VALUE rb_ArrowInt32Array;
199
+ VALUE rb_ArrowTensor;
200
+
201
+ rb_Arrow = rb_const_get(rb_cObject, rb_intern("Arrow"));
202
+ rb_ArrowInt32Array = rb_const_get(rb_Arrow, rb_intern("Int32Array"));
203
+ rb_ArrowTensor = rb_const_get(rb_Arrow, rb_intern("Tensor"));
204
+
205
+ rb_define_method(rb_ArrowInt32Array, "to_gsl",
206
+ rb_arrow_int32_array_to_gsl, 0);
207
+ rb_define_method(rb_ArrowTensor, "to_gsl",
208
+ rb_arrow_tensor_to_gsl, 0);
209
+
210
+ /*
211
+ rb_define_method(cgsl_vector_int, "to_arrow",
212
+ rb_gsl_vector_int_to_arrow, 0);
213
+ rb_define_method(cgsl_vector, "to_arrow",
214
+ rb_gsl_vector_to_arrow, 0);
215
+ */
216
+
217
+ rb_define_method(cgsl_matrix_int, "to_arrow",
218
+ rb_gsl_matrix_int_to_arrow, 0);
219
+ rb_define_method(cgsl_matrix, "to_arrow",
220
+ rb_gsl_matrix_to_arrow, 0);
221
+ }
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module ArrowGSL
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-gsl/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-gsl
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-gsl/arrow-gsl.c
143
144
  - ext/arrow-gsl/extconf.rb
144
145
  - lib/arrow-gsl.rb
145
146
  - lib/arrow-gsl/version.rb
@@ -176,6 +177,6 @@ summary: Red Arrow GSL is a library that provides converters between Apache Arro
176
177
  data (`GSL::Vector` and `GSL::Vector::Int`) / matrix data (`GSL::Matrix::*`).
177
178
  test_files:
178
179
  - test/test-to-gsl.rb
179
- - test/test-to-arrow.rb
180
- - test/helper.rb
181
180
  - test/run-test.rb
181
+ - test/helper.rb
182
+ - test/test-to-arrow.rb