numo-narray-alt 0.9.5 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +13 -0
- data/ext/numo/narray/SFMT-params19937.h +12 -12
- data/ext/numo/narray/array.c +26 -2
- data/ext/numo/narray/data.c +70 -72
- data/ext/numo/narray/extconf.rb +0 -1
- data/ext/numo/narray/index.c +2 -2
- data/ext/numo/narray/kwargs.c +6 -6
- data/ext/numo/narray/math.c +10 -4
- data/ext/numo/narray/narray.c +80 -52
- data/ext/numo/narray/numo/narray.h +20 -20
- data/ext/numo/narray/numo/ndloop.h +1 -1
- data/ext/numo/narray/numo/template.h +80 -80
- data/ext/numo/narray/numo/types/bit.h +76 -0
- data/ext/numo/narray/numo/types/complex.h +2 -2
- data/ext/numo/narray/numo/types/complex_macro.h +27 -26
- data/ext/numo/narray/numo/types/float_macro.h +18 -17
- data/ext/numo/narray/numo/types/real_accum.h +22 -22
- data/ext/numo/narray/numo/types/robj_macro.h +15 -14
- data/ext/numo/narray/numo/types/xint_macro.h +50 -8
- data/ext/numo/narray/rand.c +7 -0
- data/ext/numo/narray/src/mh/mean.h +102 -0
- data/ext/numo/narray/src/mh/rms.h +102 -0
- data/ext/numo/narray/src/mh/stddev.h +103 -0
- data/ext/numo/narray/src/mh/var.h +102 -0
- data/ext/numo/narray/src/t_bit.c +121 -71
- data/ext/numo/narray/src/t_dcomplex.c +248 -387
- data/ext/numo/narray/src/t_dfloat.c +922 -1068
- data/ext/numo/narray/src/t_int16.c +282 -231
- data/ext/numo/narray/src/t_int32.c +282 -231
- data/ext/numo/narray/src/t_int64.c +281 -230
- data/ext/numo/narray/src/t_int8.c +282 -231
- data/ext/numo/narray/src/t_robject.c +278 -405
- data/ext/numo/narray/src/t_scomplex.c +246 -406
- data/ext/numo/narray/src/t_sfloat.c +916 -1058
- data/ext/numo/narray/src/t_uint16.c +282 -231
- data/ext/numo/narray/src/t_uint32.c +282 -231
- data/ext/numo/narray/src/t_uint64.c +282 -231
- data/ext/numo/narray/src/t_uint8.c +282 -231
- data/ext/numo/narray/struct.c +12 -7
- data/lib/numo/narray/extra.rb +8 -5
- metadata +6 -3
- data/ext/numo/narray/src/t_mean.c +0 -105
data/ext/numo/narray/narray.c
CHANGED
@@ -77,8 +77,6 @@ void Init_nary_math();
|
|
77
77
|
void Init_nary_rand();
|
78
78
|
void Init_nary_array();
|
79
79
|
void Init_nary_struct();
|
80
|
-
// define mean method for integer array
|
81
|
-
void Init_nary_mean();
|
82
80
|
|
83
81
|
const rb_data_type_t na_data_type = {
|
84
82
|
"Numo::NArray",
|
@@ -323,9 +321,9 @@ static void na_setup(VALUE self, int ndim, size_t* shape) {
|
|
323
321
|
/*
|
324
322
|
@overload initialize(shape)
|
325
323
|
@overload initialize(size0, size1, ...)
|
326
|
-
|
327
|
-
|
328
|
-
|
324
|
+
@param [Array] shape (array of sizes along each dimension)
|
325
|
+
@param [Integer] sizeN (size along Nth-dimension)
|
326
|
+
@return [Numo::NArray] unallocated narray.
|
329
327
|
|
330
328
|
Constructs an instance of NArray class using the given
|
331
329
|
and <i>shape</i> or <i>sizes</i>.
|
@@ -400,8 +398,8 @@ nary_view_new(VALUE klass, int ndim, size_t* shape) {
|
|
400
398
|
Replaces the contents of self with the contents of other narray.
|
401
399
|
Used in dup and clone method.
|
402
400
|
@overload initialize_copy(other)
|
403
|
-
|
404
|
-
|
401
|
+
@param [Numo::NArray] other
|
402
|
+
@return [Numo::NArray] self
|
405
403
|
*/
|
406
404
|
static VALUE na_initialize_copy(VALUE self, VALUE orig) {
|
407
405
|
narray_t* na;
|
@@ -461,10 +459,10 @@ static VALUE na_s_ones(int argc, VALUE* argv, VALUE klass) {
|
|
461
459
|
but for typed NArray subclasses, e.g., DFloat, Int64.
|
462
460
|
|
463
461
|
@overload linspace(x1, x2, [n])
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
462
|
+
@param [Numeric] x1 The start value
|
463
|
+
@param [Numeric] x2 The end value
|
464
|
+
@param [Integer] n The number of elements. (default is 100).
|
465
|
+
@return [Numo::NArray] result array.
|
468
466
|
|
469
467
|
@example
|
470
468
|
a = Numo::DFloat.linspace(-5,5,7)
|
@@ -497,11 +495,11 @@ static VALUE na_s_linspace(int argc, VALUE* argv, VALUE klass) {
|
|
497
495
|
i.e., DFloat, SFloat, DComplex, and SComplex.
|
498
496
|
|
499
497
|
@overload logspace(a, b, [n, base])
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
498
|
+
@param [Numeric] a The start value
|
499
|
+
@param [Numeric] b The end value
|
500
|
+
@param [Integer] n The number of elements. (default is 50)
|
501
|
+
@param [Numeric] base The base of log space. (default is 10)
|
502
|
+
@return [Numo::NArray] result array.
|
505
503
|
|
506
504
|
@example
|
507
505
|
Numo::DFloat.logspace(4,0,5,2)
|
@@ -537,8 +535,8 @@ static VALUE na_s_logspace(int argc, VALUE* argv, VALUE klass) {
|
|
537
535
|
/*
|
538
536
|
Returns a NArray with shape=(n,n) whose diagonal elements are 1, otherwise 0.
|
539
537
|
@overload eye(n)
|
540
|
-
|
541
|
-
|
538
|
+
@param [Integer] n Size of NArray. Creates 2-D NArray with shape=(n,n)
|
539
|
+
@return [Numo::NArray] created NArray.
|
542
540
|
@example
|
543
541
|
a = Numo::DFloat.eye(3)
|
544
542
|
# => Numo::DFloat#shape=[3,3]
|
@@ -1024,8 +1022,9 @@ na_make_view(VALUE self) {
|
|
1024
1022
|
*
|
1025
1023
|
* Expand the shape of an array. Insert a new axis with size=1
|
1026
1024
|
* at a given dimension.
|
1027
|
-
* @
|
1028
|
-
*
|
1025
|
+
* @overload expand_dims(dim)
|
1026
|
+
* @param [Integer] dim dimension at which new axis is inserted.
|
1027
|
+
* @return [Numo::NArray] result narray view.
|
1029
1028
|
*/
|
1030
1029
|
static VALUE na_expand_dims(VALUE self, VALUE vdim) {
|
1031
1030
|
int i, j, nd, dim;
|
@@ -1191,8 +1190,8 @@ numo_na_upcast(VALUE type1, VALUE type2) {
|
|
1191
1190
|
Note that NArray has distinct UPCAST mechanism.
|
1192
1191
|
Coerce is used for operation between non-NArray and NArray.
|
1193
1192
|
@overload coerce(other)
|
1194
|
-
|
1195
|
-
|
1193
|
+
@param [Object] other numeric object.
|
1194
|
+
@return [Array] NArray-casted [other,self]
|
1196
1195
|
*/
|
1197
1196
|
static VALUE nary_coerce(VALUE x, VALUE y) {
|
1198
1197
|
VALUE type;
|
@@ -1229,9 +1228,9 @@ static VALUE nary_s_byte_size(VALUE type) {
|
|
1229
1228
|
/*
|
1230
1229
|
Returns a new 1-D array initialized from binary raw data in a string.
|
1231
1230
|
@overload from_binary(string,[shape])
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1231
|
+
@param [String] string Binary raw data.
|
1232
|
+
@param [Array] shape array of integers representing array shape.
|
1233
|
+
@return [Numo::NArray] NArray containing binary data.
|
1235
1234
|
*/
|
1236
1235
|
static VALUE nary_s_from_binary(int argc, VALUE* argv, VALUE type) {
|
1237
1236
|
size_t len, str_len, byte_size;
|
@@ -1304,9 +1303,9 @@ static VALUE nary_s_from_binary(int argc, VALUE* argv, VALUE type) {
|
|
1304
1303
|
/*
|
1305
1304
|
Returns a new 1-D array initialized from binary raw data in a string.
|
1306
1305
|
@overload store_binary(string,[offset])
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1306
|
+
@param [String] string Binary raw data.
|
1307
|
+
@param [Integer] (optional) offset Byte offset in string.
|
1308
|
+
@return [Integer] stored length.
|
1310
1309
|
*/
|
1311
1310
|
static VALUE nary_store_binary(int argc, VALUE* argv, VALUE self) {
|
1312
1311
|
size_t size, str_len, byte_size, offset;
|
@@ -1353,7 +1352,7 @@ static VALUE nary_store_binary(int argc, VALUE* argv, VALUE self) {
|
|
1353
1352
|
/*
|
1354
1353
|
Returns string containing the raw data bytes in NArray.
|
1355
1354
|
@overload to_binary()
|
1356
|
-
|
1355
|
+
@return [String] String object containing binary raw data.
|
1357
1356
|
*/
|
1358
1357
|
static VALUE nary_to_binary(VALUE self) {
|
1359
1358
|
size_t len, offset = 0;
|
@@ -1379,7 +1378,7 @@ static VALUE nary_to_binary(VALUE self) {
|
|
1379
1378
|
/*
|
1380
1379
|
Dump marshal data.
|
1381
1380
|
@overload marshal_dump()
|
1382
|
-
|
1381
|
+
@return [Array] Array containing marshal data.
|
1383
1382
|
*/
|
1384
1383
|
static VALUE nary_marshal_dump(VALUE self) {
|
1385
1384
|
VALUE a;
|
@@ -1413,8 +1412,8 @@ static VALUE na_inplace(VALUE self);
|
|
1413
1412
|
/*
|
1414
1413
|
Load marshal data.
|
1415
1414
|
@overload marshal_load(data)
|
1416
|
-
|
1417
|
-
|
1415
|
+
@param [Array] Array containing marshal data.
|
1416
|
+
@return [nil]
|
1418
1417
|
*/
|
1419
1418
|
static VALUE nary_marshal_load(VALUE self, VALUE a) {
|
1420
1419
|
VALUE v;
|
@@ -1463,8 +1462,8 @@ static VALUE nary_marshal_load(VALUE self, VALUE a) {
|
|
1463
1462
|
/*
|
1464
1463
|
Cast self to another NArray datatype.
|
1465
1464
|
@overload cast_to(datatype)
|
1466
|
-
|
1467
|
-
|
1465
|
+
@param [Class] datatype NArray datatype.
|
1466
|
+
@return [Numo::NArray]
|
1468
1467
|
*/
|
1469
1468
|
static VALUE nary_cast_to(VALUE obj, VALUE type) {
|
1470
1469
|
return rb_funcall(type, id_cast, 1, obj);
|
@@ -1732,7 +1731,7 @@ static VALUE na_profile_set(VALUE mod, VALUE val) {
|
|
1732
1731
|
/*
|
1733
1732
|
Returns the number of rows used for NArray#inspect
|
1734
1733
|
@overload inspect_rows
|
1735
|
-
|
1734
|
+
@return [Integer or nil] the number of rows.
|
1736
1735
|
*/
|
1737
1736
|
static VALUE na_inspect_rows(VALUE mod) {
|
1738
1737
|
if (numo_na_inspect_rows > 0) {
|
@@ -1745,8 +1744,8 @@ static VALUE na_inspect_rows(VALUE mod) {
|
|
1745
1744
|
/*
|
1746
1745
|
Set the number of rows used for NArray#inspect
|
1747
1746
|
@overload inspect_rows=(rows)
|
1748
|
-
|
1749
|
-
|
1747
|
+
@param [Integer or nil] rows the number of rows
|
1748
|
+
@return [nil]
|
1750
1749
|
*/
|
1751
1750
|
static VALUE na_inspect_rows_set(VALUE mod, VALUE num) {
|
1752
1751
|
if (RTEST(num)) {
|
@@ -1760,7 +1759,7 @@ static VALUE na_inspect_rows_set(VALUE mod, VALUE num) {
|
|
1760
1759
|
/*
|
1761
1760
|
Returns the number of cols used for NArray#inspect
|
1762
1761
|
@overload inspect_cols
|
1763
|
-
|
1762
|
+
@return [Integer or nil] the number of cols.
|
1764
1763
|
*/
|
1765
1764
|
static VALUE na_inspect_cols(VALUE mod) {
|
1766
1765
|
if (numo_na_inspect_cols > 0) {
|
@@ -1773,8 +1772,8 @@ static VALUE na_inspect_cols(VALUE mod) {
|
|
1773
1772
|
/*
|
1774
1773
|
Set the number of cols used for NArray#inspect
|
1775
1774
|
@overload inspect_cols=(cols)
|
1776
|
-
|
1777
|
-
|
1775
|
+
@param [Integer or nil] cols the number of cols
|
1776
|
+
@return [nil]
|
1778
1777
|
*/
|
1779
1778
|
static VALUE na_inspect_cols_set(VALUE mod, VALUE num) {
|
1780
1779
|
if (RTEST(num)) {
|
@@ -1789,8 +1788,8 @@ static VALUE na_inspect_cols_set(VALUE mod, VALUE num) {
|
|
1789
1788
|
Equality of self and other in view of numerical array.
|
1790
1789
|
i.e., both arrays have same shape and corresponding elements are equal.
|
1791
1790
|
@overload == other
|
1792
|
-
|
1793
|
-
|
1791
|
+
@param [Object] other
|
1792
|
+
@return [Boolean] true if self and other is equal.
|
1794
1793
|
*/
|
1795
1794
|
static VALUE na_equal(VALUE self, volatile VALUE other) {
|
1796
1795
|
volatile VALUE vbool;
|
@@ -1825,16 +1824,21 @@ void Init_narray(void) {
|
|
1825
1824
|
rb_ext_ractor_safe(true);
|
1826
1825
|
#endif
|
1827
1826
|
|
1827
|
+
/**
|
1828
|
+
* Document-module: Numo
|
1829
|
+
*
|
1830
|
+
* Ruby/Numo (NUmerical MOdules)
|
1831
|
+
*/
|
1828
1832
|
mNumo = rb_define_module("Numo");
|
1829
1833
|
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1834
|
+
/**
|
1835
|
+
* Document-class: Numo::NArray
|
1836
|
+
*
|
1837
|
+
* Numo::NArray is the abstract super class for
|
1838
|
+
* Numerical N-dimensional Array in the Ruby/Numo module.
|
1839
|
+
* Use Typed Subclasses of NArray (Numo::DFloat, Int32, etc)
|
1840
|
+
* to create data array instances.
|
1841
|
+
*/
|
1838
1842
|
cNArray = rb_define_class_under(mNumo, "NArray", rb_cObject);
|
1839
1843
|
|
1840
1844
|
#ifndef HAVE_RB_CCOMPLEX
|
@@ -1845,12 +1849,38 @@ void Init_narray(void) {
|
|
1845
1849
|
rb_cArithSeq = rb_path2class("Enumerator::ArithmeticSequence");
|
1846
1850
|
#endif
|
1847
1851
|
|
1852
|
+
/* The version of Numo::NArray Alternative. */
|
1848
1853
|
rb_define_const(cNArray, "VERSION", rb_str_new2(NARRAY_VERSION));
|
1849
1854
|
|
1855
|
+
/**
|
1856
|
+
* Document-class: Numo::NArray::CastError
|
1857
|
+
*
|
1858
|
+
* Exception raised when type casting is not possible.
|
1859
|
+
*/
|
1850
1860
|
nary_eCastError = rb_define_class_under(cNArray, "CastError", rb_eStandardError);
|
1861
|
+
/**
|
1862
|
+
* Document-class: Numo::NArray::ShapeError
|
1863
|
+
*
|
1864
|
+
* Exception raised when shape is invalid.
|
1865
|
+
*/
|
1851
1866
|
nary_eShapeError = rb_define_class_under(cNArray, "ShapeError", rb_eStandardError);
|
1867
|
+
/**
|
1868
|
+
* Document-class: Numo::NArray::OperationError
|
1869
|
+
*
|
1870
|
+
* Exception raised when operation is not appropriate.
|
1871
|
+
*/
|
1852
1872
|
nary_eOperationError = rb_define_class_under(cNArray, "OperationError", rb_eStandardError);
|
1873
|
+
/**
|
1874
|
+
* Document-class: Numo::NArray::DimensionError
|
1875
|
+
*
|
1876
|
+
* Exception raised when dimension is invalid.
|
1877
|
+
*/
|
1853
1878
|
nary_eDimensionError = rb_define_class_under(cNArray, "DimensionError", rb_eStandardError);
|
1879
|
+
/**
|
1880
|
+
* Document-class: Numo::NArray::ValueError
|
1881
|
+
*
|
1882
|
+
* Exception raised when occurred value error.
|
1883
|
+
*/
|
1854
1884
|
nary_eValueError = rb_define_class_under(cNArray, "ValueError", rb_eStandardError);
|
1855
1885
|
|
1856
1886
|
rb_define_singleton_method(cNArray, "debug=", na_debug_set, 1);
|
@@ -1973,8 +2003,6 @@ void Init_narray(void) {
|
|
1973
2003
|
Init_numo_bit();
|
1974
2004
|
Init_numo_robject();
|
1975
2005
|
|
1976
|
-
Init_nary_mean();
|
1977
|
-
|
1978
2006
|
Init_nary_math();
|
1979
2007
|
|
1980
2008
|
Init_nary_rand();
|
@@ -13,8 +13,8 @@ extern "C" {
|
|
13
13
|
#endif
|
14
14
|
#endif
|
15
15
|
|
16
|
-
#define NARRAY_VERSION "0.9.
|
17
|
-
#define NARRAY_VERSION_CODE
|
16
|
+
#define NARRAY_VERSION "0.9.6"
|
17
|
+
#define NARRAY_VERSION_CODE 960
|
18
18
|
|
19
19
|
#include <math.h>
|
20
20
|
#include "numo/compat.h"
|
@@ -343,31 +343,31 @@ static inline narray_t* _na_get_narray_t(VALUE obj, unsigned char na_type) {
|
|
343
343
|
#define NA_FL0_TEST(x, f) (NA_FLAG0(x) & (f))
|
344
344
|
#define NA_FL1_TEST(x, f) (NA_FLAG1(x) & (f))
|
345
345
|
|
346
|
-
#define NA_FL0_SET(x, f)
|
347
|
-
do {
|
348
|
-
NA_FLAG0(x) |= (f);
|
346
|
+
#define NA_FL0_SET(x, f) \
|
347
|
+
do { \
|
348
|
+
NA_FLAG0(x) |= (f); \
|
349
349
|
} while (0)
|
350
|
-
#define NA_FL1_SET(x, f)
|
351
|
-
do {
|
352
|
-
NA_FLAG1(x) |= (f);
|
350
|
+
#define NA_FL1_SET(x, f) \
|
351
|
+
do { \
|
352
|
+
NA_FLAG1(x) |= (f); \
|
353
353
|
} while (0)
|
354
354
|
|
355
|
-
#define NA_FL0_UNSET(x, f)
|
356
|
-
do {
|
357
|
-
NA_FLAG0(x) &= ~(f);
|
355
|
+
#define NA_FL0_UNSET(x, f) \
|
356
|
+
do { \
|
357
|
+
NA_FLAG0(x) &= ~(f); \
|
358
358
|
} while (0)
|
359
|
-
#define NA_FL1_UNSET(x, f)
|
360
|
-
do {
|
361
|
-
NA_FLAG1(x) &= ~(f);
|
359
|
+
#define NA_FL1_UNSET(x, f) \
|
360
|
+
do { \
|
361
|
+
NA_FLAG1(x) &= ~(f); \
|
362
362
|
} while (0)
|
363
363
|
|
364
|
-
#define NA_FL0_REVERSE(x, f)
|
365
|
-
do {
|
366
|
-
NA_FLAG0(x) ^= (f);
|
364
|
+
#define NA_FL0_REVERSE(x, f) \
|
365
|
+
do { \
|
366
|
+
NA_FLAG0(x) ^= (f); \
|
367
367
|
} while (0)
|
368
|
-
#define NA_FL1_REVERSE(x, f)
|
369
|
-
do {
|
370
|
-
NA_FLAG1(x) ^= (f);
|
368
|
+
#define NA_FL1_REVERSE(x, f) \
|
369
|
+
do { \
|
370
|
+
NA_FLAG1(x) ^= (f); \
|
371
371
|
} while (0)
|
372
372
|
|
373
373
|
/* FLAGS
|
@@ -6,7 +6,7 @@
|
|
6
6
|
#ifndef TEMPLATE_H
|
7
7
|
#define TEMPLATE_H
|
8
8
|
|
9
|
-
#define INIT_COUNTER(lp, c)
|
9
|
+
#define INIT_COUNTER(lp, c) \
|
10
10
|
{ c = (lp)->n[0]; }
|
11
11
|
|
12
12
|
#define NDL_CNT(lp) ((lp)->n[0])
|
@@ -16,113 +16,113 @@
|
|
16
16
|
#define NDL_ESZ(lp, i) ((lp)->args[i].elmsz)
|
17
17
|
#define NDL_SHAPE(lp, i) ((lp)->args[i].shape)
|
18
18
|
|
19
|
-
#define INIT_PTR(lp, i, pt, st)
|
20
|
-
{
|
21
|
-
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos;
|
22
|
-
st = ((lp)->args[i].iter[0]).step;
|
19
|
+
#define INIT_PTR(lp, i, pt, st) \
|
20
|
+
{ \
|
21
|
+
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos; \
|
22
|
+
st = ((lp)->args[i].iter[0]).step; \
|
23
23
|
}
|
24
24
|
|
25
|
-
#define INIT_PTR_IDX(lp, i, pt, st, id)
|
26
|
-
{
|
27
|
-
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos;
|
28
|
-
st = ((lp)->args[i].iter[0]).step;
|
29
|
-
id = ((lp)->args[i].iter[0]).idx;
|
25
|
+
#define INIT_PTR_IDX(lp, i, pt, st, id) \
|
26
|
+
{ \
|
27
|
+
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos; \
|
28
|
+
st = ((lp)->args[i].iter[0]).step; \
|
29
|
+
id = ((lp)->args[i].iter[0]).idx; \
|
30
30
|
}
|
31
31
|
|
32
|
-
#define INIT_ELMSIZE(lp, i, es)
|
32
|
+
#define INIT_ELMSIZE(lp, i, es) \
|
33
33
|
{ es = ((lp)->args[i]).elmsz; }
|
34
34
|
|
35
|
-
#define INIT_PTR_BIT(lp, i, ad, ps, st)
|
36
|
-
{
|
37
|
-
ps = ((lp)->args[i].iter[0]).pos;
|
38
|
-
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr);
|
39
|
-
st = ((lp)->args[i].iter[0]).step;
|
35
|
+
#define INIT_PTR_BIT(lp, i, ad, ps, st) \
|
36
|
+
{ \
|
37
|
+
ps = ((lp)->args[i].iter[0]).pos; \
|
38
|
+
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr); \
|
39
|
+
st = ((lp)->args[i].iter[0]).step; \
|
40
40
|
}
|
41
41
|
|
42
|
-
#define INIT_PTR_BIT_IDX(lp, i, ad, ps, st, id)
|
43
|
-
{
|
44
|
-
ps = ((lp)->args[i].iter[0]).pos;
|
45
|
-
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr);
|
46
|
-
st = ((lp)->args[i].iter[0]).step;
|
47
|
-
id = ((lp)->args[i].iter[0]).idx;
|
42
|
+
#define INIT_PTR_BIT_IDX(lp, i, ad, ps, st, id) \
|
43
|
+
{ \
|
44
|
+
ps = ((lp)->args[i].iter[0]).pos; \
|
45
|
+
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr); \
|
46
|
+
st = ((lp)->args[i].iter[0]).step; \
|
47
|
+
id = ((lp)->args[i].iter[0]).idx; \
|
48
48
|
}
|
49
49
|
|
50
|
-
#define GET_DATA(ptr, type, val)
|
50
|
+
#define GET_DATA(ptr, type, val) \
|
51
51
|
{ val = *(type*)(ptr); }
|
52
52
|
|
53
|
-
#define SET_DATA(ptr, type, val)
|
53
|
+
#define SET_DATA(ptr, type, val) \
|
54
54
|
{ *(type*)(ptr) = val; }
|
55
55
|
|
56
|
-
#define GET_DATA_STRIDE(ptr, step, type, val)
|
57
|
-
{
|
58
|
-
val = *(type*)(ptr);
|
59
|
-
ptr += step;
|
56
|
+
#define GET_DATA_STRIDE(ptr, step, type, val) \
|
57
|
+
{ \
|
58
|
+
val = *(type*)(ptr); \
|
59
|
+
ptr += step; \
|
60
60
|
}
|
61
61
|
|
62
|
-
#define GET_DATA_INDEX(ptr, idx, type, val)
|
63
|
-
{
|
64
|
-
val = *(type*)(ptr + *idx);
|
65
|
-
idx++;
|
62
|
+
#define GET_DATA_INDEX(ptr, idx, type, val) \
|
63
|
+
{ \
|
64
|
+
val = *(type*)(ptr + *idx); \
|
65
|
+
idx++; \
|
66
66
|
}
|
67
67
|
|
68
|
-
#define SET_DATA_STRIDE(ptr, step, type, val)
|
69
|
-
{
|
70
|
-
*(type*)(ptr) = val;
|
71
|
-
ptr += step;
|
68
|
+
#define SET_DATA_STRIDE(ptr, step, type, val) \
|
69
|
+
{ \
|
70
|
+
*(type*)(ptr) = val; \
|
71
|
+
ptr += step; \
|
72
72
|
}
|
73
73
|
|
74
|
-
#define SET_DATA_INDEX(ptr, idx, type, val)
|
75
|
-
{
|
76
|
-
*(type*)(ptr + *idx) = val;
|
77
|
-
idx++;
|
74
|
+
#define SET_DATA_INDEX(ptr, idx, type, val) \
|
75
|
+
{ \
|
76
|
+
*(type*)(ptr + *idx) = val; \
|
77
|
+
idx++; \
|
78
78
|
}
|
79
79
|
|
80
|
-
#define LOAD_BIT(adr, pos, val)
|
81
|
-
{
|
82
|
-
size_t dig = (pos) / NB;
|
83
|
-
int bit = (pos) % NB;
|
84
|
-
val = (((BIT_DIGIT*)(adr))[dig] >> (bit)) & 1u;
|
80
|
+
#define LOAD_BIT(adr, pos, val) \
|
81
|
+
{ \
|
82
|
+
size_t dig = (pos) / NB; \
|
83
|
+
int bit = (pos) % NB; \
|
84
|
+
val = (((BIT_DIGIT*)(adr))[dig] >> (bit)) & 1u; \
|
85
85
|
}
|
86
86
|
|
87
|
-
#define LOAD_BIT_STEP(adr, pos, step, idx, val)
|
88
|
-
{
|
89
|
-
size_t dig;
|
90
|
-
int bit;
|
91
|
-
if (idx) {
|
92
|
-
dig = ((pos) + *(idx)) / NB;
|
93
|
-
bit = ((pos) + *(idx)) % NB;
|
94
|
-
idx++;
|
95
|
-
} else {
|
96
|
-
dig = (pos) / NB;
|
97
|
-
bit = (pos) % NB;
|
98
|
-
pos += step;
|
99
|
-
}
|
100
|
-
val = (((BIT_DIGIT*)(adr))[dig] >> bit) & 1u;
|
87
|
+
#define LOAD_BIT_STEP(adr, pos, step, idx, val) \
|
88
|
+
{ \
|
89
|
+
size_t dig; \
|
90
|
+
int bit; \
|
91
|
+
if (idx) { \
|
92
|
+
dig = ((pos) + *(idx)) / NB; \
|
93
|
+
bit = ((pos) + *(idx)) % NB; \
|
94
|
+
idx++; \
|
95
|
+
} else { \
|
96
|
+
dig = (pos) / NB; \
|
97
|
+
bit = (pos) % NB; \
|
98
|
+
pos += step; \
|
99
|
+
} \
|
100
|
+
val = (((BIT_DIGIT*)(adr))[dig] >> bit) & 1u; \
|
101
101
|
}
|
102
102
|
|
103
|
-
#define STORE_BIT(adr, pos, val)
|
104
|
-
{
|
105
|
-
size_t dig = (pos) / NB;
|
106
|
-
int bit = (pos) % NB;
|
107
|
-
((BIT_DIGIT*)(adr))[dig] =
|
108
|
-
(((BIT_DIGIT*)(adr))[dig] & ~(1u << (bit))) | (((val) & 1u) << (bit));
|
103
|
+
#define STORE_BIT(adr, pos, val) \
|
104
|
+
{ \
|
105
|
+
size_t dig = (pos) / NB; \
|
106
|
+
int bit = (pos) % NB; \
|
107
|
+
((BIT_DIGIT*)(adr))[dig] = \
|
108
|
+
(((BIT_DIGIT*)(adr))[dig] & ~(1u << (bit))) | (((val) & 1u) << (bit)); \
|
109
109
|
}
|
110
110
|
|
111
|
-
#define STORE_BIT_STEP(adr, pos, step, idx, val)
|
112
|
-
{
|
113
|
-
size_t dig;
|
114
|
-
int bit;
|
115
|
-
if (idx) {
|
116
|
-
dig = ((pos) + *(idx)) / NB;
|
117
|
-
bit = ((pos) + *(idx)) % NB;
|
118
|
-
idx++;
|
119
|
-
} else {
|
120
|
-
dig = (pos) / NB;
|
121
|
-
bit = (pos) % NB;
|
122
|
-
pos += step;
|
123
|
-
}
|
124
|
-
((BIT_DIGIT*)(adr))[dig] =
|
125
|
-
(((BIT_DIGIT*)(adr))[dig] & ~(1u << (bit))) | (((val) & 1u) << (bit));
|
111
|
+
#define STORE_BIT_STEP(adr, pos, step, idx, val) \
|
112
|
+
{ \
|
113
|
+
size_t dig; \
|
114
|
+
int bit; \
|
115
|
+
if (idx) { \
|
116
|
+
dig = ((pos) + *(idx)) / NB; \
|
117
|
+
bit = ((pos) + *(idx)) % NB; \
|
118
|
+
idx++; \
|
119
|
+
} else { \
|
120
|
+
dig = (pos) / NB; \
|
121
|
+
bit = (pos) % NB; \
|
122
|
+
pos += step; \
|
123
|
+
} \
|
124
|
+
((BIT_DIGIT*)(adr))[dig] = \
|
125
|
+
(((BIT_DIGIT*)(adr))[dig] & ~(1u << (bit))) | (((val) & 1u) << (bit)); \
|
126
126
|
}
|
127
127
|
|
128
128
|
static inline int is_aligned(const void* ptr, const size_t alignment) {
|
@@ -19,6 +19,9 @@ typedef BIT_DIGIT rtype;
|
|
19
19
|
#define m_data_to_num(x) INT2FIX(x)
|
20
20
|
#define m_sprintf(s, x) sprintf(s, "%1d", (int)(x))
|
21
21
|
|
22
|
+
#define m_add(x, y) ((x) + (y))
|
23
|
+
#define m_div(x, y) ((x) / (y))
|
24
|
+
|
22
25
|
#define m_copy(x) (x)
|
23
26
|
#define m_not(x) (~(x))
|
24
27
|
#define m_and(x, y) ((x) & (y))
|
@@ -36,3 +39,76 @@ static inline BIT_DIGIT m_num_to_data(VALUE num) {
|
|
36
39
|
}
|
37
40
|
return 0;
|
38
41
|
}
|
42
|
+
|
43
|
+
static inline double f_mean(size_t n, BIT_DIGIT* p, size_t pos, ssize_t stride, size_t* idx) {
|
44
|
+
size_t count = 0;
|
45
|
+
double sum = 0.0;
|
46
|
+
BIT_DIGIT x;
|
47
|
+
if (idx) {
|
48
|
+
for (size_t i = n; i--;) {
|
49
|
+
LOAD_BIT(p, pos + *idx, x);
|
50
|
+
idx++;
|
51
|
+
sum += (double)x;
|
52
|
+
count++;
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
for (size_t i = n; i--;) {
|
56
|
+
LOAD_BIT(p, pos, x);
|
57
|
+
pos += stride;
|
58
|
+
sum += (double)x;
|
59
|
+
count++;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
return sum / (double)count;
|
63
|
+
}
|
64
|
+
|
65
|
+
static inline double f_var(size_t n, BIT_DIGIT* p, size_t pos, ssize_t stride, size_t* idx) {
|
66
|
+
size_t count = 0;
|
67
|
+
double sum = 0.0;
|
68
|
+
BIT_DIGIT x;
|
69
|
+
const double mean = f_mean(n, p, pos, stride, idx);
|
70
|
+
if (idx) {
|
71
|
+
for (size_t i = n; i--;) {
|
72
|
+
LOAD_BIT(p, pos + *idx, x);
|
73
|
+
const double d = (double)x - mean;
|
74
|
+
idx++;
|
75
|
+
sum += d * d;
|
76
|
+
count++;
|
77
|
+
}
|
78
|
+
} else {
|
79
|
+
for (size_t i = n; i--;) {
|
80
|
+
LOAD_BIT(p, pos, x);
|
81
|
+
const double d = (double)x - mean;
|
82
|
+
pos += stride;
|
83
|
+
sum += d * d;
|
84
|
+
count++;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return sum / (double)(count - 1);
|
88
|
+
}
|
89
|
+
|
90
|
+
static inline double f_stddev(size_t n, BIT_DIGIT* p, size_t pos, ssize_t stride, size_t* idx) {
|
91
|
+
return sqrt(f_var(n, p, pos, stride, idx));
|
92
|
+
}
|
93
|
+
|
94
|
+
static inline double f_rms(size_t n, BIT_DIGIT* p, size_t pos, ssize_t stride, size_t* idx) {
|
95
|
+
size_t count = 0;
|
96
|
+
double sum = 0.0;
|
97
|
+
BIT_DIGIT x;
|
98
|
+
if (idx) {
|
99
|
+
for (size_t i = n; i--;) {
|
100
|
+
LOAD_BIT(p, pos + *idx, x);
|
101
|
+
idx++;
|
102
|
+
sum += (double)(x * x);
|
103
|
+
count++;
|
104
|
+
}
|
105
|
+
} else {
|
106
|
+
for (size_t i = n; i--;) {
|
107
|
+
LOAD_BIT(p, pos, x);
|
108
|
+
pos += stride;
|
109
|
+
sum += (double)(x * x);
|
110
|
+
count++;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
return sqrt(sum / (double)count);
|
114
|
+
}
|
@@ -41,9 +41,9 @@ static inline dtype NUM2COMP(VALUE v) {
|
|
41
41
|
#define c_ne(x, y) (REAL(x) != REAL(y) || IMAG(x) != IMAG(y))
|
42
42
|
#define c_isnan(x) (isnan(REAL(x)) || isnan(IMAG(x)))
|
43
43
|
#define c_isinf(x) (isinf(REAL(x)) || isinf(IMAG(x)))
|
44
|
-
#define c_isposinf(x)
|
44
|
+
#define c_isposinf(x) \
|
45
45
|
((isinf(REAL(x)) && signbit(REAL(x)) == 0) || (isinf(IMAG(x)) && signbit(IMAG(x)) == 0))
|
46
|
-
#define c_isneginf(x)
|
46
|
+
#define c_isneginf(x) \
|
47
47
|
((isinf(REAL(x)) && signbit(REAL(x))) || (isinf(IMAG(x)) && signbit(IMAG(x))))
|
48
48
|
#define c_isfinite(x) (isfinite(REAL(x)) && isfinite(IMAG(x)))
|
49
49
|
|