paddlec 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +674 -0
- data/README.md +56 -0
- data/ext/libpaddlec/arithmetic.c +2486 -0
- data/ext/libpaddlec/comparison.c +683 -0
- data/ext/libpaddlec/complex.c +349 -0
- data/ext/libpaddlec/delay.c +240 -0
- data/ext/libpaddlec/fir_filter.c +724 -0
- data/ext/libpaddlec/fir_filter_avx.c +2645 -0
- data/ext/libpaddlec/fir_filter_neon.c +1767 -0
- data/ext/libpaddlec/fir_filter_sse.c +1677 -0
- data/ext/libpaddlec/libpaddlec.c +933 -0
- data/ext/libpaddlec/libpaddlec.h +473 -0
- data/ext/libpaddlec/math.c +563 -0
- data/ext/libpaddlec/no_fast_math.c +955 -0
- data/ext/libpaddlec/rounding.c +503 -0
- data/ext/paddlec/complex_buffer.c +3555 -0
- data/ext/paddlec/complex_buffer.h +28 -0
- data/ext/paddlec/delay.c +214 -0
- data/ext/paddlec/delay.h +29 -0
- data/ext/paddlec/extconf.rb +106 -0
- data/ext/paddlec/fir_filter.c +892 -0
- data/ext/paddlec/fir_filter.h +28 -0
- data/ext/paddlec/float_buffer.c +4770 -0
- data/ext/paddlec/float_buffer.h +28 -0
- data/ext/paddlec/paddlec.c +788 -0
- data/ext/paddlec/paddlec.h +76 -0
- data/ext/paddlec/pulseaudio.c +6767 -0
- data/ext/paddlec/pulseaudio.h +30 -0
- data/lib/paddlec.rb +26 -0
- data/lib/paddlec/version.rb +3 -0
- data/paddlec.gemspec +55 -0
- data/samples/fmdemod.rb +121 -0
- data/samples/fmdemod_chunk.rb +120 -0
- data/samples/fmdemod_chunk_buffer.rb +144 -0
- data/samples/stereo_chunk.rb +161 -0
- metadata +99 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
/* Copyright (C) 2019 Théotime Bollengier <theotime.bollengier@gmail.com>
|
2
|
+
*
|
3
|
+
* This file is part of PaddleC
|
4
|
+
*
|
5
|
+
* PaddleC is free software: you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* PaddleC is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU General Public License
|
16
|
+
* along with PaddleC. If not, see <https://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef PADDLEC_FIR_FILTER_BUFFER_H
|
20
|
+
#define PADDLEC_FIR_FILTER_BUFFER_H
|
21
|
+
|
22
|
+
#include <ruby.h>
|
23
|
+
#include "libpaddlec.h"
|
24
|
+
|
25
|
+
void Init_paddlec_fir_filter();
|
26
|
+
|
27
|
+
#endif /* PADDLEC_FIR_FILTER_BUFFER_H */
|
28
|
+
|
@@ -0,0 +1,4770 @@
|
|
1
|
+
/* Copyright (C) 2019-2020 Théotime Bollengier <theotime.bollengier@gmail.com>
|
2
|
+
*
|
3
|
+
* This file is part of PaddleC
|
4
|
+
*
|
5
|
+
* PaddleC is free software: you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* PaddleC is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU General Public License
|
16
|
+
* along with PaddleC. If not, see <https://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby.h>
|
20
|
+
#include "libpaddlec.h"
|
21
|
+
#include "paddlec.h"
|
22
|
+
#include "float_buffer.h"
|
23
|
+
#include "complex_buffer.h"
|
24
|
+
|
25
|
+
|
26
|
+
/* Document-class: PaddleC::FloatBuffer
|
27
|
+
*
|
28
|
+
* A a Ruby object that wraps a native array of single floats.
|
29
|
+
*/
|
30
|
+
|
31
|
+
|
32
|
+
VALUE c_FloatBuffer;
|
33
|
+
|
34
|
+
|
35
|
+
static void paddlec_float_buffer_free(void *p)
|
36
|
+
{
|
37
|
+
pdlc_buffer_t *fbuf = (pdlc_buffer_t*)p;
|
38
|
+
pdlc_buffer_free(fbuf);
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
static size_t paddlec_float_buffer_size(const void* data)
|
43
|
+
{
|
44
|
+
pdlc_buffer_t *fbuf = (pdlc_buffer_t*)data;
|
45
|
+
return sizeof(pdlc_buffer_t) + fbuf->capacity*sizeof(float);
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
static const rb_data_type_t paddlec_float_buffer_type = {
|
50
|
+
.wrap_struct_name = "paddlec_float_buffer_struct",
|
51
|
+
.function = {
|
52
|
+
.dmark = NULL,
|
53
|
+
.dfree = paddlec_float_buffer_free,
|
54
|
+
.dsize = paddlec_float_buffer_size,
|
55
|
+
},
|
56
|
+
.data = NULL,
|
57
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
58
|
+
};
|
59
|
+
|
60
|
+
|
61
|
+
static VALUE paddlec_float_buffer_alloc(VALUE klass)
|
62
|
+
{
|
63
|
+
VALUE obj;
|
64
|
+
pdlc_buffer_t *fbuf;
|
65
|
+
|
66
|
+
fbuf = pdlc_buffer_new(0);
|
67
|
+
obj = TypedData_Wrap_Struct(klass, &paddlec_float_buffer_type, fbuf);
|
68
|
+
|
69
|
+
return obj;
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
pdlc_buffer_t* paddlec_float_buffer_get_struct(VALUE obj)
|
74
|
+
{
|
75
|
+
pdlc_buffer_t *fbuf;
|
76
|
+
TypedData_Get_Struct(obj, pdlc_buffer_t, &paddlec_float_buffer_type, fbuf);
|
77
|
+
return fbuf;
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
/* @return [PaddleC::FloatBuffer]
|
82
|
+
* @overload initialize(length = 0, value = 0.0)
|
83
|
+
* @param length [Integer] the length of the buffer
|
84
|
+
* @param value [Float] the value which is set to all elements of the buffer
|
85
|
+
* @return [PaddleC::FloatBuffer]
|
86
|
+
* @overload initialize(a)
|
87
|
+
* @param a [Array<Float>, PaddleC::FloatBuffer] an array of float, or a FloatBuffer
|
88
|
+
* @return [PaddleC::FloatBuffer]
|
89
|
+
* @overload initialize(str)
|
90
|
+
* @param str [String] a binary string
|
91
|
+
* @return [PaddleC::FloatBuffer]
|
92
|
+
*/
|
93
|
+
static VALUE paddlec_float_buffer_initialize(int argc, VALUE *argv, VALUE self)
|
94
|
+
{
|
95
|
+
pdlc_buffer_t *fbuf;
|
96
|
+
VALUE rblength, rbvalue;
|
97
|
+
long length = 0;
|
98
|
+
float value = 0.0f;
|
99
|
+
size_t i;
|
100
|
+
const pdlc_buffer_t *ofbuf;
|
101
|
+
|
102
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
103
|
+
|
104
|
+
rb_scan_args(argc, argv, "02", &rblength, &rbvalue);
|
105
|
+
|
106
|
+
if (rb_class_of(rblength) == rb_cArray) {
|
107
|
+
if (rbvalue != Qnil)
|
108
|
+
rb_raise(rb_eArgError, "Not expecting another argument along with the array");
|
109
|
+
length = rb_array_len(rblength);
|
110
|
+
pdlc_buffer_resize(fbuf, (size_t)length, 0);
|
111
|
+
for (i = 0; i < (size_t)length; i++)
|
112
|
+
fbuf->data[i] = (float)NUM2DBL(rb_ary_entry(rblength, i));
|
113
|
+
}
|
114
|
+
else if (rb_class_of(rblength) == c_FloatBuffer) {
|
115
|
+
if (rbvalue != Qnil)
|
116
|
+
rb_raise(rb_eArgError, "Not expecting another argument along with the FloatBuffer");
|
117
|
+
ofbuf = paddlec_float_buffer_get_struct(rblength);
|
118
|
+
length = (long)ofbuf->length;
|
119
|
+
pdlc_buffer_resize(fbuf, (size_t)length, 0);
|
120
|
+
memcpy(fbuf->data, ofbuf->data, length*sizeof(float));
|
121
|
+
}
|
122
|
+
else if (rb_class_of(rblength) == rb_cString) {
|
123
|
+
length = (long)RSTRING_LEN(rblength) / sizeof(float);
|
124
|
+
pdlc_buffer_resize(fbuf, (size_t)length, 0);
|
125
|
+
memcpy(fbuf->data, StringValuePtr(rblength), length*sizeof(float));
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
if (rblength != Qnil)
|
129
|
+
length = NUM2LONG(rblength);
|
130
|
+
if (rbvalue != Qnil)
|
131
|
+
value = (float)NUM2DBL(rbvalue);
|
132
|
+
if (length < 0)
|
133
|
+
rb_raise(rb_eArgError, "negative buffer size");
|
134
|
+
|
135
|
+
if (length > 0) {
|
136
|
+
if (value != 0.0) {
|
137
|
+
pdlc_buffer_resize(fbuf, (size_t)length, 0);
|
138
|
+
pdlc_buffer_set(fbuf, value);
|
139
|
+
}
|
140
|
+
else
|
141
|
+
pdlc_buffer_resize(fbuf, (size_t)length, 1);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
return self;
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
/* @!group Array
|
150
|
+
*/
|
151
|
+
|
152
|
+
/* Change the length of the buffer
|
153
|
+
* @param new_length [Integer] the new length of the buffer, as a positive integer
|
154
|
+
* @return [self] +self+
|
155
|
+
*/
|
156
|
+
static VALUE paddlec_float_buffer_resize(VALUE self, VALUE new_length)
|
157
|
+
{
|
158
|
+
pdlc_buffer_t *fbuf;
|
159
|
+
long length;
|
160
|
+
|
161
|
+
length = NUM2LONG(new_length);
|
162
|
+
if (length < 0)
|
163
|
+
rb_raise(rb_eArgError, "New length cannot be less than 0");
|
164
|
+
|
165
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
166
|
+
|
167
|
+
pdlc_buffer_resize(fbuf, (size_t)length, 1);
|
168
|
+
|
169
|
+
return self;
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
/* @return [Array<Float>]
|
174
|
+
*/
|
175
|
+
static VALUE paddlec_float_buffer_to_a(VALUE self)
|
176
|
+
{
|
177
|
+
size_t i;
|
178
|
+
pdlc_buffer_t *fbuf;
|
179
|
+
VALUE ar;
|
180
|
+
|
181
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
182
|
+
ar = rb_ary_new_capa(fbuf->length);
|
183
|
+
for (i = 0; i < fbuf->length; i++)
|
184
|
+
rb_ary_store(ar, i, DBL2NUM((double)fbuf->data[i]));
|
185
|
+
|
186
|
+
return ar;
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
/* @return [Integer] the length of the buffer
|
191
|
+
*/
|
192
|
+
static VALUE paddlec_float_buffer_length(VALUE self)
|
193
|
+
{
|
194
|
+
pdlc_buffer_t *fbuf = paddlec_float_buffer_get_struct(self);
|
195
|
+
return ULONG2NUM(fbuf->length);
|
196
|
+
}
|
197
|
+
|
198
|
+
|
199
|
+
/* @return [Boolean] true if length < 1
|
200
|
+
*/
|
201
|
+
static VALUE paddlec_float_buffer_isempty(VALUE self)
|
202
|
+
{
|
203
|
+
pdlc_buffer_t *fbuf = paddlec_float_buffer_get_struct(self);
|
204
|
+
return ((fbuf->length < 1) ? Qtrue : Qfalse);
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
/* Element Reference -- Returns the element at index,
|
209
|
+
* or returns a sub-buffer starting at the start index and continuing for length elements,
|
210
|
+
* or returns a sub-buffer specified by range of indices.
|
211
|
+
*
|
212
|
+
* Negative indices count backward from the end of the buffer (-1 is the last element).
|
213
|
+
* Returns nil if the index (or starting index) are out of range.
|
214
|
+
*
|
215
|
+
* @overload [](index)
|
216
|
+
* @param index [Integer] the index of the element
|
217
|
+
* @return [Float, nil] the element at +index+, or +nil+ if index out of bound
|
218
|
+
* @overload [](start, length)
|
219
|
+
* @param start [Integer] the start index of the sub-buffer
|
220
|
+
* @param length [Integer] the length of the sub-buffer
|
221
|
+
* @return [PaddleC::FloatBuffer, nil] a new FloatBuffer, or +nil+ if indexes are out of bound
|
222
|
+
* @overload [](range)
|
223
|
+
* @param range [Range] the range of indexes of the sub-buffer
|
224
|
+
* @return [PaddleC::FloatBuffer, nil] a new FloatBuffer, or +nil+ if indexes are out of bound
|
225
|
+
*/
|
226
|
+
static VALUE paddlec_float_buffer_get(int argc, VALUE *argv, VALUE self)
|
227
|
+
{
|
228
|
+
const pdlc_buffer_t *fbuf;
|
229
|
+
pdlc_buffer_t *nfbuf;
|
230
|
+
VALUE rbind_start_range;
|
231
|
+
VALUE rblength;
|
232
|
+
long ind_start;
|
233
|
+
long ind_end;
|
234
|
+
long length;
|
235
|
+
VALUE res = Qnil;
|
236
|
+
VALUE beg, end;
|
237
|
+
int exc;
|
238
|
+
|
239
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
240
|
+
|
241
|
+
rb_scan_args(argc, argv, "11", &rbind_start_range, &rblength);
|
242
|
+
|
243
|
+
if (rblength == Qnil && rb_range_values(rbind_start_range, &beg, &end, &exc)) {
|
244
|
+
ind_start = NUM2LONG(beg);
|
245
|
+
if (ind_start < 0)
|
246
|
+
ind_start = (long)fbuf->length + ind_start;
|
247
|
+
if (ind_start < 0 || ind_start >= (long)fbuf->length)
|
248
|
+
return Qnil;
|
249
|
+
ind_end = NUM2LONG(end);
|
250
|
+
if (ind_end < 0)
|
251
|
+
ind_end = (long)fbuf->length + ind_end;
|
252
|
+
if (exc)
|
253
|
+
ind_end -= 1;
|
254
|
+
length = ind_end + 1 - ind_start;
|
255
|
+
if (length < 0)
|
256
|
+
length = 0;
|
257
|
+
}
|
258
|
+
else {
|
259
|
+
ind_start = NUM2LONG(rbind_start_range);
|
260
|
+
if (ind_start < 0)
|
261
|
+
ind_start = (long)fbuf->length + ind_start;
|
262
|
+
if (ind_start < 0 || ind_start >= (long)fbuf->length)
|
263
|
+
return Qnil;
|
264
|
+
if (rblength == Qnil)
|
265
|
+
return DBL2NUM((double)fbuf->data[ind_start]);
|
266
|
+
length = NUM2LONG(rblength);
|
267
|
+
if (length < 0)
|
268
|
+
return Qnil;
|
269
|
+
}
|
270
|
+
|
271
|
+
if ((ind_start + length) > (long)fbuf->length)
|
272
|
+
length = (long)fbuf->length - ind_start;
|
273
|
+
rblength = LONG2NUM(length);
|
274
|
+
|
275
|
+
res = rb_class_new_instance(1, &rblength, c_FloatBuffer);
|
276
|
+
|
277
|
+
nfbuf = paddlec_float_buffer_get_struct(res);
|
278
|
+
memcpy(nfbuf->data, fbuf->data + ind_start, length*sizeof(float));
|
279
|
+
|
280
|
+
return res;
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
/* Element Assignment -- Sets the element at index,
|
285
|
+
* or replaces a subarray from the start index for length elements,
|
286
|
+
* or replaces a subarray specified by the range of indices.
|
287
|
+
*
|
288
|
+
* Negative indices count backward from the end of the buffer (-1 is the last element).
|
289
|
+
* An exception is raised if indexes are out of bounds.
|
290
|
+
*
|
291
|
+
* @overload []=(index, value)
|
292
|
+
* @param index [Integer] the index of the element
|
293
|
+
* @param value [Float] the element to set at +index+
|
294
|
+
* @overload []=(start, length, vaule)
|
295
|
+
* @param start [Integer] the start index of the sub-buffer
|
296
|
+
* @param length [Integer] the length of the sub-buffer
|
297
|
+
* @param value [Float, Array<Float>, FloatBuffer] the element to set at +index+
|
298
|
+
* @overload []=(range, value)
|
299
|
+
* @param range [Range] the range of indexes of the sub-buffer
|
300
|
+
* @param value [Float, Array<Float>, FloatBuffer] the element to set at +index+
|
301
|
+
*/
|
302
|
+
static VALUE paddlec_float_buffer_set(int argc, VALUE *argv, VALUE self)
|
303
|
+
{
|
304
|
+
pdlc_buffer_t *fbuf;
|
305
|
+
const pdlc_buffer_t *ofbuf;
|
306
|
+
VALUE rbind_start_range;
|
307
|
+
VALUE rblength;
|
308
|
+
VALUE rbvalue;
|
309
|
+
long ind_start, length, i, j, ind_end;
|
310
|
+
VALUE beg, end;
|
311
|
+
int exc;
|
312
|
+
float value;
|
313
|
+
|
314
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
315
|
+
|
316
|
+
rb_scan_args(argc, argv, "111", &rbind_start_range, &rblength, &rbvalue);
|
317
|
+
|
318
|
+
if (rblength == Qnil && rb_range_values(rbind_start_range, &beg, &end, &exc)) {
|
319
|
+
ind_start = NUM2LONG(beg);
|
320
|
+
if (ind_start < 0)
|
321
|
+
ind_start = (long)fbuf->length + ind_start;
|
322
|
+
if (ind_start < 0 || ind_start >= (long)fbuf->length)
|
323
|
+
rb_raise(rb_eIndexError, "index out of bounds");
|
324
|
+
ind_end = NUM2LONG(end);
|
325
|
+
if (ind_end < 0)
|
326
|
+
ind_end = (long)fbuf->length + ind_end;
|
327
|
+
if (exc)
|
328
|
+
ind_end -= 1;
|
329
|
+
length = ind_end + 1 - ind_start;
|
330
|
+
}
|
331
|
+
else {
|
332
|
+
ind_start = NUM2LONG(rbind_start_range);
|
333
|
+
if (ind_start < 0)
|
334
|
+
ind_start = (long)fbuf->length + ind_start;
|
335
|
+
if (ind_start < 0 || ind_start >= (long)fbuf->length)
|
336
|
+
rb_raise(rb_eIndexError, "index out of bounds");
|
337
|
+
if (rblength == Qnil)
|
338
|
+
length = 1;
|
339
|
+
else
|
340
|
+
length = NUM2LONG(rblength);
|
341
|
+
}
|
342
|
+
if (length < 1)
|
343
|
+
rb_raise(rb_eIndexError, "index range maps to %ld..%ld which does not have a strictly positive length", ind_start, ind_start + length - 1);
|
344
|
+
if ((ind_start + length) > (long)fbuf->length)
|
345
|
+
rb_raise(rb_eIndexError, "index range maps to %ld..%ld which exceeds the buffer length [0..%lu]", ind_start, ind_start + length - 1, fbuf->length - 1);
|
346
|
+
|
347
|
+
if (rb_class_of(rbvalue) == rb_cArray) {
|
348
|
+
if (length != rb_array_len(rbvalue))
|
349
|
+
rb_raise(rb_eArgError, "trying to assign a %ld long array to a %ld long sub-buffer", rb_array_len(rbvalue), length);
|
350
|
+
for (j = 0, i = ind_start; j < length; i++, j++)
|
351
|
+
fbuf->data[i] = (float)NUM2DBL(rb_ary_entry(rbvalue, j));
|
352
|
+
}
|
353
|
+
else if (rb_class_of(rbvalue) == c_FloatBuffer) {
|
354
|
+
ofbuf = paddlec_float_buffer_get_struct(rbvalue);
|
355
|
+
if (length != (long)ofbuf->length)
|
356
|
+
rb_raise(rb_eArgError, "trying to assign a %lu long %"PRIsVALUE" to a %ld long sub-buffer", ofbuf->length, rb_class_name(rb_class_of(rbvalue)), length);
|
357
|
+
for (j = 0, i = ind_start; j < length; i++, j++)
|
358
|
+
fbuf->data[i] = ofbuf->data[j];
|
359
|
+
}
|
360
|
+
else {
|
361
|
+
value = (float)NUM2DBL(rbvalue);
|
362
|
+
ind_end = ind_start + length;
|
363
|
+
for (i = ind_start; i < ind_end; i++)
|
364
|
+
fbuf->data[i] = value;
|
365
|
+
}
|
366
|
+
|
367
|
+
return rbvalue;
|
368
|
+
}
|
369
|
+
|
370
|
+
|
371
|
+
/* @see Array#zip
|
372
|
+
* @return [Array]
|
373
|
+
*/
|
374
|
+
static VALUE paddlec_float_buffer_zip(int argc, VALUE *argv, VALUE self)
|
375
|
+
{
|
376
|
+
VALUE a, res;
|
377
|
+
|
378
|
+
a = paddlec_float_buffer_to_a(self);
|
379
|
+
res = rb_funcallv(a, id_zip, argc, argv);
|
380
|
+
|
381
|
+
return res;
|
382
|
+
}
|
383
|
+
|
384
|
+
|
385
|
+
/* @!endgroup
|
386
|
+
*/
|
387
|
+
|
388
|
+
|
389
|
+
/* @!group Enumerable
|
390
|
+
*/
|
391
|
+
|
392
|
+
|
393
|
+
static VALUE paddlec_float_buffer_to_enum_get_size_block(VALUE block_arg, VALUE data, int argc, VALUE* argv)
|
394
|
+
{
|
395
|
+
(void)block_arg;
|
396
|
+
(void)argc;
|
397
|
+
(void)argv;
|
398
|
+
return rb_funcallv(data, id_length, 0, NULL);
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
/* Calls the given block once for each element in +self+,
|
403
|
+
* passing that element as a parameter.
|
404
|
+
* Returns the array itself, or, if no block is given, an Enumerator is returned.
|
405
|
+
* @return [Object, Enumerator]
|
406
|
+
* @overload each{|item| block}
|
407
|
+
* @return [Array<Float>] self
|
408
|
+
* @overload each
|
409
|
+
* @return [Enumerator]
|
410
|
+
*/
|
411
|
+
static VALUE paddlec_float_buffer_each(VALUE self)
|
412
|
+
{
|
413
|
+
size_t i;
|
414
|
+
pdlc_buffer_t *fbuf;
|
415
|
+
VALUE res;
|
416
|
+
VALUE each_sym;
|
417
|
+
|
418
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
419
|
+
|
420
|
+
if (rb_block_given_p()) {
|
421
|
+
for (i = 0; i < fbuf->length; i++)
|
422
|
+
rb_yield(DBL2NUM(fbuf->data[i]));
|
423
|
+
res = self;
|
424
|
+
}
|
425
|
+
else {
|
426
|
+
each_sym = ID2SYM(id_each);
|
427
|
+
res = rb_block_call(self, id_to_enum, 1, &each_sym, paddlec_float_buffer_to_enum_get_size_block, self);
|
428
|
+
}
|
429
|
+
|
430
|
+
return res;
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
/* Invokes the given block once for each element of self,
|
435
|
+
* replacing the element with the value returned by the block.
|
436
|
+
* If no block is given, an Enumerator is returned instead.
|
437
|
+
* @overload collect!{|value| block}
|
438
|
+
* @return [self]
|
439
|
+
* @overload collect!
|
440
|
+
* @return [Enumerator]
|
441
|
+
*/
|
442
|
+
static VALUE paddlec_float_buffer_collect_inp(VALUE self)
|
443
|
+
{
|
444
|
+
pdlc_buffer_t *fbuf;
|
445
|
+
size_t i;
|
446
|
+
VALUE res;
|
447
|
+
VALUE collectI_sym;
|
448
|
+
|
449
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
450
|
+
|
451
|
+
if (rb_block_given_p()) {
|
452
|
+
for (i = 0; i < fbuf->length; i++)
|
453
|
+
fbuf->data[i] = (float)NUM2DBL(rb_yield(DBL2NUM(fbuf->data[i])));
|
454
|
+
res = self;
|
455
|
+
}
|
456
|
+
else {
|
457
|
+
collectI_sym = ID2SYM(id_collectI);
|
458
|
+
res = rb_block_call(self, id_to_enum, 1, &collectI_sym, paddlec_float_buffer_to_enum_get_size_block, self);
|
459
|
+
}
|
460
|
+
|
461
|
+
return res;
|
462
|
+
}
|
463
|
+
|
464
|
+
|
465
|
+
/* @!endgroup
|
466
|
+
*/
|
467
|
+
|
468
|
+
|
469
|
+
/* @!group Object
|
470
|
+
*/
|
471
|
+
|
472
|
+
|
473
|
+
/* Returns a new FloatBuffer with the same content as +self+.
|
474
|
+
* @return [PaddleC::FloatBuffer]
|
475
|
+
*/
|
476
|
+
static VALUE paddlec_float_buffer_clone(VALUE self)
|
477
|
+
{
|
478
|
+
const pdlc_buffer_t *fbuf;
|
479
|
+
pdlc_buffer_t *newfbuf;
|
480
|
+
VALUE newFloatBuffer;
|
481
|
+
VALUE len;
|
482
|
+
|
483
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
484
|
+
len = rb_funcallv(self, id_length, 0, NULL);
|
485
|
+
|
486
|
+
newFloatBuffer = rb_class_new_instance(1, &len, c_FloatBuffer);
|
487
|
+
newfbuf = paddlec_float_buffer_get_struct(newFloatBuffer);
|
488
|
+
memcpy(newfbuf->data, fbuf->data, fbuf->length*sizeof(float));
|
489
|
+
|
490
|
+
return newFloatBuffer;
|
491
|
+
}
|
492
|
+
|
493
|
+
|
494
|
+
/* @!endgroup
|
495
|
+
*/
|
496
|
+
|
497
|
+
|
498
|
+
/* @!group String
|
499
|
+
*/
|
500
|
+
|
501
|
+
|
502
|
+
#define PADDLEC_FLOAT_BUFFER_MAX_TO_S_ELEMS 1024
|
503
|
+
/* @return [String]
|
504
|
+
*/
|
505
|
+
static VALUE paddlec_float_buffer_to_s(VALUE self)
|
506
|
+
{
|
507
|
+
const pdlc_buffer_t *fbuf;
|
508
|
+
size_t nb_elm_to_print;
|
509
|
+
char *cstr, *p;
|
510
|
+
size_t i;
|
511
|
+
size_t avail;
|
512
|
+
VALUE str;
|
513
|
+
|
514
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
515
|
+
|
516
|
+
nb_elm_to_print = fbuf->length;
|
517
|
+
if (nb_elm_to_print > PADDLEC_FLOAT_BUFFER_MAX_TO_S_ELEMS)
|
518
|
+
nb_elm_to_print = PADDLEC_FLOAT_BUFFER_MAX_TO_S_ELEMS;
|
519
|
+
|
520
|
+
avail = 16*nb_elm_to_print;
|
521
|
+
cstr = malloc(avail+64);
|
522
|
+
p = cstr;
|
523
|
+
sprintf(p, "["); p += strlen(p);
|
524
|
+
if (nb_elm_to_print > 0) {
|
525
|
+
switch (fpclassify(fbuf->data[0])) {
|
526
|
+
case FP_NORMAL:
|
527
|
+
case FP_SUBNORMAL:
|
528
|
+
case FP_ZERO:
|
529
|
+
sprintf(p, "%.7g", fbuf->data[0]);
|
530
|
+
break;
|
531
|
+
case FP_INFINITE:
|
532
|
+
sprintf(p, "%sInfinity", (fbuf->data[0] < 0.0f) ? "-" : "");
|
533
|
+
break;
|
534
|
+
default:
|
535
|
+
sprintf(p, "NaN");
|
536
|
+
}
|
537
|
+
p += strlen(p);
|
538
|
+
}
|
539
|
+
i = 1;
|
540
|
+
while ((size_t)(p - cstr) < avail && i < fbuf->length) {
|
541
|
+
switch (fpclassify(fbuf->data[i])) {
|
542
|
+
case FP_NORMAL:
|
543
|
+
case FP_SUBNORMAL:
|
544
|
+
case FP_ZERO:
|
545
|
+
sprintf(p, ", %.7g", fbuf->data[i]);
|
546
|
+
break;
|
547
|
+
case FP_INFINITE:
|
548
|
+
sprintf(p, ", %sInfinity", (fbuf->data[i] < 0.0f) ? "-" : "");
|
549
|
+
break;
|
550
|
+
default:
|
551
|
+
sprintf(p, ", NaN");
|
552
|
+
}
|
553
|
+
p += strlen(p);
|
554
|
+
i++;
|
555
|
+
}
|
556
|
+
if (i < fbuf->length) {
|
557
|
+
sprintf(p, ", ...(+%lu)", fbuf->length - i);
|
558
|
+
p += strlen(p);
|
559
|
+
}
|
560
|
+
sprintf(p, "]");
|
561
|
+
p += 1;
|
562
|
+
|
563
|
+
str = rb_str_new(cstr, (long)(p - cstr));
|
564
|
+
|
565
|
+
free(cstr);
|
566
|
+
|
567
|
+
return str;
|
568
|
+
}
|
569
|
+
|
570
|
+
|
571
|
+
/* @return [String]
|
572
|
+
*/
|
573
|
+
static VALUE paddlec_float_buffer_to_gplot(VALUE self)
|
574
|
+
{
|
575
|
+
const pdlc_buffer_t *fbuf;
|
576
|
+
size_t nb_elm_to_print;
|
577
|
+
char *cstr, *p;
|
578
|
+
size_t i;
|
579
|
+
size_t avail;
|
580
|
+
VALUE str;
|
581
|
+
|
582
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
583
|
+
|
584
|
+
nb_elm_to_print = fbuf->length;
|
585
|
+
|
586
|
+
avail = 16*nb_elm_to_print;
|
587
|
+
cstr = malloc(avail+64);
|
588
|
+
p = cstr;
|
589
|
+
i = 0;
|
590
|
+
while (i < fbuf->length && (size_t)(p - cstr) < avail) {
|
591
|
+
switch (fpclassify(fbuf->data[i])) {
|
592
|
+
case FP_NORMAL:
|
593
|
+
case FP_SUBNORMAL:
|
594
|
+
case FP_ZERO:
|
595
|
+
sprintf(p, "%.7g\n", fbuf->data[i]);
|
596
|
+
break;
|
597
|
+
case FP_INFINITE:
|
598
|
+
sprintf(p, "%sInfinity\n", (fbuf->data[i] < 0.0f) ? "-" : "");
|
599
|
+
break;
|
600
|
+
default:
|
601
|
+
sprintf(p, "NaN\n");
|
602
|
+
}
|
603
|
+
p += strlen(p);
|
604
|
+
i++;
|
605
|
+
}
|
606
|
+
|
607
|
+
str = rb_str_new(cstr, (long)(p - cstr));
|
608
|
+
|
609
|
+
free(cstr);
|
610
|
+
|
611
|
+
return str;
|
612
|
+
}
|
613
|
+
|
614
|
+
|
615
|
+
/* Packs the contents of the buffer into a binary string, according to +format+.
|
616
|
+
* If the optional +outbuf+ is present, it must reference a String, which will receive the data.
|
617
|
+
* In this case, +outbuf will be resized accordingly.
|
618
|
+
* @return [String] the content of the buffer as a binary string
|
619
|
+
* @overload pack(format, outbuf = nil)
|
620
|
+
* @param format [Symbol] either +:u8+, +:s8+, +:u16+, +:s16+, +:u32+, +:s328+ or +:f32+
|
621
|
+
* @param outbuf [String, nil]
|
622
|
+
*/
|
623
|
+
static VALUE paddlec_float_buffer_pack(int argc, VALUE *argv, VALUE self)
|
624
|
+
{
|
625
|
+
const pdlc_buffer_t *fbuf;
|
626
|
+
VALUE str, format;
|
627
|
+
size_t i, len, slen;
|
628
|
+
ID fmt;
|
629
|
+
uint8_t *u8;
|
630
|
+
int8_t *s8;
|
631
|
+
uint16_t *u16;
|
632
|
+
int16_t *s16;
|
633
|
+
uint32_t *u32;
|
634
|
+
int32_t *s32;
|
635
|
+
float *f32;
|
636
|
+
|
637
|
+
rb_scan_args(argc, argv, "11", &format, &str);
|
638
|
+
|
639
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
640
|
+
len = fbuf->length;
|
641
|
+
|
642
|
+
if (rb_class_of(format) != rb_cSymbol)
|
643
|
+
rb_raise(rb_eTypeError, "format must be a symbol, not a %"PRIsVALUE, rb_class_name(rb_class_of(format)));
|
644
|
+
fmt = SYM2ID(format);
|
645
|
+
if (fmt == id_u8 || fmt == id_s8)
|
646
|
+
slen = len;
|
647
|
+
else if (fmt == id_u16 || fmt == id_s16)
|
648
|
+
slen = len * 2;
|
649
|
+
else if (fmt == id_u32 || fmt == id_s32 || fmt == id_f32)
|
650
|
+
slen = len * 4;
|
651
|
+
else
|
652
|
+
rb_raise(rb_eTypeError, "format must be either :u8, :s8, :u16, :s16, :u32, :s32 or :f32, not %"PRIsVALUE, format);
|
653
|
+
|
654
|
+
if (str == Qnil)
|
655
|
+
str = rb_usascii_str_new_cstr("");
|
656
|
+
else if (!rb_obj_is_kind_of(str, rb_cString))
|
657
|
+
rb_raise(rb_eTypeError, "expecting a string, not a %"PRIsVALUE, rb_class_name(rb_class_of(str)));
|
658
|
+
str = rb_str_resize(str, slen);
|
659
|
+
|
660
|
+
if (fmt == id_u8) {
|
661
|
+
u8 = (uint8_t*)rb_string_value_ptr(&str);
|
662
|
+
for (i = 0; i < len; i++)
|
663
|
+
u8[i] = (uint8_t)fminf(255.0f, fmaxf(0.0f, (fbuf->data[i] * 128.0f) + 128.0f));
|
664
|
+
}
|
665
|
+
else if (fmt == id_s8) {
|
666
|
+
s8 = (int8_t*)rb_string_value_ptr(&str);
|
667
|
+
for (i = 0; i < len; i++)
|
668
|
+
s8[i] = (int8_t)fminf(127.0f, fmaxf(-128.0f, fbuf->data[i] * 128.0f));
|
669
|
+
}
|
670
|
+
else if (fmt == id_u16) {
|
671
|
+
u16 = (uint16_t*)rb_string_value_ptr(&str);
|
672
|
+
for (i = 0; i < len; i++)
|
673
|
+
u16[i] = (uint16_t)fminf(65535.0f, fmaxf(0.0f, (fbuf->data[i] * 32768.0f) + 32768.0f));
|
674
|
+
}
|
675
|
+
else if (fmt == id_s16) {
|
676
|
+
s16 = (int16_t*)rb_string_value_ptr(&str);
|
677
|
+
for (i = 0; i < len; i++)
|
678
|
+
s16[i] = (uint16_t)fminf(32767.0f, fmaxf(-32768.0f, fbuf->data[i] * 32768.0f));
|
679
|
+
}
|
680
|
+
else if (fmt == id_u32) {
|
681
|
+
u32 = (uint32_t*)rb_string_value_ptr(&str);
|
682
|
+
for (i = 0; i < len; i++)
|
683
|
+
u32[i] = (uint32_t)fminf(4294967295.0f, fmaxf(0.0f, (fbuf->data[i] * 2147483648.0f) + 2147483648.0f));
|
684
|
+
}
|
685
|
+
else if (fmt == id_s32) {
|
686
|
+
s32 = (int32_t*)rb_string_value_ptr(&str);
|
687
|
+
for (i = 0; i < len; i++)
|
688
|
+
s32[i] = (int32_t)fminf(2147483647.0f, fmaxf(-2147483648.0f, fbuf->data[i] * 2147483648.0f));
|
689
|
+
}
|
690
|
+
else if (fmt == id_f32) {
|
691
|
+
f32 = (float*)rb_string_value_ptr(&str);
|
692
|
+
memcpy(f32, fbuf->data, len*4);
|
693
|
+
}
|
694
|
+
|
695
|
+
return str;
|
696
|
+
}
|
697
|
+
|
698
|
+
|
699
|
+
/* Unpack the string +str+ into +self+ according to +format+.
|
700
|
+
* The float buffer is resized accordingly.
|
701
|
+
* Elements of +self+ will be in the range [-1, 1[;
|
702
|
+
* @param str [String]
|
703
|
+
* @param format [Symbol] either +:u8+, +:s8+, +:u16+, +:s16+, +:u32+, +:s328+ or +:f32+
|
704
|
+
* @return [self]
|
705
|
+
*/
|
706
|
+
static VALUE paddlec_float_buffer_unpack(VALUE self, VALUE str, VALUE format)
|
707
|
+
{
|
708
|
+
pdlc_buffer_t *fbuf;
|
709
|
+
ID fmt;
|
710
|
+
const void *ptr;
|
711
|
+
const uint8_t *u8;
|
712
|
+
const int8_t *s8;
|
713
|
+
const uint16_t *u16;
|
714
|
+
const int16_t *s16;
|
715
|
+
const uint32_t *u32;
|
716
|
+
const int32_t *s32;
|
717
|
+
const float *f32;
|
718
|
+
size_t i, len;
|
719
|
+
|
720
|
+
if (!rb_obj_is_kind_of(str, rb_cString))
|
721
|
+
rb_raise(rb_eTypeError, "expecting a string, not a %"PRIsVALUE, rb_class_name(rb_class_of(str)));
|
722
|
+
if (rb_class_of(format) != rb_cSymbol)
|
723
|
+
rb_raise(rb_eTypeError, "format must be a symbol, not a %"PRIsVALUE, rb_class_name(rb_class_of(format)));
|
724
|
+
fmt = SYM2ID(format);
|
725
|
+
ptr = rb_string_value_ptr(&str);
|
726
|
+
len = (size_t)RSTRING_LEN(str);
|
727
|
+
|
728
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
729
|
+
|
730
|
+
if (fmt == id_u8) {
|
731
|
+
u8 = ptr;
|
732
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
733
|
+
for (i = 0; i < len; i++)
|
734
|
+
fbuf->data[i] = ((float)u8[i] - 128.0f) / 128.0f;
|
735
|
+
}
|
736
|
+
else if (fmt == id_s8) {
|
737
|
+
s8 = ptr;
|
738
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
739
|
+
for (i = 0; i < len; i++)
|
740
|
+
fbuf->data[i] = (float)s8[i] / 128.0f;
|
741
|
+
}
|
742
|
+
else if (fmt == id_u16) {
|
743
|
+
u16 = ptr;
|
744
|
+
len /= 2;
|
745
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
746
|
+
for (i = 0; i < len; i++)
|
747
|
+
fbuf->data[i] = ((float)u16[i] - 32768.0f) / 32768.0f;
|
748
|
+
}
|
749
|
+
else if (fmt == id_s16) {
|
750
|
+
s16 = ptr;
|
751
|
+
len /= 2;
|
752
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
753
|
+
for (i = 0; i < len; i++)
|
754
|
+
fbuf->data[i] = (float)s16[i] / 32768.0f;
|
755
|
+
}
|
756
|
+
else if (fmt == id_u32) {
|
757
|
+
u32 = ptr;
|
758
|
+
len /= 4;
|
759
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
760
|
+
for (i = 0; i < len; i++)
|
761
|
+
fbuf->data[i] = ((float)u32[i] - 2147483648.0f) / 2147483648.0f;
|
762
|
+
}
|
763
|
+
else if (fmt == id_s32) {
|
764
|
+
s32 = ptr;
|
765
|
+
len /= 4;
|
766
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
767
|
+
for (i = 0; i < len; i++)
|
768
|
+
fbuf->data[i] = (float)s32[i] / 2147483648.0f;
|
769
|
+
}
|
770
|
+
else if (fmt == id_f32) {
|
771
|
+
f32 = ptr;
|
772
|
+
len /= 4;
|
773
|
+
pdlc_buffer_resize(fbuf, len, 0);
|
774
|
+
memcpy(fbuf->data, f32, len*4);
|
775
|
+
}
|
776
|
+
else
|
777
|
+
rb_raise(rb_eTypeError, "format must be either :u8, :s8, :u16, :s16, :u32, :s32 or :f32, not %"PRIsVALUE, format);
|
778
|
+
|
779
|
+
return self;
|
780
|
+
}
|
781
|
+
|
782
|
+
|
783
|
+
/* Unpack the string +str+ into a new {PaddleC::FloatBuffer} according to +format+.
|
784
|
+
* The float buffer is resized accordingly.
|
785
|
+
* Elements of +self+ will be in the range [-1, 1[;
|
786
|
+
* @param str [String]
|
787
|
+
* @param format [Symbol] either +:u8+, +:s8+, +:u16+, +:s16+, +:u32+, +:s328+ or +:f32+
|
788
|
+
* @return [PaddleC::FloatBuffer] a new {PaddleC::FloatBuffer} filled with values from +str+
|
789
|
+
*/
|
790
|
+
static VALUE paddlec_float_buffer_classunpack(VALUE self, VALUE str, VALUE format)
|
791
|
+
{
|
792
|
+
VALUE res = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
793
|
+
paddlec_float_buffer_unpack(res, str, format);
|
794
|
+
return res;
|
795
|
+
}
|
796
|
+
|
797
|
+
|
798
|
+
/* @!endgroup
|
799
|
+
*/
|
800
|
+
|
801
|
+
|
802
|
+
/* @!group FFI
|
803
|
+
*/
|
804
|
+
|
805
|
+
|
806
|
+
/* Returns the native pointer pointing to the array of floats as an integer
|
807
|
+
* @return [Integer] native pointer to the data
|
808
|
+
*/
|
809
|
+
static VALUE paddlec_float_buffer_native_ptr(VALUE self)
|
810
|
+
{
|
811
|
+
const pdlc_buffer_t *fbuf;
|
812
|
+
void *ptr;
|
813
|
+
VALUE res;
|
814
|
+
|
815
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
816
|
+
|
817
|
+
ptr = fbuf->data;
|
818
|
+
res = ULL2NUM( (sizeof(ptr) == 4) ? (unsigned long long int)(unsigned long int)ptr : (unsigned long long int)ptr );
|
819
|
+
|
820
|
+
return res;
|
821
|
+
}
|
822
|
+
|
823
|
+
|
824
|
+
/* Returns a +FFI::Pointer+ pointing to the native array of floats.
|
825
|
+
* +FFI+ must be requiered before +paddlec+ for this method to be defined.
|
826
|
+
* @return [FFI::Pointer] FFI::Pointer pointing to the native array of floats
|
827
|
+
*/
|
828
|
+
static VALUE paddlec_float_buffer_ffi_pointer(VALUE self)
|
829
|
+
{
|
830
|
+
const pdlc_buffer_t *fbuf;
|
831
|
+
VALUE type_and_addr[2];
|
832
|
+
VALUE res;
|
833
|
+
|
834
|
+
fbuf = paddlec_float_buffer_get_struct(self);
|
835
|
+
|
836
|
+
type_and_addr[0] = o_FFI_Type_FLOAT;
|
837
|
+
type_and_addr[1] = paddlec_float_buffer_native_ptr(self);
|
838
|
+
res = rb_class_new_instance(2, type_and_addr, c_FFI_Pointer);
|
839
|
+
res = rb_funcall(res, rb_intern("slice"), 2, LONG2NUM(0), ULONG2NUM(fbuf->length*sizeof(float)));
|
840
|
+
|
841
|
+
return res;
|
842
|
+
}
|
843
|
+
|
844
|
+
|
845
|
+
/* @!endgroup
|
846
|
+
*/
|
847
|
+
|
848
|
+
|
849
|
+
/* @return [PaddleC::FloatBuffer]
|
850
|
+
*/
|
851
|
+
static VALUE paddlec_array_to_float_buffer(VALUE self)
|
852
|
+
{
|
853
|
+
return rb_class_new_instance(1, &self, c_FloatBuffer);
|
854
|
+
}
|
855
|
+
|
856
|
+
|
857
|
+
/* @return [self]
|
858
|
+
*/
|
859
|
+
static VALUE paddlec_float_buffer_to_float_buffer(VALUE self)
|
860
|
+
{
|
861
|
+
return self;
|
862
|
+
}
|
863
|
+
|
864
|
+
|
865
|
+
/* @return [PaddleC::ComplexBuffer] a new {PaddleC::ComplexBuffer} whose real part is +slef+ and imaginary part is 0
|
866
|
+
*/
|
867
|
+
static VALUE paddlec_float_buffer_to_complex_buffer(VALUE self)
|
868
|
+
{
|
869
|
+
return rb_class_new_instance(1, &self, c_ComplexBuffer);
|
870
|
+
}
|
871
|
+
|
872
|
+
|
873
|
+
/* If +numeric+ is a +Complex+, returns an array +[PaddleC::ComplexBuffer, self]+.
|
874
|
+
* Otherwise, returns an array +[PaddleC::FloatBuffer, self]+.
|
875
|
+
*
|
876
|
+
* The coercion mechanism is used by Ruby to handle mixed-type numeric operations:
|
877
|
+
* it is intended to find a compatible common type between the two operands of the operator.
|
878
|
+
*
|
879
|
+
* @param numeric [Numeric]
|
880
|
+
* @return [Array<PaddleC::FloatBuffer, PaddleC::ComplexBuffer>]
|
881
|
+
*/
|
882
|
+
static VALUE paddlec_float_buffer_coerce(VALUE self, VALUE numeric)
|
883
|
+
{
|
884
|
+
VALUE other_coerced;
|
885
|
+
VALUE len_val[2];
|
886
|
+
|
887
|
+
len_val[0] = rb_funcallv(self, id_length, 0, NULL);
|
888
|
+
len_val[1] = numeric;
|
889
|
+
if (rb_class_of(numeric) == rb_cComplex)
|
890
|
+
other_coerced = rb_class_new_instance(2, len_val, c_ComplexBuffer);
|
891
|
+
else
|
892
|
+
other_coerced = rb_class_new_instance(2, len_val, c_FloatBuffer);
|
893
|
+
|
894
|
+
return rb_assoc_new(other_coerced, self);
|
895
|
+
}
|
896
|
+
|
897
|
+
|
898
|
+
static pdlc_buffer_t* pdlc_buffer_finite(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
899
|
+
{
|
900
|
+
size_t i;
|
901
|
+
|
902
|
+
if (!ofbuf)
|
903
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
904
|
+
else
|
905
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
906
|
+
|
907
|
+
for (i = 0; i < fbuf->length; i++)
|
908
|
+
ofbuf->data[i] = (isfinite(fbuf->data[i]) ? 1.0f : 0.0f);
|
909
|
+
|
910
|
+
return ofbuf;
|
911
|
+
}
|
912
|
+
|
913
|
+
|
914
|
+
static pdlc_buffer_t* pdlc_buffer_infinite(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
915
|
+
{
|
916
|
+
size_t i;
|
917
|
+
|
918
|
+
if (!ofbuf)
|
919
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
920
|
+
else
|
921
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
922
|
+
|
923
|
+
for (i = 0; i < fbuf->length; i++)
|
924
|
+
ofbuf->data[i] = ((isinf(fbuf->data[i])) ? 1.0f : 0.0f);
|
925
|
+
|
926
|
+
return ofbuf;
|
927
|
+
}
|
928
|
+
|
929
|
+
|
930
|
+
static pdlc_buffer_t* pdlc_buffer_nan(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
931
|
+
{
|
932
|
+
size_t i;
|
933
|
+
|
934
|
+
if (!ofbuf)
|
935
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
936
|
+
else
|
937
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
938
|
+
|
939
|
+
for (i = 0; i < fbuf->length; i++)
|
940
|
+
ofbuf->data[i] = ((isnan(fbuf->data[i])) ? 1.0f : 0.0f);
|
941
|
+
|
942
|
+
return ofbuf;
|
943
|
+
}
|
944
|
+
|
945
|
+
|
946
|
+
static pdlc_buffer_t* pdlc_buffer_integer(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
947
|
+
{
|
948
|
+
size_t i;
|
949
|
+
|
950
|
+
if (!ofbuf)
|
951
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
952
|
+
else
|
953
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
954
|
+
|
955
|
+
for (i = 0; i < fbuf->length; i++)
|
956
|
+
ofbuf->data[i] = ((isfinite(fbuf->data[i]) && (fbuf->data[i] == truncf(fbuf->data[i]))) ? 1.0f : 0.0f);
|
957
|
+
|
958
|
+
return ofbuf;
|
959
|
+
}
|
960
|
+
|
961
|
+
|
962
|
+
static pdlc_buffer_t* pdlc_buffer_negative(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
963
|
+
{
|
964
|
+
size_t i;
|
965
|
+
|
966
|
+
if (!ofbuf)
|
967
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
968
|
+
else
|
969
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
970
|
+
|
971
|
+
for (i = 0; i < fbuf->length; i++)
|
972
|
+
ofbuf->data[i] = ((fbuf->data[i] < 0.0f) ? 1.0f : 0.0f);
|
973
|
+
|
974
|
+
return ofbuf;
|
975
|
+
}
|
976
|
+
|
977
|
+
|
978
|
+
static pdlc_buffer_t* pdlc_buffer_positive(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
979
|
+
{
|
980
|
+
size_t i;
|
981
|
+
|
982
|
+
if (!ofbuf)
|
983
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
984
|
+
else
|
985
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
986
|
+
|
987
|
+
for (i = 0; i < fbuf->length; i++)
|
988
|
+
ofbuf->data[i] = ((fbuf->data[i] > 0.0f) ? 1.0f : 0.0f);
|
989
|
+
|
990
|
+
return ofbuf;
|
991
|
+
}
|
992
|
+
|
993
|
+
|
994
|
+
static pdlc_buffer_t* pdlc_buffer_nonzero(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
995
|
+
{
|
996
|
+
size_t i;
|
997
|
+
|
998
|
+
if (!ofbuf)
|
999
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
1000
|
+
else
|
1001
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
1002
|
+
|
1003
|
+
for (i = 0; i < fbuf->length; i++)
|
1004
|
+
ofbuf->data[i] = ((fbuf->data[i] == 0.0f) ? 0.0f : 1.0f);
|
1005
|
+
|
1006
|
+
return ofbuf;
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
|
1010
|
+
static pdlc_buffer_t* pdlc_buffer_zero(const pdlc_buffer_t *fbuf, pdlc_buffer_t *ofbuf)
|
1011
|
+
{
|
1012
|
+
size_t i;
|
1013
|
+
|
1014
|
+
if (!ofbuf)
|
1015
|
+
ofbuf = pdlc_buffer_new(fbuf->length);
|
1016
|
+
else
|
1017
|
+
pdlc_buffer_resize(ofbuf, fbuf->length, 0);
|
1018
|
+
|
1019
|
+
for (i = 0; i < fbuf->length; i++)
|
1020
|
+
ofbuf->data[i] = ((fbuf->data[i] == 0.0f) ? 1.0f : 0.0f);
|
1021
|
+
|
1022
|
+
return ofbuf;
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
|
1026
|
+
static inline int pdlc_f2b(float x)
|
1027
|
+
{
|
1028
|
+
return ((x == 0.0f || isnan(x)) ? 0 : 1);
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
|
1032
|
+
static pdlc_buffer_t* pdlc_buffer_and(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
|
1033
|
+
{
|
1034
|
+
size_t i;
|
1035
|
+
size_t len = lhs->length;
|
1036
|
+
|
1037
|
+
if (len > rhs->length)
|
1038
|
+
len = rhs->length;
|
1039
|
+
|
1040
|
+
pdlc_buffer_resize(res, len, 0);
|
1041
|
+
|
1042
|
+
for (i = 0; i < len; i++)
|
1043
|
+
res->data[i] = (float)(pdlc_f2b(lhs->data[i]) & pdlc_f2b(rhs->data[i]));
|
1044
|
+
|
1045
|
+
return res;
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
|
1049
|
+
static pdlc_buffer_t* pdlc_buffer_or(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
|
1050
|
+
{
|
1051
|
+
size_t i;
|
1052
|
+
size_t len = lhs->length;
|
1053
|
+
|
1054
|
+
if (len > rhs->length)
|
1055
|
+
len = rhs->length;
|
1056
|
+
|
1057
|
+
pdlc_buffer_resize(res, len, 0);
|
1058
|
+
|
1059
|
+
for (i = 0; i < len; i++)
|
1060
|
+
res->data[i] = (float)(pdlc_f2b(lhs->data[i]) | pdlc_f2b(rhs->data[i]));
|
1061
|
+
|
1062
|
+
return res;
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
|
1066
|
+
static pdlc_buffer_t* pdlc_buffer_xor(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
|
1067
|
+
{
|
1068
|
+
size_t i;
|
1069
|
+
size_t len = lhs->length;
|
1070
|
+
|
1071
|
+
if (len > rhs->length)
|
1072
|
+
len = rhs->length;
|
1073
|
+
|
1074
|
+
pdlc_buffer_resize(res, len, 0);
|
1075
|
+
|
1076
|
+
for (i = 0; i < len; i++)
|
1077
|
+
res->data[i] = (float)(pdlc_f2b(lhs->data[i]) ^ pdlc_f2b(rhs->data[i]));
|
1078
|
+
|
1079
|
+
return res;
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
|
1083
|
+
static pdlc_buffer_t* pdlc_buffer_not(const pdlc_buffer_t *lhs, pdlc_buffer_t *res)
|
1084
|
+
{
|
1085
|
+
size_t i;
|
1086
|
+
const size_t len = lhs->length;
|
1087
|
+
|
1088
|
+
pdlc_buffer_resize(res, len, 0);
|
1089
|
+
|
1090
|
+
for (i = 0; i < len; i++)
|
1091
|
+
res->data[i] = (pdlc_f2b(lhs->data[i]) ? 0.0f : 1.0f );
|
1092
|
+
|
1093
|
+
return res;
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
|
1097
|
+
/* @!group Float
|
1098
|
+
*/
|
1099
|
+
|
1100
|
+
|
1101
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for values which are valid IEEE floating point number, i.e. which are not infinite or NaN, 0.0 otherwize.
|
1102
|
+
* @return [PaddleC::FloatBuffer]
|
1103
|
+
*/
|
1104
|
+
static VALUE paddlec_float_buffer_finite(VALUE self)
|
1105
|
+
{
|
1106
|
+
const pdlc_buffer_t *mfbuf;
|
1107
|
+
pdlc_buffer_t *rfbuf;
|
1108
|
+
VALUE buffer;
|
1109
|
+
|
1110
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1111
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1112
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1113
|
+
pdlc_buffer_finite(mfbuf, rfbuf);
|
1114
|
+
|
1115
|
+
return buffer;
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
|
1119
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for values which are positive or negative infinity, 0.0 otherwize.
|
1120
|
+
* @return [PaddleC::FloatBuffer]
|
1121
|
+
*/
|
1122
|
+
static VALUE paddlec_float_buffer_infinite(VALUE self)
|
1123
|
+
{
|
1124
|
+
const pdlc_buffer_t *mfbuf;
|
1125
|
+
pdlc_buffer_t *rfbuf;
|
1126
|
+
VALUE buffer;
|
1127
|
+
|
1128
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1129
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1130
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1131
|
+
pdlc_buffer_infinite(mfbuf, rfbuf);
|
1132
|
+
|
1133
|
+
return buffer;
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
|
1137
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for values which are NaN, 0.0 otherwize.
|
1138
|
+
* @return [PaddleC::FloatBuffer]
|
1139
|
+
*/
|
1140
|
+
static VALUE paddlec_float_buffer_nan(VALUE self)
|
1141
|
+
{
|
1142
|
+
const pdlc_buffer_t *mfbuf;
|
1143
|
+
pdlc_buffer_t *rfbuf;
|
1144
|
+
VALUE buffer;
|
1145
|
+
|
1146
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1147
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1148
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1149
|
+
pdlc_buffer_nan(mfbuf, rfbuf);
|
1150
|
+
|
1151
|
+
return buffer;
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
|
1155
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 if +value == value.truncate+, 0.0 otherwise.
|
1156
|
+
* @return [PaddleC::FloatBuffer]
|
1157
|
+
*/
|
1158
|
+
static VALUE paddlec_float_buffer_integer(VALUE self)
|
1159
|
+
{
|
1160
|
+
const pdlc_buffer_t *mfbuf;
|
1161
|
+
pdlc_buffer_t *rfbuf;
|
1162
|
+
VALUE buffer;
|
1163
|
+
|
1164
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1165
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1166
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1167
|
+
pdlc_buffer_integer(mfbuf, rfbuf);
|
1168
|
+
|
1169
|
+
return buffer;
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
|
1173
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 if +value < 0+, 0.0 otherwise.
|
1174
|
+
* @return [PaddleC::FloatBuffer]
|
1175
|
+
*/
|
1176
|
+
static VALUE paddlec_float_buffer_negative(VALUE self)
|
1177
|
+
{
|
1178
|
+
const pdlc_buffer_t *mfbuf;
|
1179
|
+
pdlc_buffer_t *rfbuf;
|
1180
|
+
VALUE buffer;
|
1181
|
+
|
1182
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1183
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1184
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1185
|
+
pdlc_buffer_negative(mfbuf, rfbuf);
|
1186
|
+
|
1187
|
+
return buffer;
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
|
1191
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 if +value > 0+, 0.0 otherwise.
|
1192
|
+
* @return [PaddleC::FloatBuffer]
|
1193
|
+
*/
|
1194
|
+
static VALUE paddlec_float_buffer_positive(VALUE self)
|
1195
|
+
{
|
1196
|
+
const pdlc_buffer_t *mfbuf;
|
1197
|
+
pdlc_buffer_t *rfbuf;
|
1198
|
+
VALUE buffer;
|
1199
|
+
|
1200
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1201
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1202
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1203
|
+
pdlc_buffer_positive(mfbuf, rfbuf);
|
1204
|
+
|
1205
|
+
return buffer;
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
|
1209
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 if +value != 0+, 0.0 otherwise.
|
1210
|
+
* @return [PaddleC::FloatBuffer]
|
1211
|
+
*/
|
1212
|
+
static VALUE paddlec_float_buffer_nonzero(VALUE self)
|
1213
|
+
{
|
1214
|
+
const pdlc_buffer_t *mfbuf;
|
1215
|
+
pdlc_buffer_t *rfbuf;
|
1216
|
+
VALUE buffer;
|
1217
|
+
|
1218
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1219
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1220
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1221
|
+
pdlc_buffer_nonzero(mfbuf, rfbuf);
|
1222
|
+
|
1223
|
+
return buffer;
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
|
1227
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 if +value == 0+, 0.0 otherwise.
|
1228
|
+
* @return [PaddleC::FloatBuffer]
|
1229
|
+
*/
|
1230
|
+
static VALUE paddlec_float_buffer_zero(VALUE self)
|
1231
|
+
{
|
1232
|
+
const pdlc_buffer_t *mfbuf;
|
1233
|
+
pdlc_buffer_t *rfbuf;
|
1234
|
+
VALUE buffer;
|
1235
|
+
|
1236
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1237
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1238
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1239
|
+
pdlc_buffer_zero(mfbuf, rfbuf);
|
1240
|
+
|
1241
|
+
return buffer;
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
|
1245
|
+
/* @!endgroup
|
1246
|
+
*/
|
1247
|
+
|
1248
|
+
|
1249
|
+
/* @!group Logic operators
|
1250
|
+
*/
|
1251
|
+
|
1252
|
+
|
1253
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1254
|
+
* @param other [PaddleC::FloatBuffer]
|
1255
|
+
* @return [PaddleC::FloatBuffer]
|
1256
|
+
*/
|
1257
|
+
static VALUE paddlec_float_buffer_and(VALUE self, VALUE other)
|
1258
|
+
{
|
1259
|
+
const pdlc_buffer_t *mfbuf;
|
1260
|
+
const pdlc_buffer_t *ofbuf;
|
1261
|
+
pdlc_buffer_t *rfbuf;
|
1262
|
+
VALUE buffer;
|
1263
|
+
|
1264
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1265
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1266
|
+
|
1267
|
+
if (!rb_obj_is_kind_of(other, c_FloatBuffer))
|
1268
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(other)));
|
1269
|
+
|
1270
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1271
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1272
|
+
|
1273
|
+
pdlc_buffer_and(mfbuf, ofbuf, rfbuf);
|
1274
|
+
|
1275
|
+
return buffer;
|
1276
|
+
}
|
1277
|
+
|
1278
|
+
|
1279
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1280
|
+
* @param other [PaddleC::FloatBuffer]
|
1281
|
+
* @return [PaddleC::FloatBuffer]
|
1282
|
+
*/
|
1283
|
+
static VALUE paddlec_float_buffer_or(VALUE self, VALUE other)
|
1284
|
+
{
|
1285
|
+
const pdlc_buffer_t *mfbuf;
|
1286
|
+
const pdlc_buffer_t *ofbuf;
|
1287
|
+
pdlc_buffer_t *rfbuf;
|
1288
|
+
VALUE buffer;
|
1289
|
+
|
1290
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1291
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1292
|
+
|
1293
|
+
if (!rb_obj_is_kind_of(other, c_FloatBuffer))
|
1294
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(other)));
|
1295
|
+
|
1296
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1297
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1298
|
+
|
1299
|
+
pdlc_buffer_or(mfbuf, ofbuf, rfbuf);
|
1300
|
+
|
1301
|
+
return buffer;
|
1302
|
+
}
|
1303
|
+
|
1304
|
+
|
1305
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1306
|
+
* @param other [PaddleC::FloatBuffer]
|
1307
|
+
* @return [PaddleC::FloatBuffer]
|
1308
|
+
*/
|
1309
|
+
static VALUE paddlec_float_buffer_xor(VALUE self, VALUE other)
|
1310
|
+
{
|
1311
|
+
const pdlc_buffer_t *mfbuf;
|
1312
|
+
const pdlc_buffer_t *ofbuf;
|
1313
|
+
pdlc_buffer_t *rfbuf;
|
1314
|
+
VALUE buffer;
|
1315
|
+
|
1316
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1317
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1318
|
+
|
1319
|
+
if (!rb_obj_is_kind_of(other, c_FloatBuffer))
|
1320
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(other)));
|
1321
|
+
|
1322
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1323
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1324
|
+
|
1325
|
+
pdlc_buffer_xor(mfbuf, ofbuf, rfbuf);
|
1326
|
+
|
1327
|
+
return buffer;
|
1328
|
+
}
|
1329
|
+
|
1330
|
+
|
1331
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1332
|
+
* @return [PaddleC::FloatBuffer]
|
1333
|
+
*/
|
1334
|
+
static VALUE paddlec_float_buffer_not(VALUE self)
|
1335
|
+
{
|
1336
|
+
const pdlc_buffer_t *mfbuf;
|
1337
|
+
pdlc_buffer_t *rfbuf;
|
1338
|
+
VALUE buffer;
|
1339
|
+
|
1340
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1341
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1342
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1343
|
+
pdlc_buffer_not(mfbuf, rfbuf);
|
1344
|
+
|
1345
|
+
return buffer;
|
1346
|
+
}
|
1347
|
+
|
1348
|
+
|
1349
|
+
/* @!endgroup
|
1350
|
+
*/
|
1351
|
+
|
1352
|
+
|
1353
|
+
/* @!group Comparison
|
1354
|
+
*/
|
1355
|
+
|
1356
|
+
|
1357
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1358
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
1359
|
+
* @return [PaddleC::FloatBuffer]
|
1360
|
+
*/
|
1361
|
+
static VALUE paddlec_float_buffer_cmpless(VALUE self, VALUE other)
|
1362
|
+
{
|
1363
|
+
const pdlc_buffer_t *mfbuf;
|
1364
|
+
pdlc_buffer_t *rfbuf;
|
1365
|
+
const pdlc_buffer_t *ofbuf;
|
1366
|
+
float of;
|
1367
|
+
VALUE buffer;
|
1368
|
+
|
1369
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1370
|
+
|
1371
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1372
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1373
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1374
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
1375
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1376
|
+
pdlc_fb_fb_cmpless(mfbuf, ofbuf, rfbuf);
|
1377
|
+
}
|
1378
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1379
|
+
of = (float)NUM2DBL(other);
|
1380
|
+
pdlc_fb_fs_cmpless(mfbuf, of, rfbuf);
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
else
|
1384
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
1385
|
+
|
1386
|
+
return buffer;
|
1387
|
+
}
|
1388
|
+
|
1389
|
+
|
1390
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1391
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
1392
|
+
* @return [PaddleC::FloatBuffer]
|
1393
|
+
*/
|
1394
|
+
static VALUE paddlec_float_buffer_cmplessequ(VALUE self, VALUE other)
|
1395
|
+
{
|
1396
|
+
const pdlc_buffer_t *mfbuf;
|
1397
|
+
pdlc_buffer_t *rfbuf;
|
1398
|
+
const pdlc_buffer_t *ofbuf;
|
1399
|
+
float of;
|
1400
|
+
VALUE buffer;
|
1401
|
+
|
1402
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1403
|
+
|
1404
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1405
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1406
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1407
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
1408
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1409
|
+
pdlc_fb_fb_cmplessequ(mfbuf, ofbuf, rfbuf);
|
1410
|
+
}
|
1411
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1412
|
+
of = (float)NUM2DBL(other);
|
1413
|
+
pdlc_fb_fs_cmplessequ(mfbuf, of, rfbuf);
|
1414
|
+
}
|
1415
|
+
}
|
1416
|
+
else
|
1417
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
1418
|
+
|
1419
|
+
return buffer;
|
1420
|
+
}
|
1421
|
+
|
1422
|
+
|
1423
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1424
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
1425
|
+
* @return [PaddleC::FloatBuffer]
|
1426
|
+
*/
|
1427
|
+
static VALUE paddlec_float_buffer_cmpgrt(VALUE self, VALUE other)
|
1428
|
+
{
|
1429
|
+
const pdlc_buffer_t *mfbuf;
|
1430
|
+
pdlc_buffer_t *rfbuf;
|
1431
|
+
const pdlc_buffer_t *ofbuf;
|
1432
|
+
float of;
|
1433
|
+
VALUE buffer;
|
1434
|
+
|
1435
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1436
|
+
|
1437
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1438
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1439
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1440
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
1441
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1442
|
+
pdlc_fb_fb_cmpgrt(mfbuf, ofbuf, rfbuf);
|
1443
|
+
}
|
1444
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1445
|
+
of = (float)NUM2DBL(other);
|
1446
|
+
pdlc_fb_fs_cmpgrt(mfbuf, of, rfbuf);
|
1447
|
+
}
|
1448
|
+
}
|
1449
|
+
else
|
1450
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
1451
|
+
|
1452
|
+
return buffer;
|
1453
|
+
}
|
1454
|
+
|
1455
|
+
|
1456
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1457
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
1458
|
+
* @return [PaddleC::FloatBuffer]
|
1459
|
+
*/
|
1460
|
+
static VALUE paddlec_float_buffer_cmpgrtequ(VALUE self, VALUE other)
|
1461
|
+
{
|
1462
|
+
const pdlc_buffer_t *mfbuf;
|
1463
|
+
pdlc_buffer_t *rfbuf;
|
1464
|
+
const pdlc_buffer_t *ofbuf;
|
1465
|
+
float of;
|
1466
|
+
VALUE buffer;
|
1467
|
+
|
1468
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1469
|
+
|
1470
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1471
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1472
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1473
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
1474
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1475
|
+
pdlc_fb_fb_cmpgrtequ(mfbuf, ofbuf, rfbuf);
|
1476
|
+
}
|
1477
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1478
|
+
of = (float)NUM2DBL(other);
|
1479
|
+
pdlc_fb_fs_cmpgrtequ(mfbuf, of, rfbuf);
|
1480
|
+
}
|
1481
|
+
}
|
1482
|
+
else
|
1483
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
1484
|
+
|
1485
|
+
return buffer;
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
|
1489
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1490
|
+
* @param other [PaddleC::ComplexBuffer, Complex, PaddleC::FloatBuffer, Numeric]
|
1491
|
+
* @return [PaddleC::FloatBuffer]
|
1492
|
+
*/
|
1493
|
+
static VALUE paddlec_float_buffer_equ(VALUE self, VALUE other)
|
1494
|
+
{
|
1495
|
+
const pdlc_buffer_t *mfbuf;
|
1496
|
+
pdlc_buffer_t *rfbuf;
|
1497
|
+
const pdlc_buffer_t *ofbuf;
|
1498
|
+
float of;
|
1499
|
+
const pdlc_complex_buffer_t *ocbuf;
|
1500
|
+
pdlc_complex_t oc;
|
1501
|
+
VALUE buffer;
|
1502
|
+
|
1503
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1504
|
+
|
1505
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex) || rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1506
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1507
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1508
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
1509
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
1510
|
+
pdlc_fb_cb_equ(mfbuf, ocbuf, rfbuf);
|
1511
|
+
}
|
1512
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
1513
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
1514
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
1515
|
+
pdlc_fb_cs_equ(mfbuf, oc, rfbuf);
|
1516
|
+
}
|
1517
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
1518
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1519
|
+
pdlc_fb_fb_equ(mfbuf, ofbuf, rfbuf);
|
1520
|
+
}
|
1521
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1522
|
+
of = (float)NUM2DBL(other);
|
1523
|
+
pdlc_fb_fs_equ(mfbuf, of, rfbuf);
|
1524
|
+
}
|
1525
|
+
}
|
1526
|
+
else
|
1527
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
1528
|
+
|
1529
|
+
return buffer;
|
1530
|
+
}
|
1531
|
+
|
1532
|
+
|
1533
|
+
/* Returns a {PaddleC::FloatBuffer}. 1.0 for true, 0.0 for false.
|
1534
|
+
* @param other [PaddleC::ComplexBuffer, Complex, PaddleC::FloatBuffer, Numeric]
|
1535
|
+
* @return [PaddleC::FloatBuffer]
|
1536
|
+
*/
|
1537
|
+
static VALUE paddlec_float_buffer_different(VALUE self, VALUE other)
|
1538
|
+
{
|
1539
|
+
const pdlc_buffer_t *mfbuf;
|
1540
|
+
pdlc_buffer_t *rfbuf;
|
1541
|
+
const pdlc_buffer_t *ofbuf;
|
1542
|
+
float of;
|
1543
|
+
const pdlc_complex_buffer_t *ocbuf;
|
1544
|
+
pdlc_complex_t oc;
|
1545
|
+
VALUE buffer;
|
1546
|
+
|
1547
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1548
|
+
|
1549
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex) || rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1550
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1551
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1552
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
1553
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
1554
|
+
pdlc_fb_cb_different(mfbuf, ocbuf, rfbuf);
|
1555
|
+
}
|
1556
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
1557
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
1558
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
1559
|
+
pdlc_fb_cs_different(mfbuf, oc, rfbuf);
|
1560
|
+
}
|
1561
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
1562
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
1563
|
+
pdlc_fb_fb_different(mfbuf, ofbuf, rfbuf);
|
1564
|
+
}
|
1565
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
1566
|
+
of = (float)NUM2DBL(other);
|
1567
|
+
pdlc_fb_fs_different(mfbuf, of, rfbuf);
|
1568
|
+
}
|
1569
|
+
}
|
1570
|
+
else
|
1571
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
1572
|
+
|
1573
|
+
return buffer;
|
1574
|
+
}
|
1575
|
+
|
1576
|
+
|
1577
|
+
/* @!endgroup
|
1578
|
+
*/
|
1579
|
+
|
1580
|
+
|
1581
|
+
/* @!group Rounding
|
1582
|
+
*/
|
1583
|
+
|
1584
|
+
|
1585
|
+
/* Returns the smallest numbers greater than or equal to values of +self+, with a precision of +ndigits+ decimal digits (default: 0).
|
1586
|
+
* @overload ceil(ndigits = 0, buffer = nil)
|
1587
|
+
* @param ndigits [Integer] precision
|
1588
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1589
|
+
* @return [PaddleC::FloatBuffer]
|
1590
|
+
*/
|
1591
|
+
static VALUE paddlec_float_buffer_ceil(int argc, VALUE *argv, VALUE self)
|
1592
|
+
{
|
1593
|
+
const pdlc_buffer_t *mfbuf;
|
1594
|
+
pdlc_buffer_t *rfbuf;
|
1595
|
+
VALUE digits, buffer, tmp;
|
1596
|
+
int d;
|
1597
|
+
|
1598
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1599
|
+
|
1600
|
+
rb_scan_args(argc, argv, "02", &digits, &buffer);
|
1601
|
+
if (NIL_P(buffer) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1602
|
+
buffer = digits;
|
1603
|
+
digits = Qnil;
|
1604
|
+
}
|
1605
|
+
else if (rb_obj_is_kind_of(buffer, rb_cNumeric) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1606
|
+
tmp = buffer;
|
1607
|
+
buffer = digits;
|
1608
|
+
digits = tmp;
|
1609
|
+
}
|
1610
|
+
|
1611
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1612
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1613
|
+
buffer = Qnil;
|
1614
|
+
}
|
1615
|
+
if (buffer == Qnil)
|
1616
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1617
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1618
|
+
|
1619
|
+
if (digits == Qnil)
|
1620
|
+
pdlc_buffer_ceil(mfbuf, rfbuf);
|
1621
|
+
else {
|
1622
|
+
d = NUM2INT(digits);
|
1623
|
+
pdlc_buffer_ceil_digits(mfbuf, d, rfbuf);
|
1624
|
+
}
|
1625
|
+
|
1626
|
+
return buffer;
|
1627
|
+
}
|
1628
|
+
|
1629
|
+
|
1630
|
+
/* Returns the smallest integral values that are not less than values of +self+, with a precision of +ndigits+ decimal digits (default: 0).
|
1631
|
+
* @overload ceil!(ndigits = 0)
|
1632
|
+
* @param ndigits [Integer] precision
|
1633
|
+
* @return [self]
|
1634
|
+
*/
|
1635
|
+
static VALUE paddlec_float_buffer_ceil_inplace(int argc, VALUE *argv, VALUE self)
|
1636
|
+
{
|
1637
|
+
pdlc_buffer_t *mfbuf;
|
1638
|
+
VALUE digits;
|
1639
|
+
int d;
|
1640
|
+
|
1641
|
+
rb_scan_args(argc, argv, "01", &digits);
|
1642
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1643
|
+
|
1644
|
+
if (digits == Qnil)
|
1645
|
+
pdlc_buffer_ceil_inplace(mfbuf);
|
1646
|
+
else {
|
1647
|
+
d = NUM2INT(digits);
|
1648
|
+
pdlc_buffer_ceil_digits_inplace(mfbuf, d);
|
1649
|
+
}
|
1650
|
+
|
1651
|
+
return self;
|
1652
|
+
}
|
1653
|
+
|
1654
|
+
|
1655
|
+
/* Returns the largest integral values that are not greater than values of +self+, with a precision of +ndigits+ decimal digits (default: 0).
|
1656
|
+
* @overload floor(ndigits = 0, buffer = nil)
|
1657
|
+
* @param ndigits [Integer] precision
|
1658
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1659
|
+
* @return [PaddleC::FloatBuffer]
|
1660
|
+
*/
|
1661
|
+
static VALUE paddlec_float_buffer_floor(int argc, VALUE *argv, VALUE self)
|
1662
|
+
{
|
1663
|
+
const pdlc_buffer_t *mfbuf;
|
1664
|
+
pdlc_buffer_t *rfbuf;
|
1665
|
+
VALUE digits, buffer, tmp;
|
1666
|
+
int d;
|
1667
|
+
|
1668
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1669
|
+
|
1670
|
+
rb_scan_args(argc, argv, "02", &digits, &buffer);
|
1671
|
+
if (NIL_P(buffer) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1672
|
+
buffer = digits;
|
1673
|
+
digits = Qnil;
|
1674
|
+
}
|
1675
|
+
else if (rb_obj_is_kind_of(buffer, rb_cNumeric) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1676
|
+
tmp = buffer;
|
1677
|
+
buffer = digits;
|
1678
|
+
digits = tmp;
|
1679
|
+
}
|
1680
|
+
|
1681
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1682
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1683
|
+
buffer = Qnil;
|
1684
|
+
}
|
1685
|
+
if (buffer == Qnil)
|
1686
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1687
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1688
|
+
|
1689
|
+
if (digits == Qnil)
|
1690
|
+
pdlc_buffer_floor(mfbuf, rfbuf);
|
1691
|
+
else {
|
1692
|
+
d = NUM2INT(digits);
|
1693
|
+
pdlc_buffer_floor_digits(mfbuf, d, rfbuf);
|
1694
|
+
}
|
1695
|
+
|
1696
|
+
return buffer;
|
1697
|
+
}
|
1698
|
+
|
1699
|
+
|
1700
|
+
/* Returns the largest integral values that are not greater than values of +self+, with a precision of +ndigits+ decimal digits (default: 0).
|
1701
|
+
* @overload floor!(ndigits = 0)
|
1702
|
+
* @param ndigits [Integer] precision
|
1703
|
+
* @return [self]
|
1704
|
+
*/
|
1705
|
+
static VALUE paddlec_float_buffer_floor_inplace(int argc, VALUE *argv, VALUE self)
|
1706
|
+
{
|
1707
|
+
pdlc_buffer_t *mfbuf;
|
1708
|
+
VALUE digits;
|
1709
|
+
int d;
|
1710
|
+
|
1711
|
+
rb_scan_args(argc, argv, "01", &digits);
|
1712
|
+
|
1713
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1714
|
+
|
1715
|
+
if (digits == Qnil)
|
1716
|
+
pdlc_buffer_floor_inplace(mfbuf);
|
1717
|
+
else {
|
1718
|
+
d = NUM2INT(digits);
|
1719
|
+
pdlc_buffer_floor_digits_inplace(mfbuf, d);
|
1720
|
+
}
|
1721
|
+
|
1722
|
+
return self;
|
1723
|
+
}
|
1724
|
+
|
1725
|
+
|
1726
|
+
/* Truncates values of +self+ to the nearest integers not larger in absolute value, with a precision of +ndigits+ decimal digits (default: 0).
|
1727
|
+
* @overload truncate(ndigits = 0, buffer = nil)
|
1728
|
+
* @param ndigits [Integer] precision
|
1729
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1730
|
+
* @return [PaddleC::FloatBuffer]
|
1731
|
+
*/
|
1732
|
+
static VALUE paddlec_float_buffer_truncate(int argc, VALUE *argv, VALUE self)
|
1733
|
+
{
|
1734
|
+
const pdlc_buffer_t *mfbuf;
|
1735
|
+
pdlc_buffer_t *rfbuf;
|
1736
|
+
VALUE digits, buffer, tmp;
|
1737
|
+
int d;
|
1738
|
+
|
1739
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1740
|
+
|
1741
|
+
rb_scan_args(argc, argv, "02", &digits, &buffer);
|
1742
|
+
if (NIL_P(buffer) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1743
|
+
buffer = digits;
|
1744
|
+
digits = Qnil;
|
1745
|
+
}
|
1746
|
+
else if (rb_obj_is_kind_of(buffer, rb_cNumeric) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1747
|
+
tmp = buffer;
|
1748
|
+
buffer = digits;
|
1749
|
+
digits = tmp;
|
1750
|
+
}
|
1751
|
+
|
1752
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1753
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1754
|
+
buffer = Qnil;
|
1755
|
+
}
|
1756
|
+
if (buffer == Qnil)
|
1757
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1758
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1759
|
+
|
1760
|
+
if (digits == Qnil)
|
1761
|
+
pdlc_buffer_truncate(mfbuf, rfbuf);
|
1762
|
+
else {
|
1763
|
+
d = NUM2INT(digits);
|
1764
|
+
pdlc_buffer_truncate_digits(mfbuf, d, rfbuf);
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
return buffer;
|
1768
|
+
}
|
1769
|
+
|
1770
|
+
|
1771
|
+
/* Truncates values of +self+ to the nearest integers not larger in absolute value, with a precision of +ndigits+ decimal digits (default: 0).
|
1772
|
+
* @overload truncate!(ndigits = 0)
|
1773
|
+
* @param ndigits [Integer] precision
|
1774
|
+
* @return [self]
|
1775
|
+
*/
|
1776
|
+
static VALUE paddlec_float_buffer_truncate_inplace(int argc, VALUE *argv, VALUE self)
|
1777
|
+
{
|
1778
|
+
pdlc_buffer_t *mfbuf;
|
1779
|
+
VALUE digits;
|
1780
|
+
int d;
|
1781
|
+
|
1782
|
+
rb_scan_args(argc, argv, "01", &digits);
|
1783
|
+
|
1784
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1785
|
+
|
1786
|
+
if (digits == Qnil)
|
1787
|
+
pdlc_buffer_truncate_inplace(mfbuf);
|
1788
|
+
else {
|
1789
|
+
d = NUM2INT(digits);
|
1790
|
+
pdlc_buffer_truncate_digits_inplace(mfbuf, d);
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
return self;
|
1794
|
+
}
|
1795
|
+
|
1796
|
+
|
1797
|
+
/* Rounds values of +self+ to the nearest integers, but round halfway cases away from zero, with a precision of +ndigits+ decimal digits (default: 0).
|
1798
|
+
* @overload round(ndigits = 0, buffer = nil)
|
1799
|
+
* @param ndigits [Integer] precision
|
1800
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1801
|
+
* @return [PaddleC::FloatBuffer]
|
1802
|
+
*/
|
1803
|
+
static VALUE paddlec_float_buffer_round(int argc, VALUE *argv, VALUE self)
|
1804
|
+
{
|
1805
|
+
const pdlc_buffer_t *mfbuf;
|
1806
|
+
pdlc_buffer_t *rfbuf;
|
1807
|
+
VALUE digits, buffer, tmp;
|
1808
|
+
int d;
|
1809
|
+
|
1810
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1811
|
+
|
1812
|
+
rb_scan_args(argc, argv, "02", &digits, &buffer);
|
1813
|
+
if (NIL_P(buffer) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1814
|
+
buffer = digits;
|
1815
|
+
digits = Qnil;
|
1816
|
+
}
|
1817
|
+
else if (rb_obj_is_kind_of(buffer, rb_cNumeric) && rb_obj_is_kind_of(digits, c_FloatBuffer)) {
|
1818
|
+
tmp = buffer;
|
1819
|
+
buffer = digits;
|
1820
|
+
digits = tmp;
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1824
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1825
|
+
buffer = Qnil;
|
1826
|
+
}
|
1827
|
+
if (buffer == Qnil)
|
1828
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1829
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1830
|
+
|
1831
|
+
if (digits == Qnil)
|
1832
|
+
pdlc_buffer_round(mfbuf, rfbuf);
|
1833
|
+
else {
|
1834
|
+
d = NUM2INT(digits);
|
1835
|
+
pdlc_buffer_round_digits(mfbuf, d, rfbuf);
|
1836
|
+
}
|
1837
|
+
|
1838
|
+
return buffer;
|
1839
|
+
}
|
1840
|
+
|
1841
|
+
|
1842
|
+
/* Rounds values of +self+ to the nearest integers, but round halfway cases away from zero, with a precision of +ndigits+ decimal digits (default: 0).
|
1843
|
+
* @overload round!(ndigits = 0)
|
1844
|
+
* @param ndigits [Integer] precision
|
1845
|
+
* @return [self]
|
1846
|
+
*/
|
1847
|
+
static VALUE paddlec_float_buffer_round_inplace(int argc, VALUE *argv, VALUE self)
|
1848
|
+
{
|
1849
|
+
pdlc_buffer_t *mfbuf;
|
1850
|
+
VALUE digits;
|
1851
|
+
int d;
|
1852
|
+
|
1853
|
+
rb_scan_args(argc, argv, "01", &digits);
|
1854
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1855
|
+
|
1856
|
+
if (digits == Qnil)
|
1857
|
+
pdlc_buffer_round_inplace(mfbuf);
|
1858
|
+
else {
|
1859
|
+
d = NUM2INT(digits);
|
1860
|
+
pdlc_buffer_round_digits_inplace(mfbuf, d);
|
1861
|
+
}
|
1862
|
+
|
1863
|
+
return self;
|
1864
|
+
}
|
1865
|
+
|
1866
|
+
|
1867
|
+
/* @!endgroup
|
1868
|
+
*/
|
1869
|
+
|
1870
|
+
|
1871
|
+
/* @!group Complex
|
1872
|
+
*/
|
1873
|
+
|
1874
|
+
|
1875
|
+
/* Returns the absolute value / the absolute part of its polar form.
|
1876
|
+
* @overload abs(buffer = nil)
|
1877
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1878
|
+
* @return [PaddleC::FloatBuffer]
|
1879
|
+
*/
|
1880
|
+
static VALUE paddlec_float_buffer_abs(int argc, VALUE *argv, VALUE self)
|
1881
|
+
{
|
1882
|
+
const pdlc_buffer_t *mfbuf;
|
1883
|
+
pdlc_buffer_t *rfbuf;
|
1884
|
+
VALUE buffer;
|
1885
|
+
|
1886
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1887
|
+
|
1888
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
1889
|
+
|
1890
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1891
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1892
|
+
buffer = Qnil;
|
1893
|
+
}
|
1894
|
+
if (buffer == Qnil)
|
1895
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1896
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1897
|
+
|
1898
|
+
pdlc_buffer_abs(mfbuf, rfbuf);
|
1899
|
+
|
1900
|
+
return buffer;
|
1901
|
+
}
|
1902
|
+
|
1903
|
+
|
1904
|
+
/* Returns the absolute value / the absolute part of its polar form.
|
1905
|
+
* @return [self]
|
1906
|
+
*/
|
1907
|
+
static VALUE paddlec_float_buffer_abs_inplace(VALUE self)
|
1908
|
+
{
|
1909
|
+
pdlc_buffer_t *mfbuf;
|
1910
|
+
|
1911
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1912
|
+
|
1913
|
+
pdlc_buffer_abs_inplace(mfbuf);
|
1914
|
+
|
1915
|
+
return self;
|
1916
|
+
}
|
1917
|
+
|
1918
|
+
|
1919
|
+
/* Returns the square of the absolute value / the square of the absolute part of its polar form.
|
1920
|
+
* @overload abs2(buffer = nil)
|
1921
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1922
|
+
* @return [PaddleC::FloatBuffer]
|
1923
|
+
*/
|
1924
|
+
static VALUE paddlec_float_buffer_abs2(int argc, VALUE *argv, VALUE self)
|
1925
|
+
{
|
1926
|
+
const pdlc_buffer_t *mfbuf;
|
1927
|
+
pdlc_buffer_t *rfbuf;
|
1928
|
+
VALUE buffer;
|
1929
|
+
|
1930
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1931
|
+
|
1932
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
1933
|
+
|
1934
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1935
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1936
|
+
buffer = Qnil;
|
1937
|
+
}
|
1938
|
+
if (buffer == Qnil)
|
1939
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1940
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1941
|
+
|
1942
|
+
pdlc_buffer_abs2(mfbuf, rfbuf);
|
1943
|
+
|
1944
|
+
return buffer;
|
1945
|
+
}
|
1946
|
+
|
1947
|
+
|
1948
|
+
/* Returns the square of the absolute value / the square of the absolute part of its polar form.
|
1949
|
+
* @return [self]
|
1950
|
+
*/
|
1951
|
+
static VALUE paddlec_float_buffer_abs2_inplace(VALUE self)
|
1952
|
+
{
|
1953
|
+
pdlc_buffer_t *mfbuf;
|
1954
|
+
|
1955
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1956
|
+
|
1957
|
+
pdlc_buffer_abs2_inplace(mfbuf);
|
1958
|
+
|
1959
|
+
return self;
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
|
1963
|
+
/* Returns the angle part of its polar form.
|
1964
|
+
* @overload arg(buffer = nil)
|
1965
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1966
|
+
* @return [PaddleC::FloatBuffer]
|
1967
|
+
*/
|
1968
|
+
static VALUE paddlec_float_buffer_arg(int argc, VALUE *argv, VALUE self)
|
1969
|
+
{
|
1970
|
+
const pdlc_buffer_t *mfbuf;
|
1971
|
+
pdlc_buffer_t *rfbuf;
|
1972
|
+
VALUE buffer;
|
1973
|
+
|
1974
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
1975
|
+
|
1976
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
1977
|
+
|
1978
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
1979
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
1980
|
+
buffer = Qnil;
|
1981
|
+
}
|
1982
|
+
if (buffer == Qnil)
|
1983
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
1984
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
1985
|
+
|
1986
|
+
pdlc_buffer_arg(mfbuf, rfbuf);
|
1987
|
+
|
1988
|
+
return buffer;
|
1989
|
+
}
|
1990
|
+
|
1991
|
+
|
1992
|
+
/* Returns the complex conjugate.
|
1993
|
+
* @overload conjugate(buffer = nil)
|
1994
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
1995
|
+
* @return [PaddleC::FloatBuffer]
|
1996
|
+
*/
|
1997
|
+
static VALUE paddlec_float_buffer_conjugate(int argc, VALUE *argv, VALUE self)
|
1998
|
+
{
|
1999
|
+
const pdlc_buffer_t *mfbuf;
|
2000
|
+
pdlc_buffer_t *rfbuf;
|
2001
|
+
VALUE buffer;
|
2002
|
+
|
2003
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2004
|
+
|
2005
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
2006
|
+
|
2007
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2008
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2009
|
+
buffer = Qnil;
|
2010
|
+
}
|
2011
|
+
if (buffer == Qnil)
|
2012
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2013
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2014
|
+
|
2015
|
+
pdlc_buffer_conjugate(mfbuf, rfbuf);
|
2016
|
+
|
2017
|
+
return buffer;
|
2018
|
+
}
|
2019
|
+
|
2020
|
+
|
2021
|
+
/* Returns the complex conjugate.
|
2022
|
+
* @return [self]
|
2023
|
+
*/
|
2024
|
+
static VALUE paddlec_float_buffer_conjugate_inplace(VALUE self)
|
2025
|
+
{
|
2026
|
+
pdlc_buffer_t *mfbuf;
|
2027
|
+
|
2028
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2029
|
+
|
2030
|
+
pdlc_buffer_conjugate_inplace(mfbuf);
|
2031
|
+
|
2032
|
+
return self;
|
2033
|
+
}
|
2034
|
+
|
2035
|
+
|
2036
|
+
/* Returns the imaginary part.
|
2037
|
+
* @overload imaginary(buffer = nil)
|
2038
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
2039
|
+
* @return [PaddleC::FloatBuffer]
|
2040
|
+
*/
|
2041
|
+
static VALUE paddlec_float_buffer_imag(int argc, VALUE *argv, VALUE self)
|
2042
|
+
{
|
2043
|
+
const pdlc_buffer_t *mfbuf;
|
2044
|
+
pdlc_buffer_t *rfbuf;
|
2045
|
+
VALUE buffer;
|
2046
|
+
|
2047
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2048
|
+
|
2049
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
2050
|
+
|
2051
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2052
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2053
|
+
buffer = Qnil;
|
2054
|
+
}
|
2055
|
+
if (buffer == Qnil)
|
2056
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2057
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2058
|
+
|
2059
|
+
pdlc_buffer_imag(mfbuf, rfbuf);
|
2060
|
+
|
2061
|
+
return buffer;
|
2062
|
+
}
|
2063
|
+
|
2064
|
+
|
2065
|
+
/* Returns the real part.
|
2066
|
+
* @overload real(buffer = nil)
|
2067
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
2068
|
+
* @return [PaddleC::FloatBuffer]
|
2069
|
+
*/
|
2070
|
+
static VALUE paddlec_float_buffer_real(int argc, VALUE *argv, VALUE self)
|
2071
|
+
{
|
2072
|
+
const pdlc_buffer_t *mfbuf;
|
2073
|
+
pdlc_buffer_t *rfbuf;
|
2074
|
+
VALUE buffer;
|
2075
|
+
|
2076
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2077
|
+
|
2078
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
2079
|
+
|
2080
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2081
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2082
|
+
buffer = Qnil;
|
2083
|
+
}
|
2084
|
+
if (buffer == Qnil)
|
2085
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2086
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2087
|
+
|
2088
|
+
pdlc_buffer_real(mfbuf, rfbuf);
|
2089
|
+
|
2090
|
+
return buffer;
|
2091
|
+
}
|
2092
|
+
|
2093
|
+
|
2094
|
+
/* Swap the real and imaginary parts.
|
2095
|
+
* @overload swapIQ(buffer = nil)
|
2096
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if provided, the result is written into +buffer+.
|
2097
|
+
* @return [PaddleC::ComplexBuffer]
|
2098
|
+
*/
|
2099
|
+
static VALUE paddlec_float_buffer_swapIQ(int argc, VALUE *argv, VALUE self)
|
2100
|
+
{
|
2101
|
+
const pdlc_buffer_t *mfbuf;
|
2102
|
+
pdlc_complex_buffer_t *rcbuf;
|
2103
|
+
VALUE buffer;
|
2104
|
+
|
2105
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2106
|
+
|
2107
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
2108
|
+
|
2109
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2110
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2111
|
+
buffer = Qnil;
|
2112
|
+
}
|
2113
|
+
if (buffer == Qnil)
|
2114
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2115
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2116
|
+
|
2117
|
+
pdlc_buffer_swapIQ(mfbuf, rcbuf);
|
2118
|
+
|
2119
|
+
return buffer;
|
2120
|
+
}
|
2121
|
+
|
2122
|
+
|
2123
|
+
/* @!endgroup
|
2124
|
+
*/
|
2125
|
+
|
2126
|
+
|
2127
|
+
/* @!group Arithmetic
|
2128
|
+
*/
|
2129
|
+
|
2130
|
+
|
2131
|
+
/* Unary plus, returns the receiver.
|
2132
|
+
* @return [self]
|
2133
|
+
*/
|
2134
|
+
static VALUE paddlec_float_buffer_unaryplus(VALUE self)
|
2135
|
+
{
|
2136
|
+
return self;
|
2137
|
+
}
|
2138
|
+
|
2139
|
+
|
2140
|
+
/* Unary minus, returns the receiver, negated.
|
2141
|
+
* @overload -@(buffer = nil)
|
2142
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
2143
|
+
* @return [PaddleC::FloatBuffer]
|
2144
|
+
*/
|
2145
|
+
static VALUE paddlec_float_buffer_unaryminus(int argc, VALUE *argv, VALUE self)
|
2146
|
+
{
|
2147
|
+
const pdlc_buffer_t *mfbuf;
|
2148
|
+
pdlc_buffer_t *rfbuf;
|
2149
|
+
VALUE buffer;
|
2150
|
+
|
2151
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2152
|
+
|
2153
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
2154
|
+
|
2155
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2156
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2157
|
+
buffer = Qnil;
|
2158
|
+
}
|
2159
|
+
if (buffer == Qnil)
|
2160
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2161
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2162
|
+
|
2163
|
+
pdlc_buffer_unaryminus(mfbuf, rfbuf);
|
2164
|
+
|
2165
|
+
return buffer;
|
2166
|
+
}
|
2167
|
+
|
2168
|
+
|
2169
|
+
/* Unary minus, returns the receiver, negated.
|
2170
|
+
* @return [self]
|
2171
|
+
*/
|
2172
|
+
static VALUE paddlec_float_buffer_unaryminus_inplace(VALUE self)
|
2173
|
+
{
|
2174
|
+
pdlc_buffer_t *mfbuf;
|
2175
|
+
|
2176
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2177
|
+
|
2178
|
+
pdlc_buffer_unaryminus_inplace(mfbuf);
|
2179
|
+
|
2180
|
+
return self;
|
2181
|
+
}
|
2182
|
+
|
2183
|
+
|
2184
|
+
/* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2185
|
+
* @overload -(other, buffer = nil)
|
2186
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2187
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2188
|
+
* @return [PaddleC::FloatBuffer]
|
2189
|
+
* @overload -(other, buffer = nil)
|
2190
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2191
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2192
|
+
* @return [PaddleC::ComplexBuffer]
|
2193
|
+
*/
|
2194
|
+
static VALUE paddlec_float_buffer_sub(int argc, VALUE *argv, VALUE self)
|
2195
|
+
{
|
2196
|
+
const pdlc_buffer_t *mfbuf;
|
2197
|
+
pdlc_buffer_t *rfbuf;
|
2198
|
+
pdlc_complex_buffer_t *rcbuf;
|
2199
|
+
const pdlc_buffer_t *ofbuf;
|
2200
|
+
float of;
|
2201
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2202
|
+
pdlc_complex_t oc;
|
2203
|
+
VALUE other, buffer;
|
2204
|
+
|
2205
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2206
|
+
|
2207
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2208
|
+
|
2209
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2210
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2211
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2212
|
+
buffer = Qnil;
|
2213
|
+
}
|
2214
|
+
if (buffer == Qnil)
|
2215
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2216
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2217
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2218
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2219
|
+
pdlc_fb_cb_sub(mfbuf, ocbuf, rcbuf);
|
2220
|
+
}
|
2221
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2222
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2223
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2224
|
+
pdlc_fb_cs_sub(mfbuf, oc, rcbuf);
|
2225
|
+
}
|
2226
|
+
}
|
2227
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2228
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2229
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2230
|
+
buffer = Qnil;
|
2231
|
+
}
|
2232
|
+
if (buffer == Qnil)
|
2233
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2234
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2235
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2236
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2237
|
+
pdlc_fb_fb_sub(mfbuf, ofbuf, rfbuf);
|
2238
|
+
}
|
2239
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2240
|
+
of = (float)NUM2DBL(other);
|
2241
|
+
pdlc_fb_fs_sub(mfbuf, of, rfbuf);
|
2242
|
+
}
|
2243
|
+
}
|
2244
|
+
else
|
2245
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2246
|
+
|
2247
|
+
return buffer;
|
2248
|
+
}
|
2249
|
+
|
2250
|
+
|
2251
|
+
/* @param other [c_FloatBuffer, rb_cNumeric]
|
2252
|
+
* @return [self]
|
2253
|
+
*/
|
2254
|
+
static VALUE paddlec_float_buffer_sub_inplace(VALUE self, VALUE other)
|
2255
|
+
{
|
2256
|
+
pdlc_buffer_t *mfbuf;
|
2257
|
+
const pdlc_buffer_t *ofbuf;
|
2258
|
+
float of;
|
2259
|
+
|
2260
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2261
|
+
|
2262
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2263
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2264
|
+
pdlc_fb_fb_sub_inplace(mfbuf, ofbuf);
|
2265
|
+
}
|
2266
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2267
|
+
of = (float)NUM2DBL(other);
|
2268
|
+
pdlc_fb_fs_sub_inplace(mfbuf, of);
|
2269
|
+
}
|
2270
|
+
else
|
2271
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2272
|
+
|
2273
|
+
return self;
|
2274
|
+
}
|
2275
|
+
|
2276
|
+
|
2277
|
+
/* Element by element soustraction.
|
2278
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2279
|
+
* @overload esub(other, buffer = nil)
|
2280
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2281
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2282
|
+
* @return [PaddleC::FloatBuffer]
|
2283
|
+
* @overload esub(other, buffer = nil)
|
2284
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2285
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2286
|
+
* @return [PaddleC::ComplexBuffer]
|
2287
|
+
*/
|
2288
|
+
static VALUE paddlec_float_buffer_esub(int argc, VALUE *argv, VALUE self)
|
2289
|
+
{
|
2290
|
+
const pdlc_buffer_t *mfbuf;
|
2291
|
+
pdlc_buffer_t *rfbuf;
|
2292
|
+
pdlc_complex_buffer_t *rcbuf;
|
2293
|
+
const pdlc_buffer_t *ofbuf;
|
2294
|
+
float of;
|
2295
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2296
|
+
pdlc_complex_t oc;
|
2297
|
+
VALUE other, buffer;
|
2298
|
+
|
2299
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2300
|
+
|
2301
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2302
|
+
|
2303
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2304
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2305
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2306
|
+
buffer = Qnil;
|
2307
|
+
}
|
2308
|
+
if (buffer == Qnil)
|
2309
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2310
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2311
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2312
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2313
|
+
pdlc_fb_cb_esub(mfbuf, ocbuf, rcbuf);
|
2314
|
+
}
|
2315
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2316
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2317
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2318
|
+
pdlc_fb_cs_esub(mfbuf, oc, rcbuf);
|
2319
|
+
}
|
2320
|
+
}
|
2321
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2322
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2323
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2324
|
+
buffer = Qnil;
|
2325
|
+
}
|
2326
|
+
if (buffer == Qnil)
|
2327
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2328
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2329
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2330
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2331
|
+
pdlc_fb_fb_esub(mfbuf, ofbuf, rfbuf);
|
2332
|
+
}
|
2333
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2334
|
+
of = (float)NUM2DBL(other);
|
2335
|
+
pdlc_fb_fs_esub(mfbuf, of, rfbuf);
|
2336
|
+
}
|
2337
|
+
}
|
2338
|
+
else
|
2339
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2340
|
+
|
2341
|
+
return buffer;
|
2342
|
+
}
|
2343
|
+
|
2344
|
+
|
2345
|
+
/* Element by element soustraction.
|
2346
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2347
|
+
* @return [self]
|
2348
|
+
*/
|
2349
|
+
static VALUE paddlec_float_buffer_esub_inplace(VALUE self, VALUE other)
|
2350
|
+
{
|
2351
|
+
pdlc_buffer_t *mfbuf;
|
2352
|
+
const pdlc_buffer_t *ofbuf;
|
2353
|
+
float of;
|
2354
|
+
|
2355
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2356
|
+
|
2357
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2358
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2359
|
+
pdlc_fb_fb_esub_inplace(mfbuf, ofbuf);
|
2360
|
+
}
|
2361
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2362
|
+
of = (float)NUM2DBL(other);
|
2363
|
+
pdlc_fb_fs_esub_inplace(mfbuf, of);
|
2364
|
+
}
|
2365
|
+
else
|
2366
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2367
|
+
|
2368
|
+
return self;
|
2369
|
+
}
|
2370
|
+
|
2371
|
+
|
2372
|
+
/* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2373
|
+
* @overload +(other, buffer = nil)
|
2374
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2375
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2376
|
+
* @return [PaddleC::FloatBuffer]
|
2377
|
+
* @overload +(other, buffer = nil)
|
2378
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2379
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2380
|
+
* @return [PaddleC::ComplexBuffer]
|
2381
|
+
*/
|
2382
|
+
static VALUE paddlec_float_buffer_add(int argc, VALUE *argv, VALUE self)
|
2383
|
+
{
|
2384
|
+
const pdlc_buffer_t *mfbuf;
|
2385
|
+
pdlc_buffer_t *rfbuf;
|
2386
|
+
pdlc_complex_buffer_t *rcbuf;
|
2387
|
+
const pdlc_buffer_t *ofbuf;
|
2388
|
+
float of;
|
2389
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2390
|
+
pdlc_complex_t oc;
|
2391
|
+
VALUE other, buffer;
|
2392
|
+
|
2393
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2394
|
+
|
2395
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2396
|
+
|
2397
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2398
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2399
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2400
|
+
buffer = Qnil;
|
2401
|
+
}
|
2402
|
+
if (buffer == Qnil)
|
2403
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2404
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2405
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2406
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2407
|
+
pdlc_fb_cb_add(mfbuf, ocbuf, rcbuf);
|
2408
|
+
}
|
2409
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2410
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2411
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2412
|
+
pdlc_fb_cs_add(mfbuf, oc, rcbuf);
|
2413
|
+
}
|
2414
|
+
}
|
2415
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2416
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2417
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2418
|
+
buffer = Qnil;
|
2419
|
+
}
|
2420
|
+
if (buffer == Qnil)
|
2421
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2422
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2423
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2424
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2425
|
+
pdlc_fb_fb_add(mfbuf, ofbuf, rfbuf);
|
2426
|
+
}
|
2427
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2428
|
+
of = (float)NUM2DBL(other);
|
2429
|
+
pdlc_fb_fs_add(mfbuf, of, rfbuf);
|
2430
|
+
}
|
2431
|
+
}
|
2432
|
+
else
|
2433
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2434
|
+
|
2435
|
+
return buffer;
|
2436
|
+
}
|
2437
|
+
|
2438
|
+
|
2439
|
+
/* @param other [c_FloatBuffer, rb_cNumeric]
|
2440
|
+
* @return [self]
|
2441
|
+
*/
|
2442
|
+
static VALUE paddlec_float_buffer_add_inplace(VALUE self, VALUE other)
|
2443
|
+
{
|
2444
|
+
pdlc_buffer_t *mfbuf;
|
2445
|
+
const pdlc_buffer_t *ofbuf;
|
2446
|
+
float of;
|
2447
|
+
|
2448
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2449
|
+
|
2450
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2451
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2452
|
+
pdlc_fb_fb_add_inplace(mfbuf, ofbuf);
|
2453
|
+
}
|
2454
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2455
|
+
of = (float)NUM2DBL(other);
|
2456
|
+
pdlc_fb_fs_add_inplace(mfbuf, of);
|
2457
|
+
}
|
2458
|
+
else
|
2459
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2460
|
+
|
2461
|
+
return self;
|
2462
|
+
}
|
2463
|
+
|
2464
|
+
|
2465
|
+
/* Element by element addition.
|
2466
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2467
|
+
* @overload eadd(other, buffer = nil)
|
2468
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2469
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2470
|
+
* @return [PaddleC::FloatBuffer]
|
2471
|
+
* @overload eadd(other, buffer = nil)
|
2472
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2473
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2474
|
+
* @return [PaddleC::ComplexBuffer]
|
2475
|
+
*/
|
2476
|
+
static VALUE paddlec_float_buffer_eadd(int argc, VALUE *argv, VALUE self)
|
2477
|
+
{
|
2478
|
+
const pdlc_buffer_t *mfbuf;
|
2479
|
+
pdlc_buffer_t *rfbuf;
|
2480
|
+
pdlc_complex_buffer_t *rcbuf;
|
2481
|
+
const pdlc_buffer_t *ofbuf;
|
2482
|
+
float of;
|
2483
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2484
|
+
pdlc_complex_t oc;
|
2485
|
+
VALUE other, buffer;
|
2486
|
+
|
2487
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2488
|
+
|
2489
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2490
|
+
|
2491
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2492
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2493
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2494
|
+
buffer = Qnil;
|
2495
|
+
}
|
2496
|
+
if (buffer == Qnil)
|
2497
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2498
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2499
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2500
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2501
|
+
pdlc_fb_cb_eadd(mfbuf, ocbuf, rcbuf);
|
2502
|
+
}
|
2503
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2504
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2505
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2506
|
+
pdlc_fb_cs_eadd(mfbuf, oc, rcbuf);
|
2507
|
+
}
|
2508
|
+
}
|
2509
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2510
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2511
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2512
|
+
buffer = Qnil;
|
2513
|
+
}
|
2514
|
+
if (buffer == Qnil)
|
2515
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2516
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2517
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2518
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2519
|
+
pdlc_fb_fb_eadd(mfbuf, ofbuf, rfbuf);
|
2520
|
+
}
|
2521
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2522
|
+
of = (float)NUM2DBL(other);
|
2523
|
+
pdlc_fb_fs_eadd(mfbuf, of, rfbuf);
|
2524
|
+
}
|
2525
|
+
}
|
2526
|
+
else
|
2527
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2528
|
+
|
2529
|
+
return buffer;
|
2530
|
+
}
|
2531
|
+
|
2532
|
+
|
2533
|
+
/* Element by element addition.
|
2534
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2535
|
+
* @return [self]
|
2536
|
+
*/
|
2537
|
+
static VALUE paddlec_float_buffer_eadd_inplace(VALUE self, VALUE other)
|
2538
|
+
{
|
2539
|
+
pdlc_buffer_t *mfbuf;
|
2540
|
+
const pdlc_buffer_t *ofbuf;
|
2541
|
+
float of;
|
2542
|
+
|
2543
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2544
|
+
|
2545
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2546
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2547
|
+
pdlc_fb_fb_eadd_inplace(mfbuf, ofbuf);
|
2548
|
+
}
|
2549
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2550
|
+
of = (float)NUM2DBL(other);
|
2551
|
+
pdlc_fb_fs_eadd_inplace(mfbuf, of);
|
2552
|
+
}
|
2553
|
+
else
|
2554
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2555
|
+
|
2556
|
+
return self;
|
2557
|
+
}
|
2558
|
+
|
2559
|
+
|
2560
|
+
/* Performs multiplication.
|
2561
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2562
|
+
* @overload *(other, buffer = nil)
|
2563
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2564
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2565
|
+
* @return [PaddleC::FloatBuffer]
|
2566
|
+
* @overload *(other, buffer = nil)
|
2567
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2568
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2569
|
+
* @return [PaddleC::ComplexBuffer]
|
2570
|
+
*/
|
2571
|
+
static VALUE paddlec_float_buffer_mult(int argc, VALUE *argv, VALUE self)
|
2572
|
+
{
|
2573
|
+
const pdlc_buffer_t *mfbuf;
|
2574
|
+
pdlc_buffer_t *rfbuf;
|
2575
|
+
pdlc_complex_buffer_t *rcbuf;
|
2576
|
+
const pdlc_buffer_t *ofbuf;
|
2577
|
+
float of;
|
2578
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2579
|
+
pdlc_complex_t oc;
|
2580
|
+
VALUE other, buffer;
|
2581
|
+
|
2582
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2583
|
+
|
2584
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2585
|
+
|
2586
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2587
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2588
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2589
|
+
buffer = Qnil;
|
2590
|
+
}
|
2591
|
+
if (buffer == Qnil)
|
2592
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2593
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2594
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2595
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2596
|
+
pdlc_fb_cb_mult(mfbuf, ocbuf, rcbuf);
|
2597
|
+
}
|
2598
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2599
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2600
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2601
|
+
pdlc_fb_cs_mult(mfbuf, oc, rcbuf);
|
2602
|
+
}
|
2603
|
+
}
|
2604
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2605
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2606
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2607
|
+
buffer = Qnil;
|
2608
|
+
}
|
2609
|
+
if (buffer == Qnil)
|
2610
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2611
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2612
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2613
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2614
|
+
pdlc_fb_fb_mult(mfbuf, ofbuf, rfbuf);
|
2615
|
+
}
|
2616
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2617
|
+
of = (float)NUM2DBL(other);
|
2618
|
+
pdlc_fb_fs_mult(mfbuf, of, rfbuf);
|
2619
|
+
}
|
2620
|
+
}
|
2621
|
+
else
|
2622
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2623
|
+
|
2624
|
+
return buffer;
|
2625
|
+
}
|
2626
|
+
|
2627
|
+
|
2628
|
+
/* Performs multiplication.
|
2629
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2630
|
+
* @return [self]
|
2631
|
+
*/
|
2632
|
+
static VALUE paddlec_float_buffer_mult_inplace(VALUE self, VALUE other)
|
2633
|
+
{
|
2634
|
+
pdlc_buffer_t *mfbuf;
|
2635
|
+
const pdlc_buffer_t *ofbuf;
|
2636
|
+
float of;
|
2637
|
+
|
2638
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2639
|
+
|
2640
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2641
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2642
|
+
pdlc_fb_fb_mult_inplace(mfbuf, ofbuf);
|
2643
|
+
}
|
2644
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2645
|
+
of = (float)NUM2DBL(other);
|
2646
|
+
pdlc_fb_fs_mult_inplace(mfbuf, of);
|
2647
|
+
}
|
2648
|
+
else
|
2649
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2650
|
+
|
2651
|
+
return self;
|
2652
|
+
}
|
2653
|
+
|
2654
|
+
|
2655
|
+
/* Element by element multiplication.
|
2656
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2657
|
+
* @overload emult(other, buffer = nil)
|
2658
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2659
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2660
|
+
* @return [PaddleC::FloatBuffer]
|
2661
|
+
* @overload emult(other, buffer = nil)
|
2662
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2663
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2664
|
+
* @return [PaddleC::ComplexBuffer]
|
2665
|
+
*/
|
2666
|
+
static VALUE paddlec_float_buffer_emult(int argc, VALUE *argv, VALUE self)
|
2667
|
+
{
|
2668
|
+
const pdlc_buffer_t *mfbuf;
|
2669
|
+
pdlc_buffer_t *rfbuf;
|
2670
|
+
pdlc_complex_buffer_t *rcbuf;
|
2671
|
+
const pdlc_buffer_t *ofbuf;
|
2672
|
+
float of;
|
2673
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2674
|
+
pdlc_complex_t oc;
|
2675
|
+
VALUE other, buffer;
|
2676
|
+
|
2677
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2678
|
+
|
2679
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2680
|
+
|
2681
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2682
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2683
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2684
|
+
buffer = Qnil;
|
2685
|
+
}
|
2686
|
+
if (buffer == Qnil)
|
2687
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2688
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2689
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2690
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2691
|
+
pdlc_fb_cb_emult(mfbuf, ocbuf, rcbuf);
|
2692
|
+
}
|
2693
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2694
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2695
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2696
|
+
pdlc_fb_cs_emult(mfbuf, oc, rcbuf);
|
2697
|
+
}
|
2698
|
+
}
|
2699
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2700
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2701
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2702
|
+
buffer = Qnil;
|
2703
|
+
}
|
2704
|
+
if (buffer == Qnil)
|
2705
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2706
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2707
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2708
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2709
|
+
pdlc_fb_fb_emult(mfbuf, ofbuf, rfbuf);
|
2710
|
+
}
|
2711
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2712
|
+
of = (float)NUM2DBL(other);
|
2713
|
+
pdlc_fb_fs_emult(mfbuf, of, rfbuf);
|
2714
|
+
}
|
2715
|
+
}
|
2716
|
+
else
|
2717
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2718
|
+
|
2719
|
+
return buffer;
|
2720
|
+
}
|
2721
|
+
|
2722
|
+
|
2723
|
+
/* Element by element multiplication.
|
2724
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2725
|
+
* @return [self]
|
2726
|
+
*/
|
2727
|
+
static VALUE paddlec_float_buffer_emult_inplace(VALUE self, VALUE other)
|
2728
|
+
{
|
2729
|
+
pdlc_buffer_t *mfbuf;
|
2730
|
+
const pdlc_buffer_t *ofbuf;
|
2731
|
+
float of;
|
2732
|
+
|
2733
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2734
|
+
|
2735
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2736
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2737
|
+
pdlc_fb_fb_emult_inplace(mfbuf, ofbuf);
|
2738
|
+
}
|
2739
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2740
|
+
of = (float)NUM2DBL(other);
|
2741
|
+
pdlc_fb_fs_emult_inplace(mfbuf, of);
|
2742
|
+
}
|
2743
|
+
else
|
2744
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2745
|
+
|
2746
|
+
return self;
|
2747
|
+
}
|
2748
|
+
|
2749
|
+
|
2750
|
+
/* Performs division.
|
2751
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2752
|
+
* @overload /(other, buffer = nil)
|
2753
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2754
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2755
|
+
* @return [PaddleC::FloatBuffer]
|
2756
|
+
* @overload /(other, buffer = nil)
|
2757
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2758
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2759
|
+
* @return [PaddleC::ComplexBuffer]
|
2760
|
+
*/
|
2761
|
+
static VALUE paddlec_float_buffer_div(int argc, VALUE *argv, VALUE self)
|
2762
|
+
{
|
2763
|
+
const pdlc_buffer_t *mfbuf;
|
2764
|
+
pdlc_buffer_t *rfbuf;
|
2765
|
+
pdlc_complex_buffer_t *rcbuf;
|
2766
|
+
const pdlc_buffer_t *ofbuf;
|
2767
|
+
float of;
|
2768
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2769
|
+
pdlc_complex_t oc;
|
2770
|
+
VALUE other, buffer;
|
2771
|
+
|
2772
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2773
|
+
|
2774
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2775
|
+
|
2776
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2777
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2778
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2779
|
+
buffer = Qnil;
|
2780
|
+
}
|
2781
|
+
if (buffer == Qnil)
|
2782
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2783
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2784
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2785
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2786
|
+
pdlc_fb_cb_div(mfbuf, ocbuf, rcbuf);
|
2787
|
+
}
|
2788
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2789
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2790
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2791
|
+
pdlc_fb_cs_div(mfbuf, oc, rcbuf);
|
2792
|
+
}
|
2793
|
+
}
|
2794
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2795
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2796
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2797
|
+
buffer = Qnil;
|
2798
|
+
}
|
2799
|
+
if (buffer == Qnil)
|
2800
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2801
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2802
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2803
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2804
|
+
pdlc_fb_fb_div(mfbuf, ofbuf, rfbuf);
|
2805
|
+
}
|
2806
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2807
|
+
of = (float)NUM2DBL(other);
|
2808
|
+
pdlc_fb_fs_div(mfbuf, of, rfbuf);
|
2809
|
+
}
|
2810
|
+
}
|
2811
|
+
else
|
2812
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2813
|
+
|
2814
|
+
return buffer;
|
2815
|
+
}
|
2816
|
+
|
2817
|
+
|
2818
|
+
/* Performs division.
|
2819
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2820
|
+
* @return [self]
|
2821
|
+
*/
|
2822
|
+
static VALUE paddlec_float_buffer_div_inplace(VALUE self, VALUE other)
|
2823
|
+
{
|
2824
|
+
pdlc_buffer_t *mfbuf;
|
2825
|
+
const pdlc_buffer_t *ofbuf;
|
2826
|
+
float of;
|
2827
|
+
|
2828
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2829
|
+
|
2830
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2831
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2832
|
+
pdlc_fb_fb_div_inplace(mfbuf, ofbuf);
|
2833
|
+
}
|
2834
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2835
|
+
of = (float)NUM2DBL(other);
|
2836
|
+
pdlc_fb_fs_div_inplace(mfbuf, of);
|
2837
|
+
}
|
2838
|
+
else
|
2839
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2840
|
+
|
2841
|
+
return self;
|
2842
|
+
}
|
2843
|
+
|
2844
|
+
|
2845
|
+
/* Element by element division.
|
2846
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
2847
|
+
* @overload ediv(other, buffer = nil)
|
2848
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2849
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2850
|
+
* @return [PaddleC::FloatBuffer]
|
2851
|
+
* @overload ediv(other, buffer = nil)
|
2852
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
2853
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
2854
|
+
* @return [PaddleC::ComplexBuffer]
|
2855
|
+
*/
|
2856
|
+
static VALUE paddlec_float_buffer_ediv(int argc, VALUE *argv, VALUE self)
|
2857
|
+
{
|
2858
|
+
const pdlc_buffer_t *mfbuf;
|
2859
|
+
pdlc_buffer_t *rfbuf;
|
2860
|
+
pdlc_complex_buffer_t *rcbuf;
|
2861
|
+
const pdlc_buffer_t *ofbuf;
|
2862
|
+
float of;
|
2863
|
+
const pdlc_complex_buffer_t *ocbuf;
|
2864
|
+
pdlc_complex_t oc;
|
2865
|
+
VALUE other, buffer;
|
2866
|
+
|
2867
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2868
|
+
|
2869
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2870
|
+
|
2871
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
2872
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
2873
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
2874
|
+
buffer = Qnil;
|
2875
|
+
}
|
2876
|
+
if (buffer == Qnil)
|
2877
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
2878
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
2879
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
2880
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
2881
|
+
pdlc_fb_cb_ediv(mfbuf, ocbuf, rcbuf);
|
2882
|
+
}
|
2883
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
2884
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
2885
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
2886
|
+
pdlc_fb_cs_ediv(mfbuf, oc, rcbuf);
|
2887
|
+
}
|
2888
|
+
}
|
2889
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2890
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2891
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2892
|
+
buffer = Qnil;
|
2893
|
+
}
|
2894
|
+
if (buffer == Qnil)
|
2895
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2896
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2897
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2898
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2899
|
+
pdlc_fb_fb_ediv(mfbuf, ofbuf, rfbuf);
|
2900
|
+
}
|
2901
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2902
|
+
of = (float)NUM2DBL(other);
|
2903
|
+
pdlc_fb_fs_ediv(mfbuf, of, rfbuf);
|
2904
|
+
}
|
2905
|
+
}
|
2906
|
+
else
|
2907
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2908
|
+
|
2909
|
+
return buffer;
|
2910
|
+
}
|
2911
|
+
|
2912
|
+
|
2913
|
+
/* Element by element division.
|
2914
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2915
|
+
* @return [self]
|
2916
|
+
*/
|
2917
|
+
static VALUE paddlec_float_buffer_ediv_inplace(VALUE self, VALUE other)
|
2918
|
+
{
|
2919
|
+
pdlc_buffer_t *mfbuf;
|
2920
|
+
const pdlc_buffer_t *ofbuf;
|
2921
|
+
float of;
|
2922
|
+
|
2923
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2924
|
+
|
2925
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2926
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2927
|
+
pdlc_fb_fb_ediv_inplace(mfbuf, ofbuf);
|
2928
|
+
}
|
2929
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2930
|
+
of = (float)NUM2DBL(other);
|
2931
|
+
pdlc_fb_fs_ediv_inplace(mfbuf, of);
|
2932
|
+
}
|
2933
|
+
else
|
2934
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2935
|
+
|
2936
|
+
return self;
|
2937
|
+
}
|
2938
|
+
|
2939
|
+
|
2940
|
+
/* Performs exponentiation. Raises +self+ to the power of +rhs+.
|
2941
|
+
* @return [PaddleC::FloatBuffer]
|
2942
|
+
* @overload **(other, buffer = nil)
|
2943
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
2944
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
2945
|
+
* @return [PaddleC::FloatBuffer]
|
2946
|
+
*/
|
2947
|
+
static VALUE paddlec_float_buffer_pow(int argc, VALUE *argv, VALUE self)
|
2948
|
+
{
|
2949
|
+
const pdlc_buffer_t *mfbuf;
|
2950
|
+
pdlc_buffer_t *rfbuf;
|
2951
|
+
const pdlc_buffer_t *ofbuf;
|
2952
|
+
float of;
|
2953
|
+
VALUE other, buffer;
|
2954
|
+
|
2955
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
2956
|
+
|
2957
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2958
|
+
|
2959
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2960
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
2961
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
2962
|
+
buffer = Qnil;
|
2963
|
+
}
|
2964
|
+
if (buffer == Qnil)
|
2965
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
2966
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
2967
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2968
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2969
|
+
pdlc_fb_fb_pow(mfbuf, ofbuf, rfbuf);
|
2970
|
+
}
|
2971
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
2972
|
+
of = (float)NUM2DBL(other);
|
2973
|
+
pdlc_fb_fs_pow(mfbuf, of, rfbuf);
|
2974
|
+
}
|
2975
|
+
}
|
2976
|
+
else
|
2977
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
2978
|
+
|
2979
|
+
return buffer;
|
2980
|
+
}
|
2981
|
+
|
2982
|
+
|
2983
|
+
/* Performs exponentiation. Raises +self+ to the power of +rhs+.
|
2984
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
2985
|
+
* @return [self]
|
2986
|
+
*/
|
2987
|
+
static VALUE paddlec_float_buffer_pow_inplace(VALUE self, VALUE other)
|
2988
|
+
{
|
2989
|
+
pdlc_buffer_t *mfbuf;
|
2990
|
+
const pdlc_buffer_t *ofbuf;
|
2991
|
+
float of;
|
2992
|
+
|
2993
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
2994
|
+
|
2995
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
2996
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
2997
|
+
pdlc_fb_fb_pow_inplace(mfbuf, ofbuf);
|
2998
|
+
}
|
2999
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3000
|
+
of = (float)NUM2DBL(other);
|
3001
|
+
pdlc_fb_fs_pow_inplace(mfbuf, of);
|
3002
|
+
}
|
3003
|
+
else
|
3004
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3005
|
+
|
3006
|
+
return self;
|
3007
|
+
}
|
3008
|
+
|
3009
|
+
|
3010
|
+
/* Returns the modulo after division of values of +lhs+ by values of +rhs+.
|
3011
|
+
* @return [PaddleC::FloatBuffer]
|
3012
|
+
* @overload %(other, buffer = nil)
|
3013
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
3014
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
3015
|
+
* @return [PaddleC::FloatBuffer]
|
3016
|
+
*/
|
3017
|
+
static VALUE paddlec_float_buffer_modulo(int argc, VALUE *argv, VALUE self)
|
3018
|
+
{
|
3019
|
+
const pdlc_buffer_t *mfbuf;
|
3020
|
+
pdlc_buffer_t *rfbuf;
|
3021
|
+
const pdlc_buffer_t *ofbuf;
|
3022
|
+
float of;
|
3023
|
+
VALUE other, buffer;
|
3024
|
+
|
3025
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
3026
|
+
|
3027
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3028
|
+
|
3029
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3030
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3031
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3032
|
+
buffer = Qnil;
|
3033
|
+
}
|
3034
|
+
if (buffer == Qnil)
|
3035
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3036
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3037
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
3038
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
3039
|
+
pdlc_fb_fb_modulo(mfbuf, ofbuf, rfbuf);
|
3040
|
+
}
|
3041
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3042
|
+
of = (float)NUM2DBL(other);
|
3043
|
+
pdlc_fb_fs_modulo(mfbuf, of, rfbuf);
|
3044
|
+
}
|
3045
|
+
}
|
3046
|
+
else
|
3047
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3048
|
+
|
3049
|
+
return buffer;
|
3050
|
+
}
|
3051
|
+
|
3052
|
+
|
3053
|
+
/* Returns the modulo after division of values of +lhs+ by values of +rhs+.
|
3054
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
3055
|
+
* @return [self]
|
3056
|
+
*/
|
3057
|
+
static VALUE paddlec_float_buffer_modulo_inplace(VALUE self, VALUE other)
|
3058
|
+
{
|
3059
|
+
pdlc_buffer_t *mfbuf;
|
3060
|
+
const pdlc_buffer_t *ofbuf;
|
3061
|
+
float of;
|
3062
|
+
|
3063
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3064
|
+
|
3065
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
3066
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
3067
|
+
pdlc_fb_fb_modulo_inplace(mfbuf, ofbuf);
|
3068
|
+
}
|
3069
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3070
|
+
of = (float)NUM2DBL(other);
|
3071
|
+
pdlc_fb_fs_modulo_inplace(mfbuf, of);
|
3072
|
+
}
|
3073
|
+
else
|
3074
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3075
|
+
|
3076
|
+
return self;
|
3077
|
+
}
|
3078
|
+
|
3079
|
+
|
3080
|
+
/* Element by element modulo.
|
3081
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
3082
|
+
* @overload emod(other, buffer = nil)
|
3083
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
3084
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
3085
|
+
* @return [PaddleC::FloatBuffer]
|
3086
|
+
* @overload emod(other, buffer = nil)
|
3087
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
3088
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
3089
|
+
* @return [PaddleC::ComplexBuffer]
|
3090
|
+
*/
|
3091
|
+
static VALUE paddlec_float_buffer_emod(int argc, VALUE *argv, VALUE self)
|
3092
|
+
{
|
3093
|
+
const pdlc_buffer_t *mfbuf;
|
3094
|
+
pdlc_buffer_t *rfbuf;
|
3095
|
+
pdlc_complex_buffer_t *rcbuf;
|
3096
|
+
const pdlc_buffer_t *ofbuf;
|
3097
|
+
float of;
|
3098
|
+
const pdlc_complex_buffer_t *ocbuf;
|
3099
|
+
pdlc_complex_t oc;
|
3100
|
+
VALUE other, buffer;
|
3101
|
+
|
3102
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
3103
|
+
|
3104
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3105
|
+
|
3106
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
3107
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
3108
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
3109
|
+
buffer = Qnil;
|
3110
|
+
}
|
3111
|
+
if (buffer == Qnil)
|
3112
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
3113
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
3114
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
3115
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
3116
|
+
pdlc_fb_cb_emod(mfbuf, ocbuf, rcbuf);
|
3117
|
+
}
|
3118
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
3119
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
3120
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
3121
|
+
pdlc_fb_cs_emod(mfbuf, oc, rcbuf);
|
3122
|
+
}
|
3123
|
+
}
|
3124
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3125
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3126
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3127
|
+
buffer = Qnil;
|
3128
|
+
}
|
3129
|
+
if (buffer == Qnil)
|
3130
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3131
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3132
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
3133
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
3134
|
+
pdlc_fb_fb_emod(mfbuf, ofbuf, rfbuf);
|
3135
|
+
}
|
3136
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3137
|
+
of = (float)NUM2DBL(other);
|
3138
|
+
pdlc_fb_fs_emod(mfbuf, of, rfbuf);
|
3139
|
+
}
|
3140
|
+
}
|
3141
|
+
else
|
3142
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3143
|
+
|
3144
|
+
return buffer;
|
3145
|
+
}
|
3146
|
+
|
3147
|
+
|
3148
|
+
/* Element by element modulo.
|
3149
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
3150
|
+
* @return [self]
|
3151
|
+
*/
|
3152
|
+
static VALUE paddlec_float_buffer_emod_inplace(VALUE self, VALUE other)
|
3153
|
+
{
|
3154
|
+
pdlc_buffer_t *mfbuf;
|
3155
|
+
const pdlc_buffer_t *ofbuf;
|
3156
|
+
float of;
|
3157
|
+
|
3158
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3159
|
+
|
3160
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
3161
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
3162
|
+
pdlc_fb_fb_emod_inplace(mfbuf, ofbuf);
|
3163
|
+
}
|
3164
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3165
|
+
of = (float)NUM2DBL(other);
|
3166
|
+
pdlc_fb_fs_emod_inplace(mfbuf, of);
|
3167
|
+
}
|
3168
|
+
else
|
3169
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3170
|
+
|
3171
|
+
return self;
|
3172
|
+
}
|
3173
|
+
|
3174
|
+
|
3175
|
+
/* Element by element exponentiation.
|
3176
|
+
* @return [PaddleC::FloatBuffer, PaddleC::ComplexBuffer]
|
3177
|
+
* @overload epow(other, buffer = nil)
|
3178
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
3179
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
3180
|
+
* @return [PaddleC::FloatBuffer]
|
3181
|
+
* @overload epow(other, buffer = nil)
|
3182
|
+
* @param other [PaddleC::ComplexBuffer, Complex]
|
3183
|
+
* @param buffer [nil, PaddleC::ComplexBuffer] if a {ComplexBuffer} is provided, it is filled with the output
|
3184
|
+
* @return [PaddleC::ComplexBuffer]
|
3185
|
+
*/
|
3186
|
+
static VALUE paddlec_float_buffer_epow(int argc, VALUE *argv, VALUE self)
|
3187
|
+
{
|
3188
|
+
const pdlc_buffer_t *mfbuf;
|
3189
|
+
pdlc_buffer_t *rfbuf;
|
3190
|
+
pdlc_complex_buffer_t *rcbuf;
|
3191
|
+
const pdlc_buffer_t *ofbuf;
|
3192
|
+
float of;
|
3193
|
+
const pdlc_complex_buffer_t *ocbuf;
|
3194
|
+
pdlc_complex_t oc;
|
3195
|
+
VALUE other, buffer;
|
3196
|
+
|
3197
|
+
rb_scan_args(argc, argv, "11", &other, &buffer);
|
3198
|
+
|
3199
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3200
|
+
|
3201
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer) || rb_obj_is_kind_of(other, rb_cComplex)) {
|
3202
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_ComplexBuffer)) {
|
3203
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_class_of(buffer)));
|
3204
|
+
buffer = Qnil;
|
3205
|
+
}
|
3206
|
+
if (buffer == Qnil)
|
3207
|
+
buffer = rb_class_new_instance(0, NULL, c_ComplexBuffer);
|
3208
|
+
rcbuf = paddlec_complex_buffer_get_struct(buffer);
|
3209
|
+
if (rb_obj_is_kind_of(other, c_ComplexBuffer)) {
|
3210
|
+
ocbuf = paddlec_complex_buffer_get_struct(other);
|
3211
|
+
pdlc_fb_cb_epow(mfbuf, ocbuf, rcbuf);
|
3212
|
+
}
|
3213
|
+
else if (rb_obj_is_kind_of(other, rb_cComplex)) {
|
3214
|
+
oc.real = (float)NUM2DBL(rb_funcallv(other, id_real, 0, NULL));
|
3215
|
+
oc.imag = (float)NUM2DBL(rb_funcallv(other, id_imag, 0, NULL));
|
3216
|
+
pdlc_fb_cs_epow(mfbuf, oc, rcbuf);
|
3217
|
+
}
|
3218
|
+
}
|
3219
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3220
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3221
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3222
|
+
buffer = Qnil;
|
3223
|
+
}
|
3224
|
+
if (buffer == Qnil)
|
3225
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3226
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3227
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
3228
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
3229
|
+
pdlc_fb_fb_epow(mfbuf, ofbuf, rfbuf);
|
3230
|
+
}
|
3231
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3232
|
+
of = (float)NUM2DBL(other);
|
3233
|
+
pdlc_fb_fs_epow(mfbuf, of, rfbuf);
|
3234
|
+
}
|
3235
|
+
}
|
3236
|
+
else
|
3237
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_ComplexBuffer), rb_class_name(rb_cComplex), rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3238
|
+
|
3239
|
+
return buffer;
|
3240
|
+
}
|
3241
|
+
|
3242
|
+
|
3243
|
+
/* Element by element exponentiation.
|
3244
|
+
* @param other [c_FloatBuffer, rb_cNumeric]
|
3245
|
+
* @return [self]
|
3246
|
+
*/
|
3247
|
+
static VALUE paddlec_float_buffer_epow_inplace(VALUE self, VALUE other)
|
3248
|
+
{
|
3249
|
+
pdlc_buffer_t *mfbuf;
|
3250
|
+
const pdlc_buffer_t *ofbuf;
|
3251
|
+
float of;
|
3252
|
+
|
3253
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3254
|
+
|
3255
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
3256
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
3257
|
+
pdlc_fb_fb_epow_inplace(mfbuf, ofbuf);
|
3258
|
+
}
|
3259
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
3260
|
+
of = (float)NUM2DBL(other);
|
3261
|
+
pdlc_fb_fs_epow_inplace(mfbuf, of);
|
3262
|
+
}
|
3263
|
+
else
|
3264
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
3265
|
+
|
3266
|
+
return self;
|
3267
|
+
}
|
3268
|
+
|
3269
|
+
|
3270
|
+
/* @!endgroup
|
3271
|
+
*/
|
3272
|
+
|
3273
|
+
|
3274
|
+
/* @!group Math
|
3275
|
+
*/
|
3276
|
+
|
3277
|
+
|
3278
|
+
/* Computes the arc cosine of values of +self+. Returns 0..PI.
|
3279
|
+
* @overload acos(buffer = nil)
|
3280
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3281
|
+
* @return [PaddleC::FloatBuffer]
|
3282
|
+
*/
|
3283
|
+
static VALUE paddlec_float_buffer_acos(int argc, VALUE *argv, VALUE self)
|
3284
|
+
{
|
3285
|
+
const pdlc_buffer_t *mfbuf;
|
3286
|
+
pdlc_buffer_t *rfbuf;
|
3287
|
+
VALUE buffer;
|
3288
|
+
|
3289
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3290
|
+
|
3291
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3292
|
+
|
3293
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3294
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3295
|
+
buffer = Qnil;
|
3296
|
+
}
|
3297
|
+
if (buffer == Qnil)
|
3298
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3299
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3300
|
+
|
3301
|
+
pdlc_buffer_acos(mfbuf, rfbuf);
|
3302
|
+
|
3303
|
+
return buffer;
|
3304
|
+
}
|
3305
|
+
|
3306
|
+
|
3307
|
+
/* Computes the arc cosine of values of +self+. Returns 0..PI.
|
3308
|
+
* @return [self]
|
3309
|
+
*/
|
3310
|
+
static VALUE paddlec_float_buffer_acos_inplace(VALUE self)
|
3311
|
+
{
|
3312
|
+
pdlc_buffer_t *mfbuf;
|
3313
|
+
|
3314
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3315
|
+
|
3316
|
+
pdlc_buffer_acos_inplace(mfbuf);
|
3317
|
+
|
3318
|
+
return self;
|
3319
|
+
}
|
3320
|
+
|
3321
|
+
|
3322
|
+
/* Computes the inverse hyperbolic cosine of values of +self+.
|
3323
|
+
* @overload acosh(buffer = nil)
|
3324
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3325
|
+
* @return [PaddleC::FloatBuffer]
|
3326
|
+
*/
|
3327
|
+
static VALUE paddlec_float_buffer_acosh(int argc, VALUE *argv, VALUE self)
|
3328
|
+
{
|
3329
|
+
const pdlc_buffer_t *mfbuf;
|
3330
|
+
pdlc_buffer_t *rfbuf;
|
3331
|
+
VALUE buffer;
|
3332
|
+
|
3333
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3334
|
+
|
3335
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3336
|
+
|
3337
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3338
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3339
|
+
buffer = Qnil;
|
3340
|
+
}
|
3341
|
+
if (buffer == Qnil)
|
3342
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3343
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3344
|
+
|
3345
|
+
pdlc_buffer_acosh(mfbuf, rfbuf);
|
3346
|
+
|
3347
|
+
return buffer;
|
3348
|
+
}
|
3349
|
+
|
3350
|
+
|
3351
|
+
/* Computes the inverse hyperbolic cosine of values of +self+.
|
3352
|
+
* @return [self]
|
3353
|
+
*/
|
3354
|
+
static VALUE paddlec_float_buffer_acosh_inplace(VALUE self)
|
3355
|
+
{
|
3356
|
+
pdlc_buffer_t *mfbuf;
|
3357
|
+
|
3358
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3359
|
+
|
3360
|
+
pdlc_buffer_acosh_inplace(mfbuf);
|
3361
|
+
|
3362
|
+
return self;
|
3363
|
+
}
|
3364
|
+
|
3365
|
+
|
3366
|
+
/* Computes the arc sine of values of +self+. Returns -PI/2..PI/2.
|
3367
|
+
* @overload asin(buffer = nil)
|
3368
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3369
|
+
* @return [PaddleC::FloatBuffer]
|
3370
|
+
*/
|
3371
|
+
static VALUE paddlec_float_buffer_asin(int argc, VALUE *argv, VALUE self)
|
3372
|
+
{
|
3373
|
+
const pdlc_buffer_t *mfbuf;
|
3374
|
+
pdlc_buffer_t *rfbuf;
|
3375
|
+
VALUE buffer;
|
3376
|
+
|
3377
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3378
|
+
|
3379
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3380
|
+
|
3381
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3382
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3383
|
+
buffer = Qnil;
|
3384
|
+
}
|
3385
|
+
if (buffer == Qnil)
|
3386
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3387
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3388
|
+
|
3389
|
+
pdlc_buffer_asin(mfbuf, rfbuf);
|
3390
|
+
|
3391
|
+
return buffer;
|
3392
|
+
}
|
3393
|
+
|
3394
|
+
|
3395
|
+
/* Computes the arc sine of values of +self+. Returns -PI/2..PI/2.
|
3396
|
+
* @return [self]
|
3397
|
+
*/
|
3398
|
+
static VALUE paddlec_float_buffer_asin_inplace(VALUE self)
|
3399
|
+
{
|
3400
|
+
pdlc_buffer_t *mfbuf;
|
3401
|
+
|
3402
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3403
|
+
|
3404
|
+
pdlc_buffer_asin_inplace(mfbuf);
|
3405
|
+
|
3406
|
+
return self;
|
3407
|
+
}
|
3408
|
+
|
3409
|
+
|
3410
|
+
/* Computes the inverse hyperbolic sine of values of +self+.
|
3411
|
+
* @overload asinh(buffer = nil)
|
3412
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3413
|
+
* @return [PaddleC::FloatBuffer]
|
3414
|
+
*/
|
3415
|
+
static VALUE paddlec_float_buffer_asinh(int argc, VALUE *argv, VALUE self)
|
3416
|
+
{
|
3417
|
+
const pdlc_buffer_t *mfbuf;
|
3418
|
+
pdlc_buffer_t *rfbuf;
|
3419
|
+
VALUE buffer;
|
3420
|
+
|
3421
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3422
|
+
|
3423
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3424
|
+
|
3425
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3426
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3427
|
+
buffer = Qnil;
|
3428
|
+
}
|
3429
|
+
if (buffer == Qnil)
|
3430
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3431
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3432
|
+
|
3433
|
+
pdlc_buffer_asinh(mfbuf, rfbuf);
|
3434
|
+
|
3435
|
+
return buffer;
|
3436
|
+
}
|
3437
|
+
|
3438
|
+
|
3439
|
+
/* Computes the inverse hyperbolic sine of values of +self+.
|
3440
|
+
* @return [self]
|
3441
|
+
*/
|
3442
|
+
static VALUE paddlec_float_buffer_asinh_inplace(VALUE self)
|
3443
|
+
{
|
3444
|
+
pdlc_buffer_t *mfbuf;
|
3445
|
+
|
3446
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3447
|
+
|
3448
|
+
pdlc_buffer_asinh_inplace(mfbuf);
|
3449
|
+
|
3450
|
+
return self;
|
3451
|
+
}
|
3452
|
+
|
3453
|
+
|
3454
|
+
/* Computes the arc tangent of values of +self+.
|
3455
|
+
* @overload atan(buffer = nil)
|
3456
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3457
|
+
* @return [PaddleC::FloatBuffer]
|
3458
|
+
*/
|
3459
|
+
static VALUE paddlec_float_buffer_atan(int argc, VALUE *argv, VALUE self)
|
3460
|
+
{
|
3461
|
+
const pdlc_buffer_t *mfbuf;
|
3462
|
+
pdlc_buffer_t *rfbuf;
|
3463
|
+
VALUE buffer;
|
3464
|
+
|
3465
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3466
|
+
|
3467
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3468
|
+
|
3469
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3470
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3471
|
+
buffer = Qnil;
|
3472
|
+
}
|
3473
|
+
if (buffer == Qnil)
|
3474
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3475
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3476
|
+
|
3477
|
+
pdlc_buffer_atan(mfbuf, rfbuf);
|
3478
|
+
|
3479
|
+
return buffer;
|
3480
|
+
}
|
3481
|
+
|
3482
|
+
|
3483
|
+
/* Computes the arc tangent of values of +self+.
|
3484
|
+
* @return [self]
|
3485
|
+
*/
|
3486
|
+
static VALUE paddlec_float_buffer_atan_inplace(VALUE self)
|
3487
|
+
{
|
3488
|
+
pdlc_buffer_t *mfbuf;
|
3489
|
+
|
3490
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3491
|
+
|
3492
|
+
pdlc_buffer_atan_inplace(mfbuf);
|
3493
|
+
|
3494
|
+
return self;
|
3495
|
+
}
|
3496
|
+
|
3497
|
+
|
3498
|
+
/* Computes the inverse hyperbolic tangent of values of +self+.
|
3499
|
+
* @overload atanh(buffer = nil)
|
3500
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3501
|
+
* @return [PaddleC::FloatBuffer]
|
3502
|
+
*/
|
3503
|
+
static VALUE paddlec_float_buffer_atanh(int argc, VALUE *argv, VALUE self)
|
3504
|
+
{
|
3505
|
+
const pdlc_buffer_t *mfbuf;
|
3506
|
+
pdlc_buffer_t *rfbuf;
|
3507
|
+
VALUE buffer;
|
3508
|
+
|
3509
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3510
|
+
|
3511
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3512
|
+
|
3513
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3514
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3515
|
+
buffer = Qnil;
|
3516
|
+
}
|
3517
|
+
if (buffer == Qnil)
|
3518
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3519
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3520
|
+
|
3521
|
+
pdlc_buffer_atanh(mfbuf, rfbuf);
|
3522
|
+
|
3523
|
+
return buffer;
|
3524
|
+
}
|
3525
|
+
|
3526
|
+
|
3527
|
+
/* Computes the inverse hyperbolic tangent of values of +self+.
|
3528
|
+
* @return [self]
|
3529
|
+
*/
|
3530
|
+
static VALUE paddlec_float_buffer_atanh_inplace(VALUE self)
|
3531
|
+
{
|
3532
|
+
pdlc_buffer_t *mfbuf;
|
3533
|
+
|
3534
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3535
|
+
|
3536
|
+
pdlc_buffer_atanh_inplace(mfbuf);
|
3537
|
+
|
3538
|
+
return self;
|
3539
|
+
}
|
3540
|
+
|
3541
|
+
|
3542
|
+
/* Returns the cube root of values of +self+.
|
3543
|
+
* @overload cbrt(buffer = nil)
|
3544
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3545
|
+
* @return [PaddleC::FloatBuffer]
|
3546
|
+
*/
|
3547
|
+
static VALUE paddlec_float_buffer_cbrt(int argc, VALUE *argv, VALUE self)
|
3548
|
+
{
|
3549
|
+
const pdlc_buffer_t *mfbuf;
|
3550
|
+
pdlc_buffer_t *rfbuf;
|
3551
|
+
VALUE buffer;
|
3552
|
+
|
3553
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3554
|
+
|
3555
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3556
|
+
|
3557
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3558
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3559
|
+
buffer = Qnil;
|
3560
|
+
}
|
3561
|
+
if (buffer == Qnil)
|
3562
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3563
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3564
|
+
|
3565
|
+
pdlc_buffer_cbrt(mfbuf, rfbuf);
|
3566
|
+
|
3567
|
+
return buffer;
|
3568
|
+
}
|
3569
|
+
|
3570
|
+
|
3571
|
+
/* Returns the cube root of values of +self+.
|
3572
|
+
* @return [self]
|
3573
|
+
*/
|
3574
|
+
static VALUE paddlec_float_buffer_cbrt_inplace(VALUE self)
|
3575
|
+
{
|
3576
|
+
pdlc_buffer_t *mfbuf;
|
3577
|
+
|
3578
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3579
|
+
|
3580
|
+
pdlc_buffer_cbrt_inplace(mfbuf);
|
3581
|
+
|
3582
|
+
return self;
|
3583
|
+
}
|
3584
|
+
|
3585
|
+
|
3586
|
+
/* Computes the cosine of values of +self+ (expressed in radians). Returns a Float in the range -1.0..1.0.
|
3587
|
+
* @overload cos(buffer = nil)
|
3588
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3589
|
+
* @return [PaddleC::FloatBuffer]
|
3590
|
+
*/
|
3591
|
+
static VALUE paddlec_float_buffer_cos(int argc, VALUE *argv, VALUE self)
|
3592
|
+
{
|
3593
|
+
const pdlc_buffer_t *mfbuf;
|
3594
|
+
pdlc_buffer_t *rfbuf;
|
3595
|
+
VALUE buffer;
|
3596
|
+
|
3597
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3598
|
+
|
3599
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3600
|
+
|
3601
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3602
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3603
|
+
buffer = Qnil;
|
3604
|
+
}
|
3605
|
+
if (buffer == Qnil)
|
3606
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3607
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3608
|
+
|
3609
|
+
pdlc_buffer_cos(mfbuf, rfbuf);
|
3610
|
+
|
3611
|
+
return buffer;
|
3612
|
+
}
|
3613
|
+
|
3614
|
+
|
3615
|
+
/* Computes the cosine of values of +self+ (expressed in radians). Returns a Float in the range -1.0..1.0.
|
3616
|
+
* @return [self]
|
3617
|
+
*/
|
3618
|
+
static VALUE paddlec_float_buffer_cos_inplace(VALUE self)
|
3619
|
+
{
|
3620
|
+
pdlc_buffer_t *mfbuf;
|
3621
|
+
|
3622
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3623
|
+
|
3624
|
+
pdlc_buffer_cos_inplace(mfbuf);
|
3625
|
+
|
3626
|
+
return self;
|
3627
|
+
}
|
3628
|
+
|
3629
|
+
|
3630
|
+
/* Computes the hyperbolic cosine of values of +self+.
|
3631
|
+
* @overload cosh(buffer = nil)
|
3632
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3633
|
+
* @return [PaddleC::FloatBuffer]
|
3634
|
+
*/
|
3635
|
+
static VALUE paddlec_float_buffer_cosh(int argc, VALUE *argv, VALUE self)
|
3636
|
+
{
|
3637
|
+
const pdlc_buffer_t *mfbuf;
|
3638
|
+
pdlc_buffer_t *rfbuf;
|
3639
|
+
VALUE buffer;
|
3640
|
+
|
3641
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3642
|
+
|
3643
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3644
|
+
|
3645
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3646
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3647
|
+
buffer = Qnil;
|
3648
|
+
}
|
3649
|
+
if (buffer == Qnil)
|
3650
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3651
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3652
|
+
|
3653
|
+
pdlc_buffer_cosh(mfbuf, rfbuf);
|
3654
|
+
|
3655
|
+
return buffer;
|
3656
|
+
}
|
3657
|
+
|
3658
|
+
|
3659
|
+
/* Computes the hyperbolic cosine of values of +self+.
|
3660
|
+
* @return [self]
|
3661
|
+
*/
|
3662
|
+
static VALUE paddlec_float_buffer_cosh_inplace(VALUE self)
|
3663
|
+
{
|
3664
|
+
pdlc_buffer_t *mfbuf;
|
3665
|
+
|
3666
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3667
|
+
|
3668
|
+
pdlc_buffer_cosh_inplace(mfbuf);
|
3669
|
+
|
3670
|
+
return self;
|
3671
|
+
}
|
3672
|
+
|
3673
|
+
|
3674
|
+
/* Calculates the error function of values of +self+.
|
3675
|
+
* @overload erf(buffer = nil)
|
3676
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3677
|
+
* @return [PaddleC::FloatBuffer]
|
3678
|
+
*/
|
3679
|
+
static VALUE paddlec_float_buffer_erf(int argc, VALUE *argv, VALUE self)
|
3680
|
+
{
|
3681
|
+
const pdlc_buffer_t *mfbuf;
|
3682
|
+
pdlc_buffer_t *rfbuf;
|
3683
|
+
VALUE buffer;
|
3684
|
+
|
3685
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3686
|
+
|
3687
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3688
|
+
|
3689
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3690
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3691
|
+
buffer = Qnil;
|
3692
|
+
}
|
3693
|
+
if (buffer == Qnil)
|
3694
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3695
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3696
|
+
|
3697
|
+
pdlc_buffer_erf(mfbuf, rfbuf);
|
3698
|
+
|
3699
|
+
return buffer;
|
3700
|
+
}
|
3701
|
+
|
3702
|
+
|
3703
|
+
/* Calculates the error function of values of +self+.
|
3704
|
+
* @return [self]
|
3705
|
+
*/
|
3706
|
+
static VALUE paddlec_float_buffer_erf_inplace(VALUE self)
|
3707
|
+
{
|
3708
|
+
pdlc_buffer_t *mfbuf;
|
3709
|
+
|
3710
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3711
|
+
|
3712
|
+
pdlc_buffer_erf_inplace(mfbuf);
|
3713
|
+
|
3714
|
+
return self;
|
3715
|
+
}
|
3716
|
+
|
3717
|
+
|
3718
|
+
/* Calculates the complementary error function of values of +self+.
|
3719
|
+
* @overload erfc(buffer = nil)
|
3720
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3721
|
+
* @return [PaddleC::FloatBuffer]
|
3722
|
+
*/
|
3723
|
+
static VALUE paddlec_float_buffer_erfc(int argc, VALUE *argv, VALUE self)
|
3724
|
+
{
|
3725
|
+
const pdlc_buffer_t *mfbuf;
|
3726
|
+
pdlc_buffer_t *rfbuf;
|
3727
|
+
VALUE buffer;
|
3728
|
+
|
3729
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3730
|
+
|
3731
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3732
|
+
|
3733
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3734
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3735
|
+
buffer = Qnil;
|
3736
|
+
}
|
3737
|
+
if (buffer == Qnil)
|
3738
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3739
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3740
|
+
|
3741
|
+
pdlc_buffer_erfc(mfbuf, rfbuf);
|
3742
|
+
|
3743
|
+
return buffer;
|
3744
|
+
}
|
3745
|
+
|
3746
|
+
|
3747
|
+
/* Calculates the complementary error function of values of +self+.
|
3748
|
+
* @return [self]
|
3749
|
+
*/
|
3750
|
+
static VALUE paddlec_float_buffer_erfc_inplace(VALUE self)
|
3751
|
+
{
|
3752
|
+
pdlc_buffer_t *mfbuf;
|
3753
|
+
|
3754
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3755
|
+
|
3756
|
+
pdlc_buffer_erfc_inplace(mfbuf);
|
3757
|
+
|
3758
|
+
return self;
|
3759
|
+
}
|
3760
|
+
|
3761
|
+
|
3762
|
+
/* Calculates the value of e (the base of natural logarithms) raised to the power of values of +self+.
|
3763
|
+
* @overload exp(buffer = nil)
|
3764
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3765
|
+
* @return [PaddleC::FloatBuffer]
|
3766
|
+
*/
|
3767
|
+
static VALUE paddlec_float_buffer_exp(int argc, VALUE *argv, VALUE self)
|
3768
|
+
{
|
3769
|
+
const pdlc_buffer_t *mfbuf;
|
3770
|
+
pdlc_buffer_t *rfbuf;
|
3771
|
+
VALUE buffer;
|
3772
|
+
|
3773
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3774
|
+
|
3775
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3776
|
+
|
3777
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3778
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3779
|
+
buffer = Qnil;
|
3780
|
+
}
|
3781
|
+
if (buffer == Qnil)
|
3782
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3783
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3784
|
+
|
3785
|
+
pdlc_buffer_exp(mfbuf, rfbuf);
|
3786
|
+
|
3787
|
+
return buffer;
|
3788
|
+
}
|
3789
|
+
|
3790
|
+
|
3791
|
+
/* Calculates the value of e (the base of natural logarithms) raised to the power of values of +self+.
|
3792
|
+
* @return [self]
|
3793
|
+
*/
|
3794
|
+
static VALUE paddlec_float_buffer_exp_inplace(VALUE self)
|
3795
|
+
{
|
3796
|
+
pdlc_buffer_t *mfbuf;
|
3797
|
+
|
3798
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3799
|
+
|
3800
|
+
pdlc_buffer_exp_inplace(mfbuf);
|
3801
|
+
|
3802
|
+
return self;
|
3803
|
+
}
|
3804
|
+
|
3805
|
+
|
3806
|
+
/* Calculates the natural logarithm of values of +self+.
|
3807
|
+
* @overload log(buffer = nil)
|
3808
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3809
|
+
* @return [PaddleC::FloatBuffer]
|
3810
|
+
*/
|
3811
|
+
static VALUE paddlec_float_buffer_log(int argc, VALUE *argv, VALUE self)
|
3812
|
+
{
|
3813
|
+
const pdlc_buffer_t *mfbuf;
|
3814
|
+
pdlc_buffer_t *rfbuf;
|
3815
|
+
VALUE buffer;
|
3816
|
+
|
3817
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3818
|
+
|
3819
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3820
|
+
|
3821
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3822
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3823
|
+
buffer = Qnil;
|
3824
|
+
}
|
3825
|
+
if (buffer == Qnil)
|
3826
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3827
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3828
|
+
|
3829
|
+
pdlc_buffer_log(mfbuf, rfbuf);
|
3830
|
+
|
3831
|
+
return buffer;
|
3832
|
+
}
|
3833
|
+
|
3834
|
+
|
3835
|
+
/* Calculates the natural logarithm of values of +self+.
|
3836
|
+
* @return [self]
|
3837
|
+
*/
|
3838
|
+
static VALUE paddlec_float_buffer_log_inplace(VALUE self)
|
3839
|
+
{
|
3840
|
+
pdlc_buffer_t *mfbuf;
|
3841
|
+
|
3842
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3843
|
+
|
3844
|
+
pdlc_buffer_log_inplace(mfbuf);
|
3845
|
+
|
3846
|
+
return self;
|
3847
|
+
}
|
3848
|
+
|
3849
|
+
|
3850
|
+
/* Calculates the base 10 logarithm of values of +self+.
|
3851
|
+
* @overload log10(buffer = nil)
|
3852
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3853
|
+
* @return [PaddleC::FloatBuffer]
|
3854
|
+
*/
|
3855
|
+
static VALUE paddlec_float_buffer_log10(int argc, VALUE *argv, VALUE self)
|
3856
|
+
{
|
3857
|
+
const pdlc_buffer_t *mfbuf;
|
3858
|
+
pdlc_buffer_t *rfbuf;
|
3859
|
+
VALUE buffer;
|
3860
|
+
|
3861
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3862
|
+
|
3863
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3864
|
+
|
3865
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3866
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3867
|
+
buffer = Qnil;
|
3868
|
+
}
|
3869
|
+
if (buffer == Qnil)
|
3870
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3871
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3872
|
+
|
3873
|
+
pdlc_buffer_log10(mfbuf, rfbuf);
|
3874
|
+
|
3875
|
+
return buffer;
|
3876
|
+
}
|
3877
|
+
|
3878
|
+
|
3879
|
+
/* Calculates the base 10 logarithm of values of +self+.
|
3880
|
+
* @return [self]
|
3881
|
+
*/
|
3882
|
+
static VALUE paddlec_float_buffer_log10_inplace(VALUE self)
|
3883
|
+
{
|
3884
|
+
pdlc_buffer_t *mfbuf;
|
3885
|
+
|
3886
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3887
|
+
|
3888
|
+
pdlc_buffer_log10_inplace(mfbuf);
|
3889
|
+
|
3890
|
+
return self;
|
3891
|
+
}
|
3892
|
+
|
3893
|
+
|
3894
|
+
/* Calculate the base 2 logarithm of values of +self+.
|
3895
|
+
* @overload log2(buffer = nil)
|
3896
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3897
|
+
* @return [PaddleC::FloatBuffer]
|
3898
|
+
*/
|
3899
|
+
static VALUE paddlec_float_buffer_log2(int argc, VALUE *argv, VALUE self)
|
3900
|
+
{
|
3901
|
+
const pdlc_buffer_t *mfbuf;
|
3902
|
+
pdlc_buffer_t *rfbuf;
|
3903
|
+
VALUE buffer;
|
3904
|
+
|
3905
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3906
|
+
|
3907
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3908
|
+
|
3909
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3910
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3911
|
+
buffer = Qnil;
|
3912
|
+
}
|
3913
|
+
if (buffer == Qnil)
|
3914
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3915
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3916
|
+
|
3917
|
+
pdlc_buffer_log2(mfbuf, rfbuf);
|
3918
|
+
|
3919
|
+
return buffer;
|
3920
|
+
}
|
3921
|
+
|
3922
|
+
|
3923
|
+
/* Calculate the base 2 logarithm of values of +self+.
|
3924
|
+
* @return [self]
|
3925
|
+
*/
|
3926
|
+
static VALUE paddlec_float_buffer_log2_inplace(VALUE self)
|
3927
|
+
{
|
3928
|
+
pdlc_buffer_t *mfbuf;
|
3929
|
+
|
3930
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3931
|
+
|
3932
|
+
pdlc_buffer_log2_inplace(mfbuf);
|
3933
|
+
|
3934
|
+
return self;
|
3935
|
+
}
|
3936
|
+
|
3937
|
+
|
3938
|
+
/* Computes the sine of values of +self+ (expressed in radians). Returns a Float in the range -1.0..1.0.
|
3939
|
+
* @overload sin(buffer = nil)
|
3940
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3941
|
+
* @return [PaddleC::FloatBuffer]
|
3942
|
+
*/
|
3943
|
+
static VALUE paddlec_float_buffer_sin(int argc, VALUE *argv, VALUE self)
|
3944
|
+
{
|
3945
|
+
const pdlc_buffer_t *mfbuf;
|
3946
|
+
pdlc_buffer_t *rfbuf;
|
3947
|
+
VALUE buffer;
|
3948
|
+
|
3949
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3950
|
+
|
3951
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3952
|
+
|
3953
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3954
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3955
|
+
buffer = Qnil;
|
3956
|
+
}
|
3957
|
+
if (buffer == Qnil)
|
3958
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
3959
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
3960
|
+
|
3961
|
+
pdlc_buffer_sin(mfbuf, rfbuf);
|
3962
|
+
|
3963
|
+
return buffer;
|
3964
|
+
}
|
3965
|
+
|
3966
|
+
|
3967
|
+
/* Computes the sine of values of +self+ (expressed in radians). Returns a Float in the range -1.0..1.0.
|
3968
|
+
* @return [self]
|
3969
|
+
*/
|
3970
|
+
static VALUE paddlec_float_buffer_sin_inplace(VALUE self)
|
3971
|
+
{
|
3972
|
+
pdlc_buffer_t *mfbuf;
|
3973
|
+
|
3974
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3975
|
+
|
3976
|
+
pdlc_buffer_sin_inplace(mfbuf);
|
3977
|
+
|
3978
|
+
return self;
|
3979
|
+
}
|
3980
|
+
|
3981
|
+
|
3982
|
+
/* Computes the hyperbolic sine of values of +self+.
|
3983
|
+
* @overload sinh(buffer = nil)
|
3984
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
3985
|
+
* @return [PaddleC::FloatBuffer]
|
3986
|
+
*/
|
3987
|
+
static VALUE paddlec_float_buffer_sinh(int argc, VALUE *argv, VALUE self)
|
3988
|
+
{
|
3989
|
+
const pdlc_buffer_t *mfbuf;
|
3990
|
+
pdlc_buffer_t *rfbuf;
|
3991
|
+
VALUE buffer;
|
3992
|
+
|
3993
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
3994
|
+
|
3995
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
3996
|
+
|
3997
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
3998
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
3999
|
+
buffer = Qnil;
|
4000
|
+
}
|
4001
|
+
if (buffer == Qnil)
|
4002
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4003
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4004
|
+
|
4005
|
+
pdlc_buffer_sinh(mfbuf, rfbuf);
|
4006
|
+
|
4007
|
+
return buffer;
|
4008
|
+
}
|
4009
|
+
|
4010
|
+
|
4011
|
+
/* Computes the hyperbolic sine of values of +self+.
|
4012
|
+
* @return [self]
|
4013
|
+
*/
|
4014
|
+
static VALUE paddlec_float_buffer_sinh_inplace(VALUE self)
|
4015
|
+
{
|
4016
|
+
pdlc_buffer_t *mfbuf;
|
4017
|
+
|
4018
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4019
|
+
|
4020
|
+
pdlc_buffer_sinh_inplace(mfbuf);
|
4021
|
+
|
4022
|
+
return self;
|
4023
|
+
}
|
4024
|
+
|
4025
|
+
|
4026
|
+
/* Computes the non-negative square root of values of +self+.
|
4027
|
+
* @overload sqrt(buffer = nil)
|
4028
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
4029
|
+
* @return [PaddleC::FloatBuffer]
|
4030
|
+
*/
|
4031
|
+
static VALUE paddlec_float_buffer_sqrt(int argc, VALUE *argv, VALUE self)
|
4032
|
+
{
|
4033
|
+
const pdlc_buffer_t *mfbuf;
|
4034
|
+
pdlc_buffer_t *rfbuf;
|
4035
|
+
VALUE buffer;
|
4036
|
+
|
4037
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4038
|
+
|
4039
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
4040
|
+
|
4041
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4042
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4043
|
+
buffer = Qnil;
|
4044
|
+
}
|
4045
|
+
if (buffer == Qnil)
|
4046
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4047
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4048
|
+
|
4049
|
+
pdlc_buffer_sqrt(mfbuf, rfbuf);
|
4050
|
+
|
4051
|
+
return buffer;
|
4052
|
+
}
|
4053
|
+
|
4054
|
+
|
4055
|
+
/* Computes the non-negative square root of values of +self+.
|
4056
|
+
* @return [self]
|
4057
|
+
*/
|
4058
|
+
static VALUE paddlec_float_buffer_sqrt_inplace(VALUE self)
|
4059
|
+
{
|
4060
|
+
pdlc_buffer_t *mfbuf;
|
4061
|
+
|
4062
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4063
|
+
|
4064
|
+
pdlc_buffer_sqrt_inplace(mfbuf);
|
4065
|
+
|
4066
|
+
return self;
|
4067
|
+
}
|
4068
|
+
|
4069
|
+
|
4070
|
+
/* Computes the tangent of values of +self+ (expressed in radians).
|
4071
|
+
* @overload tan(buffer = nil)
|
4072
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
4073
|
+
* @return [PaddleC::FloatBuffer]
|
4074
|
+
*/
|
4075
|
+
static VALUE paddlec_float_buffer_tan(int argc, VALUE *argv, VALUE self)
|
4076
|
+
{
|
4077
|
+
const pdlc_buffer_t *mfbuf;
|
4078
|
+
pdlc_buffer_t *rfbuf;
|
4079
|
+
VALUE buffer;
|
4080
|
+
|
4081
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4082
|
+
|
4083
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
4084
|
+
|
4085
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4086
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4087
|
+
buffer = Qnil;
|
4088
|
+
}
|
4089
|
+
if (buffer == Qnil)
|
4090
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4091
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4092
|
+
|
4093
|
+
pdlc_buffer_tan(mfbuf, rfbuf);
|
4094
|
+
|
4095
|
+
return buffer;
|
4096
|
+
}
|
4097
|
+
|
4098
|
+
|
4099
|
+
/* Computes the tangent of values of +self+ (expressed in radians).
|
4100
|
+
* @return [self]
|
4101
|
+
*/
|
4102
|
+
static VALUE paddlec_float_buffer_tan_inplace(VALUE self)
|
4103
|
+
{
|
4104
|
+
pdlc_buffer_t *mfbuf;
|
4105
|
+
|
4106
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4107
|
+
|
4108
|
+
pdlc_buffer_tan_inplace(mfbuf);
|
4109
|
+
|
4110
|
+
return self;
|
4111
|
+
}
|
4112
|
+
|
4113
|
+
|
4114
|
+
/* Computes the hyperbolic tangent of values of +self+.
|
4115
|
+
* @overload tanh(buffer = nil)
|
4116
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
4117
|
+
* @return [PaddleC::FloatBuffer]
|
4118
|
+
*/
|
4119
|
+
static VALUE paddlec_float_buffer_tanh(int argc, VALUE *argv, VALUE self)
|
4120
|
+
{
|
4121
|
+
const pdlc_buffer_t *mfbuf;
|
4122
|
+
pdlc_buffer_t *rfbuf;
|
4123
|
+
VALUE buffer;
|
4124
|
+
|
4125
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4126
|
+
|
4127
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
4128
|
+
|
4129
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4130
|
+
rb_warn("expecting a %"PRIsVALUE" as buffer, not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4131
|
+
buffer = Qnil;
|
4132
|
+
}
|
4133
|
+
if (buffer == Qnil)
|
4134
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4135
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4136
|
+
|
4137
|
+
pdlc_buffer_tanh(mfbuf, rfbuf);
|
4138
|
+
|
4139
|
+
return buffer;
|
4140
|
+
}
|
4141
|
+
|
4142
|
+
|
4143
|
+
/* Computes the hyperbolic tangent of values of +self+.
|
4144
|
+
* @return [self]
|
4145
|
+
*/
|
4146
|
+
static VALUE paddlec_float_buffer_tanh_inplace(VALUE self)
|
4147
|
+
{
|
4148
|
+
pdlc_buffer_t *mfbuf;
|
4149
|
+
|
4150
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4151
|
+
|
4152
|
+
pdlc_buffer_tanh_inplace(mfbuf);
|
4153
|
+
|
4154
|
+
return self;
|
4155
|
+
}
|
4156
|
+
|
4157
|
+
|
4158
|
+
/* @!endgroup
|
4159
|
+
*/
|
4160
|
+
|
4161
|
+
|
4162
|
+
/* Return the lesser and greater values of +self+.
|
4163
|
+
* Returns nil if empty.
|
4164
|
+
* @return [Array<Float>, nil] a two element array containint the lesser and greater values from +self+.
|
4165
|
+
*/
|
4166
|
+
static VALUE paddlec_float_buffer_minmax(VALUE self)
|
4167
|
+
{
|
4168
|
+
const pdlc_buffer_t *mfbuf;
|
4169
|
+
float mi, ma;
|
4170
|
+
|
4171
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4172
|
+
|
4173
|
+
if (mfbuf->length < 1)
|
4174
|
+
return Qnil;
|
4175
|
+
|
4176
|
+
pdlc_buffer_minmax_of_self(mfbuf, &mi, &ma);
|
4177
|
+
|
4178
|
+
return rb_assoc_new(DBL2NUM((double)mi), DBL2NUM((double)ma));
|
4179
|
+
}
|
4180
|
+
|
4181
|
+
|
4182
|
+
/* @return [nil, Float, PaddleC::FloatBuffer]
|
4183
|
+
* Without any parameter, returns the lesser value stored in +self+ (or +nil+ if empty).
|
4184
|
+
* If a {PaddleC::FloatBuffer} or a Float is provided as +other+,
|
4185
|
+
* returns a new buffer for which each element is the lesser value of the corresponding element of +self+ and +other+.
|
4186
|
+
* @overload min()
|
4187
|
+
* @return [Float, nil]
|
4188
|
+
* @overload min(other, buffer = nil)
|
4189
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
4190
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
4191
|
+
* @return [PaddleC::FloatBuffer]
|
4192
|
+
*/
|
4193
|
+
static VALUE paddlec_float_buffer_min(int argc, VALUE *argv, VALUE self)
|
4194
|
+
{
|
4195
|
+
const pdlc_buffer_t *mfbuf;
|
4196
|
+
pdlc_buffer_t *rfbuf;
|
4197
|
+
const pdlc_buffer_t *ofbuf;
|
4198
|
+
float of;
|
4199
|
+
VALUE other, buffer;
|
4200
|
+
|
4201
|
+
rb_scan_args(argc, argv, "02", &other, &buffer);
|
4202
|
+
|
4203
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4204
|
+
|
4205
|
+
if (other == Qnil) {
|
4206
|
+
if (mfbuf->length < 1)
|
4207
|
+
buffer = Qnil;
|
4208
|
+
else {
|
4209
|
+
of = pdlc_buffer_min_of_self(mfbuf);
|
4210
|
+
buffer = DBL2NUM((double)of);
|
4211
|
+
}
|
4212
|
+
}
|
4213
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
4214
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4215
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4216
|
+
buffer = Qnil;
|
4217
|
+
}
|
4218
|
+
if (buffer == Qnil)
|
4219
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4220
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4221
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
4222
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
4223
|
+
pdlc_fb_fb_min(mfbuf, ofbuf, rfbuf);
|
4224
|
+
}
|
4225
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
4226
|
+
of = (float)NUM2DBL(other);
|
4227
|
+
pdlc_fb_fs_min(mfbuf, of, rfbuf);
|
4228
|
+
}
|
4229
|
+
}
|
4230
|
+
else
|
4231
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
4232
|
+
|
4233
|
+
return buffer;
|
4234
|
+
}
|
4235
|
+
|
4236
|
+
|
4237
|
+
/* @param other [c_FloatBuffer, rb_cNumeric]
|
4238
|
+
* @return [self]
|
4239
|
+
*/
|
4240
|
+
static VALUE paddlec_float_buffer_min_inplace(VALUE self, VALUE other)
|
4241
|
+
{
|
4242
|
+
pdlc_buffer_t *mfbuf;
|
4243
|
+
const pdlc_buffer_t *ofbuf;
|
4244
|
+
float of;
|
4245
|
+
|
4246
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4247
|
+
|
4248
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
4249
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
4250
|
+
pdlc_fb_fb_min_inplace(mfbuf, ofbuf);
|
4251
|
+
}
|
4252
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
4253
|
+
of = (float)NUM2DBL(other);
|
4254
|
+
pdlc_fb_fs_min_inplace(mfbuf, of);
|
4255
|
+
}
|
4256
|
+
else
|
4257
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
4258
|
+
|
4259
|
+
return self;
|
4260
|
+
}
|
4261
|
+
|
4262
|
+
|
4263
|
+
/* @return [nil, Float, PaddleC::FloatBuffer]
|
4264
|
+
* Without any parameter, returns the greater value stored in +self+ (or +nil+ is empty).
|
4265
|
+
* If a {PaddleC::FloatBuffer} or a Float is provided as +other+,
|
4266
|
+
* returns a new buffer for which each element is the greater value of the corresponding element of +self+ and +other+.
|
4267
|
+
* @overload max()
|
4268
|
+
* @return [Float, nil]
|
4269
|
+
* @overload max(other, buffer = nil)
|
4270
|
+
* @param other [PaddleC::FloatBuffer, Numeric]
|
4271
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if a {FloatBuffer} is provided, it is filled with the output
|
4272
|
+
* @return [PaddleC::FloatBuffer]
|
4273
|
+
*/
|
4274
|
+
static VALUE paddlec_float_buffer_max(int argc, VALUE *argv, VALUE self)
|
4275
|
+
{
|
4276
|
+
const pdlc_buffer_t *mfbuf;
|
4277
|
+
pdlc_buffer_t *rfbuf;
|
4278
|
+
const pdlc_buffer_t *ofbuf;
|
4279
|
+
float of;
|
4280
|
+
VALUE other, buffer;
|
4281
|
+
|
4282
|
+
rb_scan_args(argc, argv, "02", &other, &buffer);
|
4283
|
+
|
4284
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4285
|
+
|
4286
|
+
if (other == Qnil) {
|
4287
|
+
if (mfbuf->length < 1)
|
4288
|
+
buffer = Qnil;
|
4289
|
+
else {
|
4290
|
+
of = pdlc_buffer_max_of_self(mfbuf);
|
4291
|
+
buffer = DBL2NUM((double)of);
|
4292
|
+
}
|
4293
|
+
}
|
4294
|
+
else if (rb_obj_is_kind_of(other, c_FloatBuffer) || rb_obj_is_kind_of(other, rb_cNumeric)) {
|
4295
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4296
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4297
|
+
buffer = Qnil;
|
4298
|
+
}
|
4299
|
+
if (buffer == Qnil)
|
4300
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4301
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4302
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
4303
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
4304
|
+
pdlc_fb_fb_max(mfbuf, ofbuf, rfbuf);
|
4305
|
+
}
|
4306
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
4307
|
+
of = (float)NUM2DBL(other);
|
4308
|
+
pdlc_fb_fs_max(mfbuf, of, rfbuf);
|
4309
|
+
}
|
4310
|
+
}
|
4311
|
+
else
|
4312
|
+
rb_raise(rb_eTypeError, "First argument is expected to be a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
4313
|
+
|
4314
|
+
return buffer;
|
4315
|
+
}
|
4316
|
+
|
4317
|
+
|
4318
|
+
/* @param other [c_FloatBuffer, rb_cNumeric]
|
4319
|
+
* @return [self]
|
4320
|
+
*/
|
4321
|
+
static VALUE paddlec_float_buffer_max_inplace(VALUE self, VALUE other)
|
4322
|
+
{
|
4323
|
+
pdlc_buffer_t *mfbuf;
|
4324
|
+
const pdlc_buffer_t *ofbuf;
|
4325
|
+
float of;
|
4326
|
+
|
4327
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4328
|
+
|
4329
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
4330
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
4331
|
+
pdlc_fb_fb_max_inplace(mfbuf, ofbuf);
|
4332
|
+
}
|
4333
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric)) {
|
4334
|
+
of = (float)NUM2DBL(other);
|
4335
|
+
pdlc_fb_fs_max_inplace(mfbuf, of);
|
4336
|
+
}
|
4337
|
+
else
|
4338
|
+
rb_raise(rb_eTypeError, "expecting a %"PRIsVALUE" or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_cNumeric), rb_class_name(rb_class_of(other)));
|
4339
|
+
|
4340
|
+
return self;
|
4341
|
+
}
|
4342
|
+
|
4343
|
+
|
4344
|
+
/* Clipp the signal so that the output has no values greater than +max+ nor lesser than +min+.
|
4345
|
+
* @overload clipp(max = 1.0, min = -max, buffer = nil)
|
4346
|
+
* @param max [Float] the maximum value allowed
|
4347
|
+
* @param min [Float] the minimum value allowed
|
4348
|
+
* @param buffer [nil, PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
4349
|
+
* @return [PaddleC::FloatBuffer]
|
4350
|
+
*/
|
4351
|
+
static VALUE paddlec_float_buffer_clipp(int argc, VALUE *argv, VALUE self)
|
4352
|
+
{
|
4353
|
+
const pdlc_buffer_t *mfbuf;
|
4354
|
+
pdlc_buffer_t *rfbuf;
|
4355
|
+
float mi, ma;
|
4356
|
+
VALUE buffer, rbmin, rbmax;
|
4357
|
+
|
4358
|
+
rb_scan_args(argc, argv, "3", &rbmax, &rbmin, &buffer);
|
4359
|
+
|
4360
|
+
if (rbmax == Qnil)
|
4361
|
+
ma = 1.0f;
|
4362
|
+
else
|
4363
|
+
ma = (float)NUM2DBL(rbmax);
|
4364
|
+
|
4365
|
+
if (rbmin == Qnil)
|
4366
|
+
mi = -ma;
|
4367
|
+
else
|
4368
|
+
mi = (float)NUM2DBL(rbmin);
|
4369
|
+
|
4370
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4371
|
+
rb_warn("second argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4372
|
+
buffer = Qnil;
|
4373
|
+
}
|
4374
|
+
|
4375
|
+
if (buffer == Qnil)
|
4376
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4377
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4378
|
+
|
4379
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4380
|
+
|
4381
|
+
pdlc_buffer_clipp(mfbuf, mi, ma, rfbuf);
|
4382
|
+
|
4383
|
+
return buffer;
|
4384
|
+
}
|
4385
|
+
|
4386
|
+
|
4387
|
+
/* Clipp the signal so that the output has no values greater than +max+ nor lesser than +min+.
|
4388
|
+
* @overload clipp!(max = 1.0, min = -max)
|
4389
|
+
* @param max [Float] the maximum value allowed
|
4390
|
+
* @param min [Float] the minimum value allowed
|
4391
|
+
* @return [self]
|
4392
|
+
*/
|
4393
|
+
static VALUE paddlec_float_buffer_clipp_inplace(int argc, VALUE *argv, VALUE self)
|
4394
|
+
{
|
4395
|
+
pdlc_buffer_t *mfbuf;
|
4396
|
+
float mi, ma;
|
4397
|
+
VALUE rbmin, rbmax;
|
4398
|
+
|
4399
|
+
rb_scan_args(argc, argv, "2", &rbmax, &rbmin);
|
4400
|
+
|
4401
|
+
if (rbmax == Qnil)
|
4402
|
+
ma = 1.0f;
|
4403
|
+
else
|
4404
|
+
ma = (float)NUM2DBL(rbmax);
|
4405
|
+
|
4406
|
+
if (rbmin == Qnil)
|
4407
|
+
mi = -ma;
|
4408
|
+
else
|
4409
|
+
mi = (float)NUM2DBL(rbmin);
|
4410
|
+
|
4411
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4412
|
+
|
4413
|
+
pdlc_buffer_clipp_inplace(mfbuf, mi, ma);
|
4414
|
+
|
4415
|
+
return self;
|
4416
|
+
}
|
4417
|
+
|
4418
|
+
|
4419
|
+
/* Returns a new {PaddleC::FloatBuffer} containing +self+'s elements in reverse order.
|
4420
|
+
* @overload reverse(buffer = nil)
|
4421
|
+
* @param buffer [PaddleC::FloatBuffer] if provided, the result is written into +buffer+.
|
4422
|
+
* @return [PaddleC::FloatBuffer]
|
4423
|
+
*/
|
4424
|
+
static VALUE paddlec_float_buffer_reverse(int argc, VALUE *argv, VALUE self)
|
4425
|
+
{
|
4426
|
+
const pdlc_buffer_t *mfbuf;
|
4427
|
+
pdlc_buffer_t *rfbuf;
|
4428
|
+
VALUE buffer;
|
4429
|
+
|
4430
|
+
rb_scan_args(argc, argv, "01", &buffer);
|
4431
|
+
|
4432
|
+
if (buffer != Qnil && !rb_obj_is_kind_of(buffer, c_FloatBuffer)) {
|
4433
|
+
rb_warn("argument (buffer) is expected to be a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(buffer)));
|
4434
|
+
buffer = Qnil;
|
4435
|
+
}
|
4436
|
+
|
4437
|
+
if (buffer == Qnil)
|
4438
|
+
buffer = rb_class_new_instance(0, NULL, c_FloatBuffer);
|
4439
|
+
rfbuf = paddlec_float_buffer_get_struct(buffer);
|
4440
|
+
|
4441
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4442
|
+
|
4443
|
+
pdlc_buffer_reverse(mfbuf, rfbuf);
|
4444
|
+
|
4445
|
+
return buffer;
|
4446
|
+
}
|
4447
|
+
|
4448
|
+
|
4449
|
+
/* Reverse +self+ in place.
|
4450
|
+
* @return [self]
|
4451
|
+
*/
|
4452
|
+
static VALUE paddlec_float_buffer_reverse_inplace(VALUE self)
|
4453
|
+
{
|
4454
|
+
pdlc_buffer_t *mfbuf;
|
4455
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4456
|
+
pdlc_buffer_reverse_inplace(mfbuf);
|
4457
|
+
return self;
|
4458
|
+
}
|
4459
|
+
|
4460
|
+
|
4461
|
+
/* Returns the sum of all values in +self+, or +nil+ if empty.
|
4462
|
+
* @return [Float, nil]
|
4463
|
+
*/
|
4464
|
+
static VALUE paddlec_float_buffer_sum(VALUE self)
|
4465
|
+
{
|
4466
|
+
const pdlc_buffer_t *mfbuf;
|
4467
|
+
float res;
|
4468
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4469
|
+
if (mfbuf->length < 1)
|
4470
|
+
return Qnil;
|
4471
|
+
res = pdlc_buffer_sum(mfbuf);
|
4472
|
+
return DBL2NUM((double)res);
|
4473
|
+
}
|
4474
|
+
|
4475
|
+
|
4476
|
+
/* Returns the mean of all values in +self+, or +nil+ if empty.
|
4477
|
+
* @return [Float, nil]
|
4478
|
+
*/
|
4479
|
+
static VALUE paddlec_float_buffer_mean(VALUE self)
|
4480
|
+
{
|
4481
|
+
const pdlc_buffer_t *mfbuf;
|
4482
|
+
float res;
|
4483
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4484
|
+
if (mfbuf->length < 1)
|
4485
|
+
return Qnil;
|
4486
|
+
res = pdlc_buffer_mean(mfbuf);
|
4487
|
+
return DBL2NUM((double)res);
|
4488
|
+
}
|
4489
|
+
|
4490
|
+
|
4491
|
+
/* Returns the variance of all values in +self+, or +nil+ if empty.
|
4492
|
+
* 𝛔² = V(X) = E[(X - E(X))²] = E(X²) - (E(X))²
|
4493
|
+
* The variance is the square of the standard deviation.
|
4494
|
+
* @see PaddleC::FloatBuffer#standard_deviation
|
4495
|
+
* @return [Float, nil]
|
4496
|
+
*/
|
4497
|
+
static VALUE paddlec_float_buffer_variance(VALUE self)
|
4498
|
+
{
|
4499
|
+
const pdlc_buffer_t *mfbuf;
|
4500
|
+
float res;
|
4501
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4502
|
+
if (mfbuf->length < 1)
|
4503
|
+
return Qnil;
|
4504
|
+
res = pdlc_buffer_variance(mfbuf);
|
4505
|
+
return DBL2NUM((double)res);
|
4506
|
+
}
|
4507
|
+
|
4508
|
+
|
4509
|
+
/* Returns the standard deviation 𝛔 of all values in +self+, or +nil+ if empty.
|
4510
|
+
* 𝛔² = V(X) = E[(X - E(X))²] = E(X²) - (E(X))²
|
4511
|
+
* The standard deviation is the square root of the variance.
|
4512
|
+
* @see PaddleC::FloatBuffer#variance
|
4513
|
+
* @return [Float, nil]
|
4514
|
+
*/
|
4515
|
+
static VALUE paddlec_float_buffer_standard_deviation(VALUE self)
|
4516
|
+
{
|
4517
|
+
const pdlc_buffer_t *mfbuf;
|
4518
|
+
float res;
|
4519
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4520
|
+
if (mfbuf->length < 1)
|
4521
|
+
return Qnil;
|
4522
|
+
res = pdlc_buffer_standard_deviation(mfbuf);
|
4523
|
+
return DBL2NUM((double)res);
|
4524
|
+
}
|
4525
|
+
|
4526
|
+
|
4527
|
+
/* Returns the product of all values of +self+, or +nil+ if empty.
|
4528
|
+
* @return [Float, nil]
|
4529
|
+
*/
|
4530
|
+
static VALUE paddlec_float_buffer_prod(VALUE self)
|
4531
|
+
{
|
4532
|
+
const pdlc_buffer_t *mfbuf;
|
4533
|
+
float res;
|
4534
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4535
|
+
if (mfbuf->length < 1)
|
4536
|
+
return Qnil;
|
4537
|
+
res = pdlc_buffer_prod(mfbuf);
|
4538
|
+
return DBL2NUM((double)res);
|
4539
|
+
}
|
4540
|
+
|
4541
|
+
|
4542
|
+
/* Returns the sum of absolute differences of values of +self+ with +other+, or +nil+ if empty.
|
4543
|
+
* @return [Float, nil]
|
4544
|
+
* @param other [Float, PaddleC::FloatBuffer]
|
4545
|
+
*/
|
4546
|
+
static VALUE paddlec_float_buffer_sad(VALUE self, VALUE other)
|
4547
|
+
{
|
4548
|
+
const pdlc_buffer_t *mfbuf;
|
4549
|
+
const pdlc_buffer_t *ofbuf;
|
4550
|
+
float of, rf;
|
4551
|
+
|
4552
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4553
|
+
if (mfbuf->length < 1)
|
4554
|
+
return Qnil;
|
4555
|
+
|
4556
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
4557
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
4558
|
+
if (ofbuf->length < 1)
|
4559
|
+
return Qnil;
|
4560
|
+
rf = pdlc_buffer_fb_fb_sad(mfbuf, ofbuf);
|
4561
|
+
}
|
4562
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric) && !rb_obj_is_kind_of(other, rb_cComplex)) {
|
4563
|
+
of = (float)NUM2DBL(other);
|
4564
|
+
rf = pdlc_buffer_fb_fs_sad(mfbuf, of);
|
4565
|
+
}
|
4566
|
+
else
|
4567
|
+
rb_raise(rb_eArgError, "expecting a Float or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(other)));
|
4568
|
+
|
4569
|
+
return DBL2NUM((double)rf);
|
4570
|
+
}
|
4571
|
+
|
4572
|
+
|
4573
|
+
/* Returns the sum of square differences of values of +self+ with +other+, or +nil+ if empty.
|
4574
|
+
* @return [Float, nil]
|
4575
|
+
* @param other [Float, PaddleC::FloatBuffer]
|
4576
|
+
*/
|
4577
|
+
static VALUE paddlec_float_buffer_ssd(VALUE self, VALUE other)
|
4578
|
+
{
|
4579
|
+
const pdlc_buffer_t *mfbuf;
|
4580
|
+
const pdlc_buffer_t *ofbuf;
|
4581
|
+
float of, rf;
|
4582
|
+
|
4583
|
+
mfbuf = paddlec_float_buffer_get_struct(self);
|
4584
|
+
if (mfbuf->length < 1)
|
4585
|
+
return Qnil;
|
4586
|
+
|
4587
|
+
if (rb_obj_is_kind_of(other, c_FloatBuffer)) {
|
4588
|
+
ofbuf = paddlec_float_buffer_get_struct(other);
|
4589
|
+
if (ofbuf->length < 1)
|
4590
|
+
return Qnil;
|
4591
|
+
rf = pdlc_buffer_fb_fb_ssd(mfbuf, ofbuf);
|
4592
|
+
}
|
4593
|
+
else if (rb_obj_is_kind_of(other, rb_cNumeric) && !rb_obj_is_kind_of(other, rb_cComplex)) {
|
4594
|
+
of = (float)NUM2DBL(other);
|
4595
|
+
rf = pdlc_buffer_fb_fs_ssd(mfbuf, of);
|
4596
|
+
}
|
4597
|
+
else
|
4598
|
+
rb_raise(rb_eArgError, "expecting a Float or a %"PRIsVALUE", not a %"PRIsVALUE, rb_class_name(c_FloatBuffer), rb_class_name(rb_class_of(other)));
|
4599
|
+
|
4600
|
+
return DBL2NUM((double)rf);
|
4601
|
+
}
|
4602
|
+
|
4603
|
+
|
4604
|
+
void Init_paddlec_float_buffer()
|
4605
|
+
{
|
4606
|
+
c_FloatBuffer = rb_define_class_under(m_PaddleC, "FloatBuffer", rb_cObject);
|
4607
|
+
rb_define_module_function(c_FloatBuffer, "unpack", paddlec_float_buffer_classunpack, 2);
|
4608
|
+
|
4609
|
+
rb_define_alloc_func(c_FloatBuffer, paddlec_float_buffer_alloc);
|
4610
|
+
rb_include_module(c_FloatBuffer, rb_mEnumerable);
|
4611
|
+
rb_define_method(c_FloatBuffer, "initialize", paddlec_float_buffer_initialize, -1);
|
4612
|
+
rb_define_method(c_FloatBuffer, "to_float_buffer", paddlec_float_buffer_to_float_buffer, 0);
|
4613
|
+
rb_define_method(c_FloatBuffer, "to_complex_buffer", paddlec_float_buffer_to_complex_buffer, 0);
|
4614
|
+
rb_define_method(c_FloatBuffer, "each", paddlec_float_buffer_each, 0);
|
4615
|
+
rb_define_method(c_FloatBuffer, "collect!", paddlec_float_buffer_collect_inp, 0);
|
4616
|
+
rb_define_method(c_FloatBuffer, "length", paddlec_float_buffer_length, 0);
|
4617
|
+
rb_define_method(c_FloatBuffer, "empty?", paddlec_float_buffer_isempty, 0);
|
4618
|
+
rb_define_method(c_FloatBuffer, "to_a", paddlec_float_buffer_to_a, 0);
|
4619
|
+
rb_define_method(c_FloatBuffer, "to_s", paddlec_float_buffer_to_s, 0);
|
4620
|
+
rb_define_method(c_FloatBuffer, "to_gplot", paddlec_float_buffer_to_gplot, 0);
|
4621
|
+
rb_define_method(c_FloatBuffer, "zip", paddlec_float_buffer_zip, -1);
|
4622
|
+
rb_define_method(c_FloatBuffer, "inspect", paddlec_float_buffer_to_s, 0);
|
4623
|
+
rb_define_method(c_FloatBuffer, "clone", paddlec_float_buffer_clone, 0);
|
4624
|
+
rb_define_method(c_FloatBuffer, "[]", paddlec_float_buffer_get, -1);
|
4625
|
+
rb_define_method(c_FloatBuffer, "slice", paddlec_float_buffer_get, -1);
|
4626
|
+
rb_define_method(c_FloatBuffer, "[]=", paddlec_float_buffer_set, -1);
|
4627
|
+
rb_define_method(c_FloatBuffer, "pack", paddlec_float_buffer_pack, -1);
|
4628
|
+
rb_define_method(c_FloatBuffer, "unpack", paddlec_float_buffer_unpack, 2);
|
4629
|
+
rb_define_method(c_FloatBuffer, "resize", paddlec_float_buffer_resize, 1);
|
4630
|
+
rb_define_method(c_FloatBuffer, "pointer", paddlec_float_buffer_native_ptr, 0);
|
4631
|
+
rb_define_method(c_FloatBuffer, "coerce", paddlec_float_buffer_coerce, 1);
|
4632
|
+
if (c_FFI_Pointer != Qundef)
|
4633
|
+
rb_define_method(c_FloatBuffer, "to_ptr", paddlec_float_buffer_ffi_pointer, 0);
|
4634
|
+
|
4635
|
+
rb_define_method(rb_cArray, "to_float_buffer", paddlec_array_to_float_buffer, 0);
|
4636
|
+
|
4637
|
+
rb_define_method(c_FloatBuffer, "finite?", paddlec_float_buffer_finite, 0);
|
4638
|
+
rb_define_method(c_FloatBuffer, "infinite?", paddlec_float_buffer_infinite, 0);
|
4639
|
+
rb_define_method(c_FloatBuffer, "nan?", paddlec_float_buffer_nan, 0);
|
4640
|
+
rb_define_method(c_FloatBuffer, "integer?", paddlec_float_buffer_integer, 0);
|
4641
|
+
rb_define_method(c_FloatBuffer, "negative?", paddlec_float_buffer_negative, 0);
|
4642
|
+
rb_define_method(c_FloatBuffer, "positive?", paddlec_float_buffer_positive, 0);
|
4643
|
+
rb_define_method(c_FloatBuffer, "nonzero?", paddlec_float_buffer_nonzero, 0);
|
4644
|
+
rb_define_method(c_FloatBuffer, "zero?", paddlec_float_buffer_zero, 0);
|
4645
|
+
rb_define_method(c_FloatBuffer, "&", paddlec_float_buffer_and, 1);
|
4646
|
+
rb_define_method(c_FloatBuffer, "|", paddlec_float_buffer_or, 1);
|
4647
|
+
rb_define_method(c_FloatBuffer, "^", paddlec_float_buffer_xor, 1);
|
4648
|
+
rb_define_method(c_FloatBuffer, "!", paddlec_float_buffer_not, 0);
|
4649
|
+
rb_define_method(c_FloatBuffer, "<", paddlec_float_buffer_cmpless, 1);
|
4650
|
+
rb_define_method(c_FloatBuffer, "<=", paddlec_float_buffer_cmplessequ, 1);
|
4651
|
+
rb_define_method(c_FloatBuffer, ">", paddlec_float_buffer_cmpgrt, 1);
|
4652
|
+
rb_define_method(c_FloatBuffer, ">=", paddlec_float_buffer_cmpgrtequ, 1);
|
4653
|
+
rb_define_method(c_FloatBuffer, "==", paddlec_float_buffer_equ, 1);
|
4654
|
+
rb_define_method(c_FloatBuffer, "!=", paddlec_float_buffer_different, 1);
|
4655
|
+
rb_define_method(c_FloatBuffer, "ceil", paddlec_float_buffer_ceil, -1);
|
4656
|
+
rb_define_method(c_FloatBuffer, "ceil!", paddlec_float_buffer_ceil_inplace, -1);
|
4657
|
+
rb_define_method(c_FloatBuffer, "floor", paddlec_float_buffer_floor, -1);
|
4658
|
+
rb_define_method(c_FloatBuffer, "floor!", paddlec_float_buffer_floor_inplace, -1);
|
4659
|
+
rb_define_method(c_FloatBuffer, "truncate", paddlec_float_buffer_truncate, -1);
|
4660
|
+
rb_define_method(c_FloatBuffer, "truncate!", paddlec_float_buffer_truncate_inplace, -1);
|
4661
|
+
rb_define_method(c_FloatBuffer, "round", paddlec_float_buffer_round, -1);
|
4662
|
+
rb_define_method(c_FloatBuffer, "round!", paddlec_float_buffer_round_inplace, -1);
|
4663
|
+
rb_define_method(c_FloatBuffer, "abs", paddlec_float_buffer_abs, -1);
|
4664
|
+
rb_define_alias(c_FloatBuffer, "magnitude", "abs");
|
4665
|
+
rb_define_method(c_FloatBuffer, "abs!", paddlec_float_buffer_abs_inplace, 0);
|
4666
|
+
rb_define_method(c_FloatBuffer, "abs2", paddlec_float_buffer_abs2, -1);
|
4667
|
+
rb_define_method(c_FloatBuffer, "square!", paddlec_float_buffer_abs2_inplace, 0);
|
4668
|
+
rb_define_method(c_FloatBuffer, "arg", paddlec_float_buffer_arg, -1);
|
4669
|
+
rb_define_alias(c_FloatBuffer, "angle", "arg");
|
4670
|
+
rb_define_alias(c_FloatBuffer, "phase", "arg");
|
4671
|
+
rb_define_method(c_FloatBuffer, "conjugate", paddlec_float_buffer_conjugate, -1);
|
4672
|
+
rb_define_alias(c_FloatBuffer, "conj", "conjugate");
|
4673
|
+
rb_define_method(c_FloatBuffer, "conjugate!", paddlec_float_buffer_conjugate_inplace, 0);
|
4674
|
+
rb_define_method(c_FloatBuffer, "imaginary", paddlec_float_buffer_imag, -1);
|
4675
|
+
rb_define_alias(c_FloatBuffer, "imag", "imaginary");
|
4676
|
+
rb_define_method(c_FloatBuffer, "real", paddlec_float_buffer_real, -1);
|
4677
|
+
rb_define_method(c_FloatBuffer, "swapIQ", paddlec_float_buffer_swapIQ, -1);
|
4678
|
+
rb_define_alias(c_FloatBuffer, "swapRI", "swapIQ");
|
4679
|
+
rb_define_method(c_FloatBuffer, "+@", paddlec_float_buffer_unaryplus, 0);
|
4680
|
+
rb_define_method(c_FloatBuffer, "-@", paddlec_float_buffer_unaryminus, -1);
|
4681
|
+
rb_define_method(c_FloatBuffer, "negate!", paddlec_float_buffer_unaryminus_inplace, 0);
|
4682
|
+
rb_define_method(c_FloatBuffer, "-", paddlec_float_buffer_sub, -1);
|
4683
|
+
rb_define_alias(c_FloatBuffer, "sub", "-");
|
4684
|
+
rb_define_method(c_FloatBuffer, "sub!", paddlec_float_buffer_sub_inplace, 1);
|
4685
|
+
rb_define_method(c_FloatBuffer, "esub", paddlec_float_buffer_esub, -1);
|
4686
|
+
rb_define_method(c_FloatBuffer, "esub!", paddlec_float_buffer_esub_inplace, 1);
|
4687
|
+
rb_define_method(c_FloatBuffer, "+", paddlec_float_buffer_add, -1);
|
4688
|
+
rb_define_alias(c_FloatBuffer, "add", "+");
|
4689
|
+
rb_define_method(c_FloatBuffer, "add!", paddlec_float_buffer_add_inplace, 1);
|
4690
|
+
rb_define_method(c_FloatBuffer, "eadd", paddlec_float_buffer_eadd, -1);
|
4691
|
+
rb_define_method(c_FloatBuffer, "eadd!", paddlec_float_buffer_eadd_inplace, 1);
|
4692
|
+
rb_define_method(c_FloatBuffer, "*", paddlec_float_buffer_mult, -1);
|
4693
|
+
rb_define_alias(c_FloatBuffer, "mult", "*");
|
4694
|
+
rb_define_method(c_FloatBuffer, "mult!", paddlec_float_buffer_mult_inplace, 1);
|
4695
|
+
rb_define_method(c_FloatBuffer, "emult", paddlec_float_buffer_emult, -1);
|
4696
|
+
rb_define_method(c_FloatBuffer, "emul!", paddlec_float_buffer_emult_inplace, 1);
|
4697
|
+
rb_define_method(c_FloatBuffer, "/", paddlec_float_buffer_div, -1);
|
4698
|
+
rb_define_alias(c_FloatBuffer, "div", "/");
|
4699
|
+
rb_define_method(c_FloatBuffer, "div!", paddlec_float_buffer_div_inplace, 1);
|
4700
|
+
rb_define_method(c_FloatBuffer, "ediv", paddlec_float_buffer_ediv, -1);
|
4701
|
+
rb_define_method(c_FloatBuffer, "ediv!", paddlec_float_buffer_ediv_inplace, 1);
|
4702
|
+
rb_define_method(c_FloatBuffer, "**", paddlec_float_buffer_pow, -1);
|
4703
|
+
rb_define_alias(c_FloatBuffer, "pow", "**");
|
4704
|
+
rb_define_method(c_FloatBuffer, "pow!", paddlec_float_buffer_pow_inplace, 1);
|
4705
|
+
rb_define_method(c_FloatBuffer, "%", paddlec_float_buffer_modulo, -1);
|
4706
|
+
rb_define_alias(c_FloatBuffer, "modulo", "%");
|
4707
|
+
rb_define_method(c_FloatBuffer, "modulo!", paddlec_float_buffer_modulo_inplace, 1);
|
4708
|
+
rb_define_method(c_FloatBuffer, "emod", paddlec_float_buffer_emod, -1);
|
4709
|
+
rb_define_method(c_FloatBuffer, "emod!", paddlec_float_buffer_emod_inplace, 1);
|
4710
|
+
rb_define_method(c_FloatBuffer, "epow", paddlec_float_buffer_epow, -1);
|
4711
|
+
rb_define_method(c_FloatBuffer, "epow!", paddlec_float_buffer_epow_inplace, 1);
|
4712
|
+
rb_define_method(c_FloatBuffer, "acos", paddlec_float_buffer_acos, -1);
|
4713
|
+
rb_define_method(c_FloatBuffer, "acos!", paddlec_float_buffer_acos_inplace, 0);
|
4714
|
+
rb_define_method(c_FloatBuffer, "acosh", paddlec_float_buffer_acosh, -1);
|
4715
|
+
rb_define_method(c_FloatBuffer, "acosh!", paddlec_float_buffer_acosh_inplace, 0);
|
4716
|
+
rb_define_method(c_FloatBuffer, "asin", paddlec_float_buffer_asin, -1);
|
4717
|
+
rb_define_method(c_FloatBuffer, "asin!", paddlec_float_buffer_asin_inplace, 0);
|
4718
|
+
rb_define_method(c_FloatBuffer, "asinh", paddlec_float_buffer_asinh, -1);
|
4719
|
+
rb_define_method(c_FloatBuffer, "asinh!", paddlec_float_buffer_asinh_inplace, 0);
|
4720
|
+
rb_define_method(c_FloatBuffer, "atan", paddlec_float_buffer_atan, -1);
|
4721
|
+
rb_define_method(c_FloatBuffer, "atan!", paddlec_float_buffer_atan_inplace, 0);
|
4722
|
+
rb_define_method(c_FloatBuffer, "atanh", paddlec_float_buffer_atanh, -1);
|
4723
|
+
rb_define_method(c_FloatBuffer, "atanh!", paddlec_float_buffer_atanh_inplace, 0);
|
4724
|
+
rb_define_method(c_FloatBuffer, "cbrt", paddlec_float_buffer_cbrt, -1);
|
4725
|
+
rb_define_method(c_FloatBuffer, "cbrt!", paddlec_float_buffer_cbrt_inplace, 0);
|
4726
|
+
rb_define_method(c_FloatBuffer, "cos", paddlec_float_buffer_cos, -1);
|
4727
|
+
rb_define_method(c_FloatBuffer, "cos!", paddlec_float_buffer_cos_inplace, 0);
|
4728
|
+
rb_define_method(c_FloatBuffer, "cosh", paddlec_float_buffer_cosh, -1);
|
4729
|
+
rb_define_method(c_FloatBuffer, "cosh!", paddlec_float_buffer_cosh_inplace, 0);
|
4730
|
+
rb_define_method(c_FloatBuffer, "erf", paddlec_float_buffer_erf, -1);
|
4731
|
+
rb_define_method(c_FloatBuffer, "erf!", paddlec_float_buffer_erf_inplace, 0);
|
4732
|
+
rb_define_method(c_FloatBuffer, "erfc", paddlec_float_buffer_erfc, -1);
|
4733
|
+
rb_define_method(c_FloatBuffer, "erfc!", paddlec_float_buffer_erfc_inplace, 0);
|
4734
|
+
rb_define_method(c_FloatBuffer, "exp", paddlec_float_buffer_exp, -1);
|
4735
|
+
rb_define_method(c_FloatBuffer, "exp!", paddlec_float_buffer_exp_inplace, 0);
|
4736
|
+
rb_define_method(c_FloatBuffer, "log", paddlec_float_buffer_log, -1);
|
4737
|
+
rb_define_method(c_FloatBuffer, "log!", paddlec_float_buffer_log_inplace, 0);
|
4738
|
+
rb_define_method(c_FloatBuffer, "log10", paddlec_float_buffer_log10, -1);
|
4739
|
+
rb_define_method(c_FloatBuffer, "log10!", paddlec_float_buffer_log10_inplace, 0);
|
4740
|
+
rb_define_method(c_FloatBuffer, "log2", paddlec_float_buffer_log2, -1);
|
4741
|
+
rb_define_method(c_FloatBuffer, "log2!", paddlec_float_buffer_log2_inplace, 0);
|
4742
|
+
rb_define_method(c_FloatBuffer, "sin", paddlec_float_buffer_sin, -1);
|
4743
|
+
rb_define_method(c_FloatBuffer, "sin!", paddlec_float_buffer_sin_inplace, 0);
|
4744
|
+
rb_define_method(c_FloatBuffer, "sinh", paddlec_float_buffer_sinh, -1);
|
4745
|
+
rb_define_method(c_FloatBuffer, "sinh!", paddlec_float_buffer_sinh_inplace, 0);
|
4746
|
+
rb_define_method(c_FloatBuffer, "sqrt", paddlec_float_buffer_sqrt, -1);
|
4747
|
+
rb_define_method(c_FloatBuffer, "sqrt!", paddlec_float_buffer_sqrt_inplace, 0);
|
4748
|
+
rb_define_method(c_FloatBuffer, "tan", paddlec_float_buffer_tan, -1);
|
4749
|
+
rb_define_method(c_FloatBuffer, "tan!", paddlec_float_buffer_tan_inplace, 0);
|
4750
|
+
rb_define_method(c_FloatBuffer, "tanh", paddlec_float_buffer_tanh, -1);
|
4751
|
+
rb_define_method(c_FloatBuffer, "tanh!", paddlec_float_buffer_tanh_inplace, 0);
|
4752
|
+
rb_define_method(c_FloatBuffer, "min", paddlec_float_buffer_min, -1);
|
4753
|
+
rb_define_method(c_FloatBuffer, "min!", paddlec_float_buffer_min_inplace, 1);
|
4754
|
+
rb_define_method(c_FloatBuffer, "max", paddlec_float_buffer_max, -1);
|
4755
|
+
rb_define_method(c_FloatBuffer, "max!", paddlec_float_buffer_max_inplace, 1);
|
4756
|
+
rb_define_method(c_FloatBuffer, "minmax", paddlec_float_buffer_minmax, 0);
|
4757
|
+
rb_define_method(c_FloatBuffer, "clipp", paddlec_float_buffer_clipp, -1);
|
4758
|
+
rb_define_method(c_FloatBuffer, "clipp!", paddlec_float_buffer_clipp_inplace, -1);
|
4759
|
+
rb_define_method(c_FloatBuffer, "reverse", paddlec_float_buffer_reverse, -1);
|
4760
|
+
rb_define_method(c_FloatBuffer, "reverse!", paddlec_float_buffer_reverse_inplace, 0);
|
4761
|
+
rb_define_method(c_FloatBuffer, "sum", paddlec_float_buffer_sum, 0);
|
4762
|
+
rb_define_method(c_FloatBuffer, "mean", paddlec_float_buffer_mean, 0);
|
4763
|
+
rb_define_method(c_FloatBuffer, "variance", paddlec_float_buffer_variance, 0);
|
4764
|
+
rb_define_method(c_FloatBuffer, "standard_deviation",paddlec_float_buffer_standard_deviation, 0);
|
4765
|
+
rb_define_method(c_FloatBuffer, "prod", paddlec_float_buffer_prod, 0);
|
4766
|
+
rb_define_method(c_FloatBuffer, "sad", paddlec_float_buffer_sad, 1);
|
4767
|
+
rb_define_method(c_FloatBuffer, "ssd", paddlec_float_buffer_ssd, 1);
|
4768
|
+
}
|
4769
|
+
|
4770
|
+
|