numo-narray 0.9.0.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +47 -0
  4. data/Rakefile +41 -0
  5. data/ext/numo/narray/SFMT-params.h +97 -0
  6. data/ext/numo/narray/SFMT-params19937.h +46 -0
  7. data/ext/numo/narray/SFMT.c +620 -0
  8. data/ext/numo/narray/SFMT.h +157 -0
  9. data/ext/numo/narray/array.c +525 -0
  10. data/ext/numo/narray/data.c +901 -0
  11. data/ext/numo/narray/depend.erb +33 -0
  12. data/ext/numo/narray/extconf.rb +117 -0
  13. data/ext/numo/narray/gen/bit.erb.c +811 -0
  14. data/ext/numo/narray/gen/cogen.rb +18 -0
  15. data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
  16. data/ext/numo/narray/gen/def/dfloat.rb +30 -0
  17. data/ext/numo/narray/gen/def/int16.rb +29 -0
  18. data/ext/numo/narray/gen/def/int32.rb +29 -0
  19. data/ext/numo/narray/gen/def/int64.rb +29 -0
  20. data/ext/numo/narray/gen/def/int8.rb +29 -0
  21. data/ext/numo/narray/gen/def/robject.rb +30 -0
  22. data/ext/numo/narray/gen/def/scomplex.rb +32 -0
  23. data/ext/numo/narray/gen/def/sfloat.rb +30 -0
  24. data/ext/numo/narray/gen/def/uint16.rb +29 -0
  25. data/ext/numo/narray/gen/def/uint32.rb +29 -0
  26. data/ext/numo/narray/gen/def/uint64.rb +29 -0
  27. data/ext/numo/narray/gen/def/uint8.rb +29 -0
  28. data/ext/numo/narray/gen/dtype.erb.c +328 -0
  29. data/ext/numo/narray/gen/tmpl/accum.c +36 -0
  30. data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
  31. data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
  32. data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
  33. data/ext/numo/narray/gen/tmpl/aref.c +51 -0
  34. data/ext/numo/narray/gen/tmpl/aset.c +61 -0
  35. data/ext/numo/narray/gen/tmpl/binary.c +53 -0
  36. data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
  37. data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
  38. data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
  39. data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
  40. data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
  41. data/ext/numo/narray/gen/tmpl/cast.c +37 -0
  42. data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
  43. data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
  44. data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
  45. data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
  46. data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
  47. data/ext/numo/narray/gen/tmpl/cum.c +42 -0
  48. data/ext/numo/narray/gen/tmpl/each.c +43 -0
  49. data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
  50. data/ext/numo/narray/gen/tmpl/extract.c +23 -0
  51. data/ext/numo/narray/gen/tmpl/eye.c +91 -0
  52. data/ext/numo/narray/gen/tmpl/fill.c +38 -0
  53. data/ext/numo/narray/gen/tmpl/format.c +60 -0
  54. data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
  55. data/ext/numo/narray/gen/tmpl/head.c +25 -0
  56. data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
  57. data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
  58. data/ext/numo/narray/gen/tmpl/median.c +44 -0
  59. data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
  60. data/ext/numo/narray/gen/tmpl/poly.c +49 -0
  61. data/ext/numo/narray/gen/tmpl/pow.c +74 -0
  62. data/ext/numo/narray/gen/tmpl/powint.c +17 -0
  63. data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
  64. data/ext/numo/narray/gen/tmpl/rand.c +33 -0
  65. data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
  66. data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
  67. data/ext/numo/narray/gen/tmpl/seq.c +61 -0
  68. data/ext/numo/narray/gen/tmpl/set2.c +56 -0
  69. data/ext/numo/narray/gen/tmpl/sort.c +36 -0
  70. data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
  71. data/ext/numo/narray/gen/tmpl/store.c +31 -0
  72. data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
  73. data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
  74. data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
  75. data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
  76. data/ext/numo/narray/gen/tmpl/unary.c +58 -0
  77. data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
  78. data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
  79. data/ext/numo/narray/index.c +822 -0
  80. data/ext/numo/narray/kwarg.c +79 -0
  81. data/ext/numo/narray/math.c +140 -0
  82. data/ext/numo/narray/narray.c +1539 -0
  83. data/ext/numo/narray/ndloop.c +1928 -0
  84. data/ext/numo/narray/numo/compat.h +23 -0
  85. data/ext/numo/narray/numo/intern.h +112 -0
  86. data/ext/numo/narray/numo/narray.h +411 -0
  87. data/ext/numo/narray/numo/ndloop.h +99 -0
  88. data/ext/numo/narray/numo/template.h +140 -0
  89. data/ext/numo/narray/numo/types/bit.h +19 -0
  90. data/ext/numo/narray/numo/types/complex.h +410 -0
  91. data/ext/numo/narray/numo/types/complex_macro.h +205 -0
  92. data/ext/numo/narray/numo/types/dcomplex.h +11 -0
  93. data/ext/numo/narray/numo/types/dfloat.h +12 -0
  94. data/ext/numo/narray/numo/types/float_def.h +34 -0
  95. data/ext/numo/narray/numo/types/float_macro.h +277 -0
  96. data/ext/numo/narray/numo/types/int16.h +12 -0
  97. data/ext/numo/narray/numo/types/int32.h +12 -0
  98. data/ext/numo/narray/numo/types/int64.h +12 -0
  99. data/ext/numo/narray/numo/types/int8.h +12 -0
  100. data/ext/numo/narray/numo/types/int_macro.h +34 -0
  101. data/ext/numo/narray/numo/types/robj_macro.h +218 -0
  102. data/ext/numo/narray/numo/types/robject.h +21 -0
  103. data/ext/numo/narray/numo/types/scomplex.h +11 -0
  104. data/ext/numo/narray/numo/types/sfloat.h +13 -0
  105. data/ext/numo/narray/numo/types/uint16.h +12 -0
  106. data/ext/numo/narray/numo/types/uint32.h +12 -0
  107. data/ext/numo/narray/numo/types/uint64.h +12 -0
  108. data/ext/numo/narray/numo/types/uint8.h +12 -0
  109. data/ext/numo/narray/numo/types/uint_macro.h +31 -0
  110. data/ext/numo/narray/numo/types/xint_macro.h +133 -0
  111. data/ext/numo/narray/rand.c +87 -0
  112. data/ext/numo/narray/step.c +506 -0
  113. data/ext/numo/narray/struct.c +872 -0
  114. data/lib/2.1/numo/narray.so +0 -0
  115. data/lib/2.2/numo/narray.so +0 -0
  116. data/lib/2.3/numo/narray.so +0 -0
  117. data/lib/erbpp.rb +286 -0
  118. data/lib/erbpp/line_number.rb +126 -0
  119. data/lib/erbpp/narray_def.rb +338 -0
  120. data/lib/numo/narray.rb +6 -0
  121. data/numo-narray.gemspec +35 -0
  122. data/spec/bit_spec.rb +93 -0
  123. data/spec/narray_spec.rb +249 -0
  124. metadata +238 -0
@@ -0,0 +1,18 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
4
+ $LOAD_PATH.unshift libpath
5
+
6
+ require "erbpp/narray_def"
7
+ if ARGV[0] == "-l"
8
+ require "erbpp/line_number"
9
+ ARGV.shift
10
+ end
11
+
12
+ unless (1..2) === ARGV.size
13
+ puts "usage:\n ruby #{$0} [-l] erb_path [type_file]"
14
+ exit 1
15
+ end
16
+
17
+ erb_path, type_file = ARGV
18
+ DataType.new(erb_path, type_file).run
@@ -0,0 +1,32 @@
1
+ class_name "DComplex"
2
+ class_alias "Complex128"
3
+ ctype "dcomplex"
4
+ real_class_name "DFloat"
5
+ real_ctype "double"
6
+
7
+ has_math true
8
+ is_bit false
9
+ is_int false
10
+ is_float true
11
+ is_real false
12
+ is_complex true
13
+ is_object false
14
+ is_comparable false
15
+
16
+ upcast_rb "Integer"
17
+ upcast_rb "Float"
18
+ upcast_rb "Complex"
19
+
20
+ upcast "RObject", "RObject"
21
+ upcast "DComplex", "DComplex"
22
+ upcast "SComplex", "DComplex"
23
+ upcast "DFloat", "DComplex"
24
+ upcast "SFloat", "DComplex"
25
+ upcast "Int64", "DComplex"
26
+ upcast "Int32", "DComplex"
27
+ upcast "Int16", "DComplex"
28
+ upcast "Int8", "DComplex"
29
+ upcast "UInt64", "DComplex"
30
+ upcast "UInt32", "DComplex"
31
+ upcast "UInt16", "DComplex"
32
+ upcast "UInt8", "DComplex"
@@ -0,0 +1,30 @@
1
+ class_name "DFloat"
2
+ class_alias "Float64"
3
+ ctype "double"
4
+
5
+ has_math true
6
+ is_bit false
7
+ is_int false
8
+ is_float true
9
+ is_complex false
10
+ is_object false
11
+ is_real true
12
+ is_comparable true
13
+
14
+ upcast_rb "Integer"
15
+ upcast_rb "Float"
16
+ upcast_rb "Complex", "DComplex"
17
+
18
+ upcast "RObject", "RObject"
19
+ upcast "DComplex", "DComplex"
20
+ upcast "SComplex", "DComplex"
21
+ upcast "DFloat", "DFloat"
22
+ upcast "SFloat", "DFloat"
23
+ upcast "Int64", "DFloat"
24
+ upcast "Int32", "DFloat"
25
+ upcast "Int16", "DFloat"
26
+ upcast "Int8", "DFloat"
27
+ upcast "UInt64", "DFloat"
28
+ upcast "UInt32", "DFloat"
29
+ upcast "UInt16", "DFloat"
30
+ upcast "UInt8", "DFloat"
@@ -0,0 +1,29 @@
1
+ class_name "Int16"
2
+ ctype "int16_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32", "Int32"
24
+ upcast "Int16"
25
+ upcast "Int8"
26
+ upcast "UInt64", "Int64"
27
+ upcast "UInt32", "Int32"
28
+ upcast "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,29 @@
1
+ class_name "Int32"
2
+ ctype "int32_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32"
24
+ upcast "Int16"
25
+ upcast "Int8"
26
+ upcast "UInt64", "Int64"
27
+ upcast "UInt32"
28
+ upcast "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,29 @@
1
+ class_name "Int64"
2
+ ctype "int64_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64"
23
+ upcast "Int32"
24
+ upcast "Int16"
25
+ upcast "Int8"
26
+ upcast "UInt64"
27
+ upcast "UInt32"
28
+ upcast "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,29 @@
1
+ class_name "Int8"
2
+ ctype "int8_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32", "Int32"
24
+ upcast "Int16", "Int16"
25
+ upcast "Int8", "Int8"
26
+ upcast "UInt64", "Int64"
27
+ upcast "UInt32", "Int64"
28
+ upcast "UInt16", "Int32"
29
+ upcast "UInt8", "Int16"
@@ -0,0 +1,30 @@
1
+ class_name "RObject"
2
+ ctype "VALUE"
3
+ real_class_name "RObject"
4
+ real_ctype "VALUE"
5
+
6
+ has_math false
7
+ is_bit false
8
+ is_int true
9
+ is_float true
10
+ is_real false
11
+ is_complex false
12
+ is_object true
13
+ is_comparable true
14
+
15
+ upcast_rb "Integer"
16
+ upcast_rb "Float"
17
+ upcast_rb "Complex"
18
+
19
+ upcast "DComplex", "RObject"
20
+ upcast "SComplex", "RObject"
21
+ upcast "DFloat", "RObject"
22
+ upcast "SFloat", "RObject"
23
+ upcast "Int64", "RObject"
24
+ upcast "Int32", "RObject"
25
+ upcast "Int16", "RObject"
26
+ upcast "Int8", "RObject"
27
+ upcast "UInt64", "RObject"
28
+ upcast "UInt32", "RObject"
29
+ upcast "UInt16", "RObject"
30
+ upcast "UInt8", "RObject"
@@ -0,0 +1,32 @@
1
+ class_name "SComplex"
2
+ class_alias "Complex64"
3
+ ctype "scomplex"
4
+ real_class_name "SFloat"
5
+ real_ctype "float"
6
+
7
+ has_math true
8
+ is_bit false
9
+ is_int false
10
+ is_float true
11
+ is_real false
12
+ is_complex true
13
+ is_object false
14
+ is_comparable false
15
+
16
+ upcast_rb "Integer"
17
+ upcast_rb "Float"
18
+ upcast_rb "Complex"
19
+
20
+ upcast "RObject", "RObject"
21
+ upcast "DComplex", "DComplex"
22
+ upcast "SComplex", "SComplex"
23
+ upcast "DFloat", "DComplex"
24
+ upcast "SFloat", "SComplex"
25
+ upcast "Int64", "SComplex"
26
+ upcast "Int32", "SComplex"
27
+ upcast "Int16", "SComplex"
28
+ upcast "Int8", "SComplex"
29
+ upcast "UInt64", "SComplex"
30
+ upcast "UInt32", "SComplex"
31
+ upcast "UInt16", "SComplex"
32
+ upcast "UInt8", "SComplex"
@@ -0,0 +1,30 @@
1
+ class_name "SFloat"
2
+ class_alias "Float32"
3
+ ctype "float"
4
+
5
+ has_math true
6
+ is_bit false
7
+ is_int false
8
+ is_float true
9
+ is_complex false
10
+ is_object false
11
+ is_real true
12
+ is_comparable true
13
+
14
+ upcast_rb "Integer"
15
+ upcast_rb "Float"
16
+ upcast_rb "Complex", "SComplex"
17
+
18
+ upcast "RObject", "RObject"
19
+ upcast "DComplex", "DComplex"
20
+ upcast "SComplex", "SComplex"
21
+ upcast "DFloat", "DFloat"
22
+ upcast "SFloat", "SFloat"
23
+ upcast "Int64", "SFloat"
24
+ upcast "Int32", "SFloat"
25
+ upcast "Int16", "SFloat"
26
+ upcast "Int8", "SFloat"
27
+ upcast "UInt64", "SFloat"
28
+ upcast "UInt32", "SFloat"
29
+ upcast "UInt16", "SFloat"
30
+ upcast "UInt8", "SFloat"
@@ -0,0 +1,29 @@
1
+ class_name "UInt16"
2
+ ctype "u_int16_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32", "Int32"
24
+ upcast "Int16", "Int16"
25
+ upcast "Int8", "Int16"
26
+ upcast "UInt64", "UInt64"
27
+ upcast "UInt32", "UInt32"
28
+ upcast "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,29 @@
1
+ class_name "UInt32"
2
+ ctype "u_int32_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32", "Int32"
24
+ upcast "Int16", "Int32"
25
+ upcast "Int8", "Int32"
26
+ upcast "UInt64", "UInt64"
27
+ upcast "UInt32"
28
+ upcast "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,29 @@
1
+ class_name "UInt64"
2
+ ctype "u_int64_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32", "Int64"
24
+ upcast "Int16", "Int64"
25
+ upcast "Int8", "Int64"
26
+ upcast "UInt64"
27
+ upcast "UInt32"
28
+ upcast "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,29 @@
1
+ class_name "UInt8"
2
+ ctype "u_int8_t"
3
+
4
+ has_math false
5
+ is_bit false
6
+ is_int true
7
+ is_float false
8
+ is_complex false
9
+ is_object false
10
+ is_real true
11
+ is_comparable true
12
+
13
+ upcast_rb "Integer"
14
+ upcast_rb "Float", "DFloat"
15
+ upcast_rb "Complex", "DComplex"
16
+
17
+ upcast "RObject", "RObject"
18
+ upcast "DComplex", "DComplex"
19
+ upcast "SComplex", "SComplex"
20
+ upcast "DFloat", "DFloat"
21
+ upcast "SFloat", "SFloat"
22
+ upcast "Int64", "Int64"
23
+ upcast "Int32", "Int32"
24
+ upcast "Int16", "Int16"
25
+ upcast "Int8", "Int8"
26
+ upcast "UInt64", "UInt64"
27
+ upcast "UInt32", "UInt32"
28
+ upcast "UInt16", "UInt16"
29
+ upcast "UInt8"
@@ -0,0 +1,328 @@
1
+ /*
2
+ <%=type_name%>.c
3
+ Numerical Array Extension for Ruby
4
+ (C) Copyright 1999-2011,2013 by Masahiro TANAKA
5
+
6
+ This program is free software.
7
+ You can distribute/modify this program
8
+ under the same terms as Ruby itself.
9
+ NO WARRANTY.
10
+ */
11
+
12
+ #include <ruby.h>
13
+ #include <math.h>
14
+ #include "numo/narray.h"
15
+ #include "numo/template.h"
16
+ #include "SFMT.h"
17
+
18
+ #define m_map(x) m_num_to_data(rb_yield(m_data_to_num(x)))
19
+
20
+ <%
21
+ def_id "cast"
22
+ def_id "eq"
23
+ def_id "ne"
24
+ def_id "pow"
25
+ def_id "mulsum"
26
+ if is_complex
27
+ def_id "real"
28
+ def_id "imag"
29
+ else
30
+ def_id "divmod"
31
+ end
32
+ if is_float
33
+ def_id "nearly_eq"
34
+ end
35
+ if is_comparable
36
+ def_id "gt"
37
+ def_id "ge"
38
+ def_id "lt"
39
+ def_id "le"
40
+ end
41
+ if is_object
42
+ def_id "bit_and"
43
+ def_id "bit_or"
44
+ def_id "bit_xor"
45
+ def_id "bit_not"
46
+ def_id "abs"
47
+ def_id "minus"
48
+ def_id "inverse"
49
+ def_id "square"
50
+ def_id "floor"
51
+ def_id "round"
52
+ def_id "ceil"
53
+ def_id "nan?"
54
+ def_id "infinite?"
55
+ def_id "finite?"
56
+ def_id ">" ,"op_gt"
57
+ def_id ">=","op_ge"
58
+ def_id "<" ,"op_lt"
59
+ def_id "<=","op_le"
60
+ end
61
+ %>
62
+
63
+ <% IdVar.declaration.each do |x| %><%=
64
+ x %>
65
+ <% end %>
66
+
67
+ #include "numo/types/<%=type_name%>.h"
68
+
69
+ VALUE cT;
70
+ extern VALUE cRT;
71
+ #ifdef mTM
72
+ VALUE mTM;
73
+ #endif
74
+
75
+ <%
76
+ if is_object
77
+ def_allocate "robj_allocate"
78
+ end
79
+ def_method "allocate", 0
80
+
81
+ def_method "extract", 0
82
+ store_numeric
83
+ cast_array
84
+ store_array
85
+ if is_complex
86
+ store_from "DComplex","dcomplex","m_from_dcomplex"
87
+ store_from "SComplex","scomplex","m_from_scomplex"
88
+ end
89
+ store_from "DFloat","double", "m_from_real"
90
+ store_from "SFloat","float", "m_from_real"
91
+ store_from "Int64", "int64_t", "m_from_real"
92
+ store_from "Int32", "int32_t", "m_from_real"
93
+ store_from "Int16", "int16_t", "m_from_real"
94
+ store_from "Int8", "int8_t", "m_from_real"
95
+ store_from "UInt64","u_int64_t","m_from_real"
96
+ store_from "UInt32","u_int32_t","m_from_real"
97
+ store_from "UInt16","u_int16_t","m_from_real"
98
+ store_from "UInt8", "u_int8_t", "m_from_real"
99
+
100
+ def_method "store", 1
101
+ def_singleton "cast", 1
102
+
103
+ def_method "aref", -1, "aref", :op=>"[]"
104
+ def_method "aset", -1, "aset", :op=>"[]="
105
+
106
+ def_method "coerce_cast", 1
107
+ def_method "to_a", 0
108
+ def_method "fill", 1
109
+ def_method "format", -1
110
+ def_method "format_to_a", -1
111
+ def_method "inspect", 0
112
+
113
+ def_method "each", 0
114
+ unary "map"
115
+ def_method "each_with_index", 0
116
+ def_method "map_with_index", 0
117
+
118
+ # Arithmetic
119
+
120
+ unary2 "abs", "rtype", "cRT"
121
+
122
+ binary "add", "+"
123
+ binary "sub", "-"
124
+ binary "mul", "*"
125
+ binary "div", "/"
126
+
127
+ if !is_complex
128
+ binary "mod", "%"
129
+ binary2 "divmod"
130
+ end
131
+
132
+ pow
133
+
134
+ unary "minus", "-@"
135
+ unary "inverse"
136
+
137
+ # Complex
138
+
139
+ if is_complex
140
+ unary "conj"
141
+ unary "im"
142
+ unary2 "real", "rtype", "cRT"
143
+ unary2 "imag", "rtype", "cRT"
144
+ unary2 "arg", "rtype", "cRT"
145
+ def_alias "angle","arg"
146
+ set2 "set_imag", "rtype", "cRT"
147
+ set2 "set_real", "rtype", "cRT"
148
+ def_alias "imag=","set_imag"
149
+ def_alias "real=","set_real"
150
+ else
151
+ def_alias "conj", "copy"
152
+ def_alias "im", "copy"
153
+ end
154
+
155
+ def_alias "conjugate","conj"
156
+
157
+ # base_cond
158
+
159
+ cond_binary "eq"
160
+ cond_binary "ne"
161
+
162
+ # nearly_eq : x=~y is true if |x-y| <= (|x|+|y|)*epsilon
163
+ if is_float
164
+ cond_binary "nearly_eq"
165
+ else
166
+ def_alias "nearly_eq", "eq"
167
+ end
168
+ def_alias "close_to", "nearly_eq"
169
+
170
+ # Integer
171
+ if is_int
172
+ binary "bit_and", "&"
173
+ binary "bit_or" , "|"
174
+ binary "bit_xor", "^"
175
+ unary "bit_not", "~"
176
+ def_alias "floor", "copy"
177
+ def_alias "round", "copy"
178
+ def_alias "ceil", "copy"
179
+ end
180
+
181
+ if is_float && is_real
182
+ unary "floor"
183
+ unary "round"
184
+ unary "ceil"
185
+ end
186
+
187
+ if is_comparable
188
+ cond_binary "gt"
189
+ cond_binary "ge"
190
+ cond_binary "lt"
191
+ cond_binary "le"
192
+ def_alias ">", "gt"
193
+ def_alias ">=","ge"
194
+ def_alias "<", "lt"
195
+ def_alias "<=","le"
196
+ end
197
+
198
+ # Float
199
+
200
+ if is_float
201
+ cond_unary "isnan"
202
+ cond_unary "isinf"
203
+ cond_unary "isfinite"
204
+ end
205
+
206
+ accum "sum","dtype","cT"
207
+ accum "prod","dtype","cT"
208
+
209
+ if is_float
210
+ accum "mean","dtype","cT"
211
+ accum "stddev","rtype","cRT"
212
+ accum "var","rtype","cRT"
213
+ accum "rms","rtype","cRT"
214
+ end
215
+
216
+ if is_comparable
217
+ accum "min","dtype","cT"
218
+ accum "max","dtype","cT"
219
+ accum_index "max_index"
220
+ accum_index "min_index"
221
+ def_method "minmax",-1
222
+ end
223
+
224
+ cum "cumsum","add"
225
+ cum "cumprod","mul"
226
+
227
+ # dot
228
+ accum_binary "mulsum"
229
+
230
+ # rmsdev
231
+ # prod
232
+
233
+ # shuffle
234
+ # histogram
235
+
236
+ def_method "seq",-1
237
+ def_method "eye",-1
238
+ def_alias "indgen", "seq"
239
+
240
+ if !is_object
241
+ def_method "rand", 0
242
+ end
243
+
244
+ # y = a[0] + a[1]*x + a[2]*x^2 + a[3]*x^3 + ... + a[n]*x^n
245
+ def_method "poly",-2
246
+
247
+ if is_comparable && !is_object
248
+ qsort type_name,"dtype","*(dtype*)"
249
+ def_method "sort",-1
250
+ qsort type_name+"_index","dtype*","**(dtype**)"
251
+ def_method "sort_index",-1
252
+ def_method "median",-1
253
+ end
254
+
255
+ # Math
256
+ # histogram
257
+
258
+ if has_math
259
+ math "sqrt"
260
+ math "cbrt"
261
+ math "log"
262
+ math "log2"
263
+ math "log10"
264
+ math "exp"
265
+ math "exp2"
266
+ math "exp10"
267
+ math "sin"
268
+ math "cos"
269
+ math "tan"
270
+ math "asin"
271
+ math "acos"
272
+ math "atan"
273
+ math "sinh"
274
+ math "cosh"
275
+ math "tanh"
276
+ math "asinh"
277
+ math "acosh"
278
+ math "atanh"
279
+ if !is_complex
280
+ math "atan2",2
281
+ math "hypot",2
282
+ math "erf"
283
+ math "erfc"
284
+ math "ldexp",2
285
+ end
286
+ end
287
+ %>
288
+ static VALUE <%= find_tmpl('store').c_func %>(VALUE,VALUE);
289
+ <%
290
+ Function.codes.each do |x| %>
291
+ <%= x %>
292
+ <% end %>
293
+
294
+ void
295
+ Init_nary_<%=tp%>()
296
+ {
297
+ volatile VALUE hCast;
298
+
299
+ cT = rb_define_class_under(mNumo, "<%=class_name%>", cNArray);
300
+ <% for x in class_alias %>
301
+ // alias of <%=class_name%>
302
+ rb_define_const(mNumo, "<%=x%>", <%=type_var%>);
303
+ <% end %>
304
+ <% if has_math %>
305
+ mTM = rb_define_module_under(cT, "Math"); <% end %>
306
+
307
+ rb_define_const(cT, ELEMENT_BIT_SIZE, INT2FIX(sizeof(dtype)*8));
308
+ rb_define_const(cT, ELEMENT_BYTE_SIZE, INT2FIX(sizeof(dtype)));
309
+ rb_define_const(cT, CONTIGUOUS_STRIDE, INT2FIX(sizeof(dtype)));
310
+
311
+ rb_define_singleton_method(cT, "[]", <%=cast_func%>, -2);
312
+
313
+ <% if is_object %>
314
+ rb_undef_method(rb_singleton_class(cT),"from_string");
315
+ rb_undef_method(cT,"to_string");
316
+ <% end %>
317
+
318
+ <% Function.definitions.each do |x| %>
319
+ <%= x %><% end %>
320
+ <% IdVar.assignment.each do |x| %>
321
+ <%= x %><% end %>
322
+
323
+ hCast = rb_hash_new();
324
+ rb_define_const(cT, "UPCAST", hCast);
325
+ rb_hash_aset(hCast, rb_cArray, cT);
326
+ <% for x in upcast %>
327
+ <%= x %><% end %>
328
+ }