numo-narray 0.9.0.1-x64-mingw32 → 0.9.0.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -7
  3. data/Rakefile +20 -5
  4. data/ext/numo/narray/array.c +3 -3
  5. data/ext/numo/narray/data.c +102 -81
  6. data/ext/numo/narray/depend.erb +9 -7
  7. data/ext/numo/narray/extconf.rb +5 -24
  8. data/ext/numo/narray/gen/cogen.rb +19 -4
  9. data/ext/numo/narray/gen/def/bit.rb +31 -0
  10. data/ext/numo/narray/gen/def/robject.rb +1 -1
  11. data/ext/numo/narray/gen/dtype.erb.c +11 -257
  12. data/ext/numo/narray/gen/spec.rb +294 -0
  13. data/ext/numo/narray/gen/tmpl/aset.c +1 -1
  14. data/ext/numo/narray/gen/tmpl/each_with_index.c +1 -1
  15. data/ext/numo/narray/gen/tmpl/eye.c +5 -5
  16. data/ext/numo/narray/gen/tmpl/logseq.c +82 -0
  17. data/ext/numo/narray/gen/tmpl/map_with_index.c +1 -1
  18. data/ext/numo/narray/gen/tmpl/rand.c +126 -5
  19. data/ext/numo/narray/gen/tmpl/seq.c +43 -12
  20. data/ext/numo/narray/gen/tmpl/store_bit.c +55 -0
  21. data/ext/numo/narray/gen/tmpl_bit/allocate.c +28 -0
  22. data/ext/numo/narray/gen/tmpl_bit/aref.c +53 -0
  23. data/ext/numo/narray/gen/tmpl_bit/aset.c +63 -0
  24. data/ext/numo/narray/gen/{tmpl/bit_binary.c → tmpl_bit/binary.c} +1 -1
  25. data/ext/numo/narray/gen/{tmpl → tmpl_bit}/bit_count.c +5 -3
  26. data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +128 -0
  27. data/ext/numo/narray/gen/tmpl_bit/cast.c +37 -0
  28. data/ext/numo/narray/gen/tmpl_bit/cast_array.c +80 -0
  29. data/ext/numo/narray/gen/tmpl_bit/cast_numeric.c +22 -0
  30. data/ext/numo/narray/gen/tmpl_bit/coerce_cast.c +8 -0
  31. data/ext/numo/narray/gen/tmpl_bit/each.c +44 -0
  32. data/ext/numo/narray/gen/tmpl_bit/each_with_index.c +66 -0
  33. data/ext/numo/narray/gen/tmpl_bit/extract.c +25 -0
  34. data/ext/numo/narray/gen/tmpl_bit/fill.c +65 -0
  35. data/ext/numo/narray/gen/tmpl_bit/format.c +61 -0
  36. data/ext/numo/narray/gen/tmpl_bit/format_to_a.c +48 -0
  37. data/ext/numo/narray/gen/tmpl_bit/inspect.c +18 -0
  38. data/ext/numo/narray/gen/tmpl_bit/map_with_index.c +94 -0
  39. data/ext/numo/narray/gen/tmpl_bit/mask.c +117 -0
  40. data/ext/numo/narray/gen/tmpl_bit/none_p.c +14 -0
  41. data/ext/numo/narray/gen/tmpl_bit/store.c +32 -0
  42. data/ext/numo/narray/gen/tmpl_bit/store_array.c +5 -0
  43. data/ext/numo/narray/gen/tmpl_bit/store_bit.c +66 -0
  44. data/ext/numo/narray/gen/tmpl_bit/store_from.c +56 -0
  45. data/ext/numo/narray/gen/tmpl_bit/store_numeric.c +22 -0
  46. data/ext/numo/narray/gen/tmpl_bit/to_a.c +43 -0
  47. data/ext/numo/narray/gen/{tmpl/bit_unary.c → tmpl_bit/unary.c} +1 -1
  48. data/ext/numo/narray/gen/tmpl_bit/where.c +102 -0
  49. data/ext/numo/narray/gen/tmpl_bit/where2.c +37 -0
  50. data/ext/numo/narray/index.c +9 -7
  51. data/ext/numo/narray/math.c +6 -1
  52. data/ext/numo/narray/narray.c +307 -103
  53. data/ext/numo/narray/ndloop.c +21 -36
  54. data/ext/numo/narray/numo/intern.h +3 -3
  55. data/ext/numo/narray/numo/narray.h +5 -41
  56. data/ext/numo/narray/numo/template.h +2 -2
  57. data/ext/numo/narray/numo/types/bit.h +27 -13
  58. data/ext/numo/narray/numo/types/complex.h +2 -2
  59. data/ext/numo/narray/numo/types/complex_macro.h +19 -7
  60. data/ext/numo/narray/numo/types/dcomplex.h +9 -0
  61. data/ext/numo/narray/numo/types/dfloat.h +6 -0
  62. data/ext/numo/narray/numo/types/float_macro.h +9 -2
  63. data/ext/numo/narray/numo/types/int16.h +0 -1
  64. data/ext/numo/narray/numo/types/int32.h +0 -1
  65. data/ext/numo/narray/numo/types/int64.h +0 -1
  66. data/ext/numo/narray/numo/types/int8.h +0 -1
  67. data/ext/numo/narray/numo/types/int_macro.h +2 -1
  68. data/ext/numo/narray/numo/types/robj_macro.h +9 -2
  69. data/ext/numo/narray/numo/types/robject.h +6 -0
  70. data/ext/numo/narray/numo/types/scomplex.h +9 -0
  71. data/ext/numo/narray/numo/types/sfloat.h +6 -0
  72. data/ext/numo/narray/numo/types/uint16.h +0 -1
  73. data/ext/numo/narray/numo/types/uint32.h +0 -1
  74. data/ext/numo/narray/numo/types/uint64.h +0 -1
  75. data/ext/numo/narray/numo/types/uint8.h +0 -1
  76. data/ext/numo/narray/numo/types/uint_macro.h +2 -1
  77. data/ext/numo/narray/numo/types/xint_macro.h +6 -1
  78. data/ext/numo/narray/rand.c +2 -2
  79. data/ext/numo/narray/step.c +7 -7
  80. data/ext/numo/narray/struct.c +11 -12
  81. data/lib/2.0/numo/narray.so +0 -0
  82. data/lib/2.1/numo/narray.so +0 -0
  83. data/lib/2.2/numo/narray.so +0 -0
  84. data/lib/2.3/numo/narray.so +0 -0
  85. data/lib/2.4/numo/narray.so +0 -0
  86. data/lib/erbpp.rb +6 -2
  87. data/lib/erbpp/line_number.rb +1 -1
  88. data/lib/erbpp/narray_def.rb +23 -19
  89. data/numo-narray.gemspec +2 -2
  90. metadata +45 -10
  91. data/ext/numo/narray/gen/bit.erb.c +0 -811
@@ -73,7 +73,7 @@ typedef struct NA_MD_LOOP {
73
73
 
74
74
  #define NDL_READ 1
75
75
  #define NDL_WRITE 2
76
- #define NDL_READ_WRITE 3
76
+ #define NDL_READ_WRITE (NDL_READ|NDL_WRITE)
77
77
 
78
78
  static inline VALUE
79
79
  nary_type_s_cast(VALUE type, VALUE obj)
@@ -153,7 +153,7 @@ print_ndloop(na_md_loop_t *lp) {
153
153
  printf("--user.args[%d]--\n", j);
154
154
  printf(" user.args[%d].ptr = 0x%"SZF"x\n", j, (size_t)LARG(lp,j).ptr);
155
155
  printf(" user.args[%d].elmsz = %"SZF"d\n", j, LARG(lp,j).elmsz);
156
- printf(" user.args[%d].value = 0x%"SZF"x\n", j, LARG(lp,j).value);
156
+ printf(" user.args[%d].value = 0x%"PRI_VALUE_PREFIX"x\n", j, LARG(lp,j).value);
157
157
  printf(" user.args[%d].ndim = %d\n", j, LARG(lp,j).ndim);
158
158
  printf(" user.args[%d].shape = 0x%"SZF"x\n", j, (size_t)LARG(lp,j).shape);
159
159
  if (LARG(lp,j).shape) {
@@ -253,7 +253,7 @@ ndloop_cast_args(ndfunc_t *nf, VALUE args)
253
253
  value = RARRAY_AREF(args,j);
254
254
  if (!ndloop_cast_required(type, value))
255
255
  continue;
256
-
256
+
257
257
  if (ndloop_castable_type(type)) {
258
258
  RARRAY_ASET(args,j,nary_type_s_cast(type, value));
259
259
  copy_flag |= 1<<j;
@@ -300,7 +300,7 @@ ndloop_find_max_dimension(na_md_loop_t *lp, ndfunc_t *nf, VALUE args)
300
300
  int nin=0; // number of input objects (except for symbols)
301
301
  int user_nd=0; // max dimension of user function
302
302
  int loop_nd=0; // max dimension of md-loop
303
-
303
+
304
304
  for (j=0; j<RARRAY_LEN(args); j++) {
305
305
  VALUE t = nf->ain[j].type;
306
306
  VALUE v = RARRAY_AREF(args,j);
@@ -309,7 +309,7 @@ ndloop_find_max_dimension(na_md_loop_t *lp, ndfunc_t *nf, VALUE args)
309
309
  } else {
310
310
  nin++;
311
311
  user_nd = max2(user_nd, nf->ain[j].dim);
312
- if (IsNArray(v))
312
+ if (IsNArray(v))
313
313
  loop_nd = max2(loop_nd, RNARRAY_NDIM(v) - nf->ain[j].dim);
314
314
  }
315
315
  }
@@ -377,7 +377,7 @@ ndloop_alloc(na_md_loop_t *lp, ndfunc_t *nf, VALUE args,
377
377
  ndloop_find_max_dimension(lp, nf, args);
378
378
  narg = lp->nin + nf->nout;
379
379
  max_nd = lp->ndim + lp->user.ndim;
380
-
380
+
381
381
  lp->n = lp->n_ptr = ALLOC_N(size_t, max_nd+1);
382
382
  lp->xargs = ALLOC_N(na_loop_xargs_t, narg);
383
383
  lp->user.args = ALLOC_N(na_loop_args_t, narg);
@@ -535,11 +535,14 @@ ndloop_set_stepidx(na_md_loop_t *lp, int j, VALUE vna, int *dim_map, int rwflag)
535
535
 
536
536
  LARG(lp,j).value = vna;
537
537
  LARG(lp,j).elmsz = na_get_elmsz(vna);
538
- if (rwflag & NDL_READ) {
538
+ if (rwflag == NDL_READ) {
539
539
  LARG(lp,j).ptr = na_get_pointer_for_read(vna);
540
540
  } else
541
- if (rwflag & NDL_WRITE) {
541
+ if (rwflag == NDL_WRITE) {
542
542
  LARG(lp,j).ptr = na_get_pointer_for_write(vna);
543
+ } else
544
+ if (rwflag == NDL_READ_WRITE) {
545
+ LARG(lp,j).ptr = na_get_pointer_for_read_write(vna);
543
546
  } else {
544
547
  rb_bug("invalid value for read-write flag");
545
548
  }
@@ -890,7 +893,8 @@ ndfunc_contract_loop(na_md_loop_t *lp)
890
893
  }
891
894
  }
892
895
  if (success) {
893
- //printf("contract i=%d-th and %d-th\n",i-1,i);
896
+ //printf("contract i=%d-th and %d-th, lp->n[%d]=%"SZF"d, lp->n[%d]=%"SZF"d\n",
897
+ // i-1,i, i,lp->n[i], i-1,lp->n[i-1]);
894
898
  // contract (i-1)-th and i-th dimension
895
899
  lp->n[i] *= lp->n[i-1];
896
900
  // shift dimensions
@@ -915,6 +919,7 @@ ndfunc_contract_loop(na_md_loop_t *lp)
915
919
  //printf("contract cnt=%d\n",cnt);
916
920
  if (cnt>0) {
917
921
  for (j=0; j<lp->narg; j++) {
922
+ LITER(lp,cnt,j).pos = LITER(lp,0,j).pos;
918
923
  lp->xargs[j].iter = &LITER(lp,cnt,j);
919
924
  }
920
925
  lp->n = &(lp->n[cnt]);
@@ -1312,10 +1317,10 @@ ndloop_run(VALUE vlp)
1312
1317
  // loop
1313
1318
  (*(lp->loop_func))(nf, lp);
1314
1319
 
1315
- if (na_debug_flag) {
1316
- printf("-- after loop --\n");
1317
- print_ndloop(lp);
1318
- }
1320
+ //if (na_debug_flag) {
1321
+ // printf("-- after loop --\n");
1322
+ // print_ndloop(lp);
1323
+ //}
1319
1324
 
1320
1325
  if (RTEST(lp->user.err_type)) {
1321
1326
  rb_raise(lp->user.err_type, "error in NArray operation");
@@ -1531,25 +1536,9 @@ na_info_str(VALUE ary)
1531
1536
 
1532
1537
  //----------------------------------------------------------------------
1533
1538
 
1534
- static void
1535
- ndloop_inspect_get_width(int *ncol, int *nrow)
1536
- {
1537
- VALUE cols, rows;
1538
-
1539
- cols = rb_ivar_get(cNArray,rb_intern("inspect_cols"));
1540
- if (RTEST(cols)) {
1541
- *ncol = NUM2INT(cols);
1542
- } else {
1543
- *ncol = 80;
1544
- }
1545
-
1546
- rows = rb_ivar_get(cNArray,rb_intern("inspect_rows"));
1547
- if (RTEST(rows)) {
1548
- *nrow = NUM2INT(rows);
1549
- } else {
1550
- *nrow = 20;
1551
- }
1552
- }
1539
+ #define ncol numo_na_inspect_cols
1540
+ #define nrow numo_na_inspect_rows
1541
+ extern int ncol, nrow;
1553
1542
 
1554
1543
  static void
1555
1544
  loop_inspect(ndfunc_t *nf, na_md_loop_t *lp)
@@ -1559,8 +1548,6 @@ loop_inspect(ndfunc_t *nf, na_md_loop_t *lp)
1559
1548
  int col=0, row=0;
1560
1549
  long len;
1561
1550
  VALUE str;
1562
- int ncol;
1563
- int nrow;
1564
1551
  na_text_func_t func = (na_text_func_t)(nf->func);
1565
1552
  VALUE buf, opt;
1566
1553
 
@@ -1587,8 +1574,6 @@ loop_inspect(ndfunc_t *nf, na_md_loop_t *lp)
1587
1574
  rb_str_cat(buf,"",0);
1588
1575
  }
1589
1576
 
1590
- ndloop_inspect_get_width(&ncol,&nrow);
1591
-
1592
1577
  col = nd*2;
1593
1578
  for (i=0;;) {
1594
1579
  if (i<nd-1) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  intern.h
3
3
  Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2011 by Masahiro TANAKA
4
+ (C) Copyright 1999-2016 by Masahiro TANAKA
5
5
 
6
6
  This program is free software.
7
7
  You can distribute/modify this program
@@ -19,6 +19,7 @@ VALUE na_original_data(VALUE self);
19
19
  VALUE na_make_view(VALUE self);
20
20
  VALUE na_make_view_struct(VALUE self, VALUE dtype, VALUE offset);
21
21
  void na_array_to_internal_shape(VALUE self, VALUE ary, size_t *shape);
22
+ VALUE na_expand_dims(VALUE self, VALUE vdim);
22
23
 
23
24
  VALUE na_reduce_dimension(int argc, VALUE *argv, int naryc, VALUE *naryv);
24
25
 
@@ -37,7 +38,7 @@ VALUE na_sort_index_main(int argc, VALUE *argv, VALUE self, void (*func_qsort)()
37
38
  char *na_get_pointer(VALUE);
38
39
  char *na_get_pointer_for_write(VALUE);
39
40
  char *na_get_pointer_for_read(VALUE);
40
- char *na_get_pointer_at_origin_for_read(VALUE);
41
+ char *na_get_pointer_for_read_write(VALUE);
41
42
 
42
43
  size_t na_get_offset(VALUE self);
43
44
 
@@ -50,7 +51,6 @@ void na_alloc_index(narray_t *na);
50
51
  void na_copy_flags(VALUE src, VALUE dst);
51
52
 
52
53
  VALUE na_flatten(VALUE);
53
- VALUE na_dup(VALUE);
54
54
  VALUE na_copy(VALUE);
55
55
  VALUE na_upcast(VALUE type1, VALUE type2);
56
56
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  narray.h
3
3
  Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2003 by Masahiro TANAKA
4
+ (C) Copyright 1999-2016 by Masahiro TANAKA
5
5
 
6
6
  This program is free software.
7
7
  You can distribute/modify this program
@@ -11,14 +11,13 @@
11
11
  #ifndef NARRAY_H
12
12
  #define NARRAY_H
13
13
 
14
- #define NARRAY_VERSION "0.9.0.1"
15
- #define NARRAY_VERSION_CODE 901
14
+ #define NARRAY_VERSION "0.9.0.3"
15
+ #define NARRAY_VERSION_CODE 903
16
16
 
17
17
  #include <math.h>
18
18
  #include "numo/compat.h"
19
19
  #include "numo/template.h"
20
-
21
- #include "extconf.h"
20
+ #include "numo/extconf.h"
22
21
 
23
22
  #ifdef HAVE_STDBOOL_H
24
23
  # include <stdbool.h>
@@ -56,19 +55,7 @@
56
55
  # endif
57
56
  #endif
58
57
 
59
- #if SIZEOF_VOIDP==SIZEOF_LONG
60
- # define NUM2SIZE(x) NUM2ULONG(x)
61
- # define NUM2SSIZE(x) NUM2LONG(x)
62
- # define SIZE2NUM(x) ULONG2NUM(x)
63
- # define SSIZE2NUM(x) LONG2NUM(x)
64
- # define SZF "l"
65
- #elif SIZEOF_VOIDP==SIZEOF_LONG_LONG
66
- # define NUM2SIZE(x) NUM2ULL(x)
67
- # define NUM2SSIZE(x) NUM2LL(x)
68
- # define SIZE2NUM(x) ULL2NUM(x)
69
- # define SSIZE2NUM(x) LL2NUM(x)
70
- # define SZF "ll"
71
- #endif
58
+ #define SZF PRI_SIZE_PREFIX // defined in ruby.h
72
59
 
73
60
  #if SIZEOF_LONG==8
74
61
  # define NUM2INT64(x) NUM2LONG(x)
@@ -358,13 +345,10 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
358
345
  #endif
359
346
  #endif
360
347
 
361
-
362
348
  #define IsNArray(obj) (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
363
349
 
364
350
  #define DEBUG_PRINT(v) puts(StringValueCStr(rb_funcall(v,rb_intern("inspect"),0)))
365
351
 
366
-
367
-
368
352
  #define NA_IsNArray(obj) \
369
353
  (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
370
354
  #define NA_IsArray(obj) \
@@ -375,37 +359,17 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
375
359
 
376
360
  #define NA_MAX_DIMENSION (int)(sizeof(VALUE)*8-2)
377
361
 
378
- /* Function Prototypes */
379
-
380
-
381
- typedef struct {
382
- double beg;
383
- double step;
384
- double count;
385
- } seq_opt_t;
386
-
387
- typedef struct {
388
- u_int64_t max;
389
- int64_t sign;
390
- int shift;
391
- } rand_opt_t;
392
-
393
-
394
362
  typedef unsigned int BIT_DIGIT;
395
363
  //#define BYTE_BIT_DIGIT sizeof(BIT_DIGIT)
396
364
  #define NB (sizeof(BIT_DIGIT)*8)
397
365
  #define BALL (~(BIT_DIGIT)0)
398
366
  #define SLB(n) (((n)==NB)?~(BIT_DIGIT)0:(~(~(BIT_DIGIT)0<<(n))))
399
367
 
400
- //#include "template.h"
401
-
402
368
  #define ELEMENT_BIT_SIZE "ELEMENT_BIT_SIZE"
403
369
  #define ELEMENT_BYTE_SIZE "ELEMENT_BYTE_SIZE"
404
370
  #define CONTIGUOUS_STRIDE "CONTIGUOUS_STRIDE"
405
371
 
406
372
  #include "numo/ndloop.h"
407
- //#include "ndfunc.h"
408
-
409
373
  #include "numo/intern.h"
410
374
 
411
375
  #endif /* ifndef NARRAY_H */
@@ -1,7 +1,7 @@
1
1
  /*
2
- narray.h
2
+ template.h
3
3
  Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2003 by Masahiro TANAKA
4
+ (C) Copyright 1999-2016 by Masahiro TANAKA
5
5
 
6
6
  This program is free software.
7
7
  You can distribute/modify this program
@@ -1,19 +1,33 @@
1
- typedef int dtype;
1
+ typedef BIT_DIGIT dtype;
2
+ typedef BIT_DIGIT rtype;
3
+ #define cT numo_cBit
4
+ #define cRT cT
2
5
 
3
- #define m_load_data(ptr,pos) load_data(ptr,pos)
6
+ #define m_zero 0
7
+ #define m_one 1
4
8
 
5
- #define m_sprintf(s,x) sprintf(s,"%1d",(int)(x))
6
-
7
- #define m_bit_not(x) (~(x))
9
+ #define m_abs(x) (x)
10
+ #define m_sign(x) (((x)==0) ? 0:1)
8
11
 
9
- #define m_bit_and(x,y) ((x)&(y))
10
- #define m_bit_or(x,y) ((x)|(y))
11
- #define m_bit_xor(x,y) ((x)^(y))
12
- #define m_eq(x,y) (~((x)^(y)))
12
+ #define m_from_double(x) (((x)==0) ? 0 : 1)
13
+ #define m_from_real(x) (((x)==0) ? 0 : 1)
14
+ #define m_data_to_num(x) INT2FIX(x)
15
+ #define m_sprintf(s,x) sprintf(s,"%1d",(int)(x))
13
16
 
14
- #define m_count_true(x) (x!=0)
15
- #define m_count_false(x) (x==0)
17
+ #define m_copy(x) (x)
18
+ #define m_not(x) (~(x))
19
+ #define m_and(x,y) ((x)&(y))
20
+ #define m_or(x,y) ((x)|(y))
21
+ #define m_xor(x,y) ((x)^(y))
22
+ #define m_eq(x,y) (~((x)^(y)))
23
+ #define m_count_true(x) ((x)!=0)
24
+ #define m_count_false(x) ((x)==0)
16
25
 
17
- static inline dtype load_data(void *ptr, size_t pos) {
18
- return (((BIT_DIGIT*)(ptr))[(pos)/NB]>>((pos)%NB)) & 1u;
26
+ static inline BIT_DIGIT m_num_to_data(VALUE num) {
27
+ if (RTEST(num)) {
28
+ if (!RTEST(rb_equal(num,INT2FIX(0)))) {
29
+ return 1;
30
+ }
31
+ }
32
+ return 0;
19
33
  }
@@ -123,7 +123,7 @@ static inline dtype c_div_r(dtype x, rtype y) {
123
123
  return z;
124
124
  }
125
125
 
126
- static inline dtype c_inverse(dtype x) {
126
+ static inline dtype c_reciprocal(dtype x) {
127
127
  dtype z;
128
128
  if ( r_abs(REAL(x)) > r_abs(IMAG(x)) ) {
129
129
  IMAG(z) = IMAG(x)/REAL(x);
@@ -372,7 +372,7 @@ static inline dtype c_pow_int(dtype x, int p)
372
372
  dtype z = c_one();
373
373
  if (p<0) {
374
374
  x = c_pow_int(x,-p);
375
- return c_inverse(x);
375
+ return c_reciprocal(x);
376
376
  }
377
377
  if (p==2) {return c_square(x);}
378
378
  if (p&1) {z = x;}
@@ -61,13 +61,21 @@ static inline dtype c_from_dcomplex(dcomplex x) {
61
61
  #define m_pow(x,y) c_pow(x,y)
62
62
  #define m_pow_int(x,y) c_pow_int(x,y)
63
63
 
64
- #define m_minus(x) c_minus(x)
65
- #define m_inverse(x) c_inverse(x)
66
- #define m_square(x) c_square(x)
67
- #define m_im(x) c_im(x)
68
-
69
- #define m_conj(x) c_new(REAL(x),-IMAG(x))
70
64
  #define m_abs(x) c_abs(x)
65
+ #define m_minus(x) c_minus(x)
66
+ #define m_reciprocal(x) c_reciprocal(x)
67
+ #define m_square(x) c_square(x)
68
+ #define m_floor(x) c_new(floor(REAL(x)),floor(IMAG(x)))
69
+ #define m_round(x) c_new(round(REAL(x)),round(IMAG(x)))
70
+ #define m_ceil(x) c_new(ceil(REAL(x)),ceil(IMAG(x)))
71
+ #define m_trunc(x) c_new(trunc(REAL(x)),trunc(IMAG(x)))
72
+ #define m_rint(x) c_new(rint(REAL(x)),rint(IMAG(x)))
73
+ #define m_sign(x) c_new( \
74
+ ((REAL(x)==0) ? 0.0:((REAL(x)>0) ? 1.0:((REAL(x)<0) ? -1.0:REAL(x)))), \
75
+ ((IMAG(x)==0) ? 0.0:((IMAG(x)>0) ? 1.0:((IMAG(x)<0) ? -1.0:IMAG(x)))))
76
+
77
+ #define m_im(x) c_im(x)
78
+ #define m_conj(x) c_new(REAL(x),-IMAG(x))
71
79
  #define m_arg(x) atan2(IMAG(x),REAL(x))
72
80
 
73
81
  #define m_eq(x,y) c_eq(x,y)
@@ -84,7 +92,6 @@ static inline dtype c_from_dcomplex(dcomplex x) {
84
92
  #define m_mulsum(x,y,z) {z = c_add(c_mul(x,y),z);}
85
93
  #define m_mulsum_init INT2FIX(0)
86
94
 
87
- #define m_rand c_new(to_res53(gen_rand64()),to_res53(gen_rand64()))
88
95
  #define m_rand_norm(a) rand_norm(a)
89
96
 
90
97
  #define m_sprintf(s,x) sprintf(s,"%g%+gi",REAL(x),IMAG(x))
@@ -203,3 +210,8 @@ static inline rtype f_rms(size_t n, char *p, ssize_t stride)
203
210
  }
204
211
  return r_sqrt(y/count);
205
212
  }
213
+
214
+ static inline dtype f_seq(dtype x, dtype y, double c)
215
+ {
216
+ return c_add(x,c_mul_r(y,c));
217
+ }
@@ -9,3 +9,12 @@ typedef double rtype;
9
9
  static inline bool c_nearly_eq(dtype x, dtype y) {
10
10
  return c_abs(c_sub(x,y)) <= (c_abs(x)+c_abs(y))*DBL_EPSILON*2;
11
11
  }
12
+
13
+ /* generates a random number on [0,1)-real-interval */
14
+ inline static dtype m_rand(dtype max)
15
+ {
16
+ dtype z;
17
+ REAL(z) = genrand_res53_mix() * REAL(max);
18
+ IMAG(z) = genrand_res53_mix() * IMAG(max);
19
+ return z;
20
+ }
@@ -6,6 +6,12 @@ typedef double rtype;
6
6
 
7
7
  #include "float_macro.h"
8
8
 
9
+ /* generates a random number on [0,1)-real-interval */
10
+ inline static dtype m_rand(dtype max)
11
+ {
12
+ return genrand_res53_mix() * max;
13
+ }
14
+
9
15
  #define m_min_init numo_dfloat_new_dim0(0.0/0.0)
10
16
  #define m_max_init numo_dfloat_new_dim0(0.0/0.0)
11
17
  #define m_extract(x) rb_float_new(*(double*)x)
@@ -30,11 +30,14 @@ EXTERN double pow(double, double);
30
30
 
31
31
  #define m_abs(x) fabs(x)
32
32
  #define m_minus(x) (-(x))
33
- #define m_inverse(x) (1/(x))
33
+ #define m_reciprocal(x) (1/(x))
34
34
  #define m_square(x) ((x)*(x))
35
35
  #define m_floor(x) floor(x)
36
36
  #define m_round(x) round(x)
37
37
  #define m_ceil(x) ceil(x)
38
+ #define m_trunc(x) trunc(x)
39
+ #define m_rint(x) rint(x)
40
+ #define m_sign(x) (((x)==0) ? 0.0:(((x)>0) ? 1.0:(((x)<0) ? -1.0:(x))))
38
41
 
39
42
  #define m_eq(x,y) ((x)==(y))
40
43
  #define m_ne(x,y) ((x)!=(y))
@@ -50,7 +53,6 @@ EXTERN double pow(double, double);
50
53
  #define m_mulsum(x,y,z) {z += x*y;}
51
54
  #define m_mulsum_init INT2FIX(0)
52
55
 
53
- #define m_rand to_res53(gen_rand64())
54
56
  #define m_rand_norm(a) rand_norm(a)
55
57
 
56
58
  #define m_sprintf(s,x) sprintf(s,"%g",x)
@@ -275,3 +277,8 @@ static inline size_t f_max_index(size_t n, char *p, ssize_t stride)
275
277
  }
276
278
  return j;
277
279
  }
280
+
281
+ static inline dtype f_seq(dtype x, dtype y, double c)
282
+ {
283
+ return x + y * c;
284
+ }