numru-narray 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README_NARRAY.en ADDED
@@ -0,0 +1,49 @@
1
+ Ruby/NArray ver 0.6.0.0 (2011-08-27) by Masahiro TANAKA
2
+
3
+ * NArray properties:
4
+
5
+ + Fast and easy calculation for large numerical array.
6
+ + Accepting Elements:
7
+ 8,16,32 bit integer, single/double float/complex, Ruby Object.
8
+ + Easy extraction/substitution of array subset,
9
+ using assignment with number, range, array index.
10
+ + Operator: +,-,*,/,%,**, etc.
11
+ + FFTW version 2 or 3 is separately supported.
12
+ + NImage: Image viewer class.
13
+ + Ruby/PGPLOT: Graphics library interface (separately distributed)
14
+ X-Y Graph, Histogram, Contour map, Image map, etc.
15
+
16
+ * NArray is similar to:
17
+
18
+ + Python/NumPy, Perl/PDL, Yorick, IDL
19
+
20
+ * NArray is far from completed!
21
+
22
+ + Experimental! Specification may be changed.
23
+ + Far from completed.
24
+ + Bugs may be included.
25
+ + No document.
26
+
27
+ * Installation
28
+
29
+ + Compile & Install NArray
30
+
31
+ ruby extconf.rb
32
+ make
33
+ make install
34
+
35
+ * Tested Platform
36
+
37
+ ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
38
+ gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
39
+
40
+ * License
41
+
42
+ This program is free software.
43
+ You can distribute/modify this program
44
+ under the same terms as Ruby itself.
45
+ NO WARRANTY.
46
+
47
+ * Author
48
+
49
+ Masahiro TANAKA <masa16.tanaka@gmail.com>
data/README_NARRAY.ja ADDED
@@ -0,0 +1,52 @@
1
+ Ruby/NArray ver 0.6.0.0 (2011-08-27) by Masahiro TANAKA
2
+
3
+ * Ruby/NArrayの特徴。
4
+
5
+ + Rubyで、高速な数値計算が可能。
6
+ + 要素には、8,16,32 bit 整数、単精度/倍精度の実数/複素数、
7
+ および Rubyオブジェクトをサポート。
8
+ + 部分配列の取出し、代入も容易。
9
+ 要素位置の指定には、数値、範囲、インデックスの配列が使用可能。
10
+ + +,-,*,/,%,** や 算術関数の演算は、要素-対-要素でおこなう。
11
+ + 配列同士の演算・代入は、各次元のサイズが同じであることが必要。
12
+ ただし、サイズが1の次元は、他方の配列のサイズに合わせて
13
+ 「繰り返し」同じ要素が適用される。
14
+ + FFTW (高速フーリエ変換) version 3 は次のモジュールでサポート。
15
+ + NImage (X11イメージ表示) クラス附属。(nimage/ ディレクトリ参照)
16
+ + Ruby/PGPLOT (グラフィックスライブラリ、別悃) にて
17
+ XYグラフ、ヒストグラム、等高線、イメージ表示可能。
18
+ + 数値計算・画像処理・データ解析など幅広い応用が可能(と思う)。
19
+
20
+ * 類似品
21
+
22
+ + Python/NumPy, Perl/PDL, Yorick, IDL
23
+
24
+ * 不十分な点
25
+
26
+ + メソッドが不足。
27
+ + バグ出しが不十分。
28
+ + ドキュメントがない。
29
+
30
+ * インストール方法
31
+
32
+ Rubyの標準的な拡張ライブラリと同じです。ソースを展開したディレクトリで、
33
+
34
+ ruby extconf.rb
35
+ make
36
+ make install
37
+
38
+ と実行します。
39
+
40
+ * 動作確認
41
+
42
+ ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
43
+ gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)
44
+
45
+ * 配布条件
46
+
47
+ Rubyのライセンスに準拠します。
48
+
49
+ * 著者
50
+
51
+ 田中昌宏
52
+ ご意見,バグレポートその他は masa16.tanaka@gmail.com までお願いします。
data/SPEC.en ADDED
@@ -0,0 +1,327 @@
1
+
2
+ Ruby/NArray ver 0.6.0.7 (2013-02-01) by Masahiro TANAKA
3
+
4
+
5
+ Class method:
6
+ NArray.new(typecode, size, ...) create new NArray. initialize with 0.
7
+
8
+ NArray.byte(size,...) 1 byte unsigned integer
9
+ NArray.sint(size,...) 2 byte signed integer
10
+ NArray.int(size,...) 4 byte signed integer
11
+ NArray.sfloat(size,...) single precision float
12
+ NArray.float(size,...) double precision float
13
+ NArray.scomplex(size,...) single precision complex
14
+ NArray.complex(size,...) double precision complex
15
+ NArray.object(size,...) Ruby object
16
+ all above method initialize with 0 or nil.
17
+
18
+ NArray.to_na(array) convert to NArray
19
+ NArray.to_na(string,type[,size,...])
20
+ NArray[...]
21
+ NArray[1,5,10.0] #=> NArray.float(3):[1.0, 5.0, 10.0]
22
+ NArray[1..10] #=> NArray.int(10):[1,2,3,4,5,6,7,8,9,10]
23
+
24
+
25
+ Class constant:
26
+ CLASS_DIMENSION # of dimension treated as data.
27
+ 0 for NArray, 1 for NVector, 2 for NMatrix.
28
+
29
+ NArray information
30
+ self.dim Return the dimension = the number of indices
31
+ self.rank same as dim
32
+ self.shape Return the array of sizes of each index
33
+ self.total Return the number of total elements
34
+
35
+ Slicing Array
36
+ - Index components: Integer, Range, Array, true.
37
+ - Index order: FORTRAN type.
38
+ a[ 1, 2, -1 ] element slicing.
39
+ If negative, counts backward from the end.
40
+ Element-dimensions are contracted.
41
+ a[ 0..3, 4..1 ] extract in the range.
42
+ If the former of the range is bigger,
43
+ return elements in reversed order.
44
+ a[ [1,3,2,4] ] an array with the elements of the indices.
45
+ If `a' has multi-dimension but, in [],
46
+ single index is specified,
47
+ `a' is treated as a single dimension array.
48
+ a[ 1, 2..3, [1,3,2,4], true ] compound index.
49
+ This returns 3-dim array.
50
+ a[] same as a.dup.
51
+ a[ 0, true ] sams as a[0,0..-1]. `true' means all.
52
+ a[ false, 0 ] same as a[true,true,0], if a is a 3-d array,
53
+ `false' means ellipsis dimension.
54
+ a[ mask ] masking. "mask" is a byte NArray with its
55
+ length equal to that of "a". According to the
56
+ value of each element of mask, the corresponding
57
+ element in "a" is eliminated (when 0) or
58
+ retained (when not 0).
59
+ Example:
60
+ a=NArray.float(2,2).indgen!
61
+ p a[ a.lt 3 ]
62
+ --> [ 0.0, 1.0, 2.0 ]
63
+ (Here, a.lt 3 gives a byte NArray)
64
+ (This is also done by a[ (a.lt 3).where ])
65
+
66
+ - A 2-or-more-dim array object with only one argument in `[ ]',
67
+ is treated as a flat 1-d array.
68
+ e.g.: a[3] is same as a[0,1] if a is 3x3 array.
69
+
70
+ - self.slice(...) Same as self[...] but keeps the rank of
71
+ original array by not elimiting dimensions
72
+ whose length became equal to 1 (which self[]
73
+ does). This is not the case with the
74
+ 1-dimensional indexing and masking (same as []).
75
+
76
+ Replacing Elements -- Same rule as slicing
77
+
78
+ a[ 1, 2, 3 ] = 1
79
+ a[ 0..3, 1..4, 2..5 ] = 2
80
+ a[ [1,3,2,4], true ] = 3
81
+ a[] = 4 Same as a.fill!(4)
82
+
83
+ a[0..2] = b[1..5] --> Error! due to different num of elements.
84
+ a[1,2] = b[0..2,1..3] Storing elements from index [1,2]
85
+ ( a[1,2]=b[0,1],a[2,2]=b[1,1],... )
86
+ a[0..2,0..3] = b[0..2,1] Storing repetitively
87
+ ( a[0,0]=b[0,1],..,a[0,3]=b[0,1] )
88
+
89
+ Delete row/columns -- Complement of slice
90
+
91
+ self.delete_at(...) Arguments are the same as the [] and slice methods
92
+ see https://github.com/masa16/narray/issues/5
93
+
94
+ Filling values
95
+ self.indgen!([start[,step]]) Generate index;
96
+ Set values from 'start' with 'step' increment
97
+ self.fill!(value) Fill elements with 'value'
98
+ self.random!(max) Set random values between 0<=x<max
99
+ using MT19337
100
+ self.randomn Set Normally distributed random values
101
+ with mean=0, dispersion=1 (Box-Muller)
102
+ NArray.srand([seed]) Set random seed.
103
+ A time-depend seed is choosed if omitted.
104
+
105
+ Operation: performed element by element
106
+ a = NArray.float(3,3).indgen
107
+ b = NArray.float(3,3).fill(10)
108
+ c = a*b # --> NArray.float(3,3)
109
+
110
+ a = NArray.float(3,1).indgen
111
+ b = NArray.float(1,3).fill(10)
112
+ c = a*b # --> NArray.float(3,3) -- size=1 dimension is extensible.
113
+
114
+ Arithmetic operator
115
+ -self
116
+ self + other
117
+ self - other
118
+ self * other
119
+ self / other
120
+ self % other
121
+ self ** other
122
+ self.abs
123
+
124
+ self.add! other
125
+ self.sbt! other
126
+ self.mul! other
127
+ self.div! other
128
+ self.mod! other
129
+
130
+ Bitwise operator (only for integers)
131
+ ~self
132
+ self & other
133
+ self | other
134
+ self ^ other
135
+
136
+ Comparison
137
+ -- element-wise comparison, results in BYTE-type NArray;
138
+ Note that not true nor false is returned.
139
+ self.eq other (distinguish from == operator; see below )
140
+ self.ne other
141
+ self.gt other
142
+ self > other
143
+ self.ge other
144
+ self >= other
145
+ self.lt other
146
+ self < other
147
+ self.le other
148
+ self <= other
149
+
150
+ self.and other element-wise condition.
151
+ self.or other
152
+ self.xor other
153
+ self.not other
154
+
155
+ self.all? true if all the elements are true.
156
+ self.any? true if any element is true.
157
+ self.none? true if none of the element is true.
158
+ self.where Return NArray of indices where elements are true.
159
+ self.where2 Return Array including two NArrays of indices,
160
+ where elements are true and false, respectively.
161
+
162
+ e.g.: idx_t,idx_f = (a>12).where2
163
+
164
+ Equivalence
165
+ NArray[1] == NArray[1] #=> true
166
+ NArray[1] == NArray[1.0] #=> true
167
+ NArray[1].eql? NArray[1] #=> true
168
+ NArray[1].eql? NArray[1.0] #=> false
169
+ NArray[1].equal? NArray[1] #=> false
170
+ a=b=NArray[1]; a.equal? b #=> true
171
+
172
+ Statistics
173
+ self.sum(dim,..) Summation
174
+ self.cumsum Cumulative Summation (for 1-d array)
175
+ self.prod(dim,..) Product (Multiply elements)
176
+ self.cumprod Cumulative Produce (for 1-d array)
177
+ self.mean(dim,..) Mean
178
+ self.stddev(dim,..) Standard deviation
179
+ self.rms(dim,..) Root mean square
180
+ self.rmsdev(dim,..) Root mean square deviation
181
+ self.min(dim,..) Minimum
182
+ self.max(dim,..) Maximum
183
+ note: * If dimensions are specified, statistics are performed
184
+ on those dimensions and the rest dimensions are kept.
185
+ * Range can be used.
186
+ * If dimension is not specified, statistics are performed
187
+ for all the elements.
188
+ self.median(dim) Median in 0..dim (All dimensions if omitted)
189
+
190
+ Sort
191
+ self.sort(dim) Sort in 0..dim (All dimensions if omitted)
192
+ self.sort_index(dim) Return index of Sort result.
193
+ self[self.sort_index] equals to self.sort.
194
+
195
+ Transpose
196
+ self.transpose( dim0, dim1, .. )
197
+ Transpose array.
198
+ The dim0-th dimension goes to the 0-th dimension of new array.
199
+ Negative number counts backward.
200
+ transpose(-1,1..-2,0) is replacement between the first and the last.
201
+
202
+ Changing Shapes of indices
203
+ self.reshape!(size,...)
204
+ self.shape=(size,...)
205
+ self.newdim=(dim) Insert new dimension with size=1
206
+
207
+ Reference to another NArray
208
+ self.refer create NArray obj referring to another NArray
209
+ self.reshape(size,...) same as self.refer.reshape!
210
+ self.newdim(dim,...) same as self.refer.newdim!
211
+
212
+ Reverse and Rotate
213
+ self.reverse([dim,...]) Reverse array at axes
214
+ self.rot90([k]) Rotate array by 90 degrees k times
215
+
216
+ Type conversion
217
+ self.floor Return integer NArray whose elements processed 'floor'
218
+ self.ceil
219
+ self.round
220
+ self.to_f Convert NArray type to float
221
+ self.to_i Convert NArray type to integer
222
+ self.to_a Convert NArray type to Ruby-object
223
+ self.to_s Convert NArray data to String as a binary data.
224
+ self.to_string Convert NArray type to Ruby-object
225
+ containing Strings as printed elements
226
+
227
+ Iteration
228
+ self.each {|i| ...}
229
+ self.collect {|i| ...}
230
+ self.collect! {|i| ...}
231
+
232
+ Byte swap
233
+ self.swap_byte swap byte order
234
+ self.hton convert to network byte order
235
+ self.ntoh
236
+ self.htov convert to VAX byte order
237
+ self.vtoh
238
+
239
+ Boolean / mask related
240
+ self.count_false count # of elements whose value == 0 (only for
241
+ byte type)
242
+ self.count_true count # of elements whose value != 0 (only for
243
+ byte type)
244
+ self.mask( mask ) same as self[ mask ], but exclusively for masking.
245
+ Unlike [], a int or sint mask is accepted.
246
+
247
+ Complex compound number
248
+ self.real
249
+ self.imag
250
+ self.conj
251
+ self.conj!
252
+ self.angle atan2(self.imag, self.real)
253
+ self.imag= other set imaginary part
254
+ self.im multiply by imaginary unit
255
+
256
+ NMath module
257
+ sqrt(x)
258
+ exp(x)
259
+ log(x)
260
+ log10(x)
261
+ log2(x)
262
+ atan2(x,y)
263
+ sin,cos,tan
264
+ sinh,cosh,tanh
265
+ asin,acos,atan
266
+ asinh,acosh,atanh
267
+ csc,sec,cot
268
+ csch,sech,coth
269
+ acsc,asec,acot
270
+ acsch,asech,acoth
271
+ covariance (no idea why NMath::covariance doesn't work)
272
+
273
+
274
+ FFTW module
275
+ (separate module)
276
+ fftw(x,[1|-1])
277
+ convol(a,b) convolution with FFTW
278
+
279
+
280
+ NMatrix
281
+
282
+ Subclass of NArray. First 2 dimensions are used as Matrix.
283
+ Residual dimensions are treated as Multi-dimensional array.
284
+ The order of Matrix dimensions is opposite from
285
+ the notation of mathematics: a_ij => a[j,i]
286
+
287
+ Methods:
288
+ +,- enable if other is NMatrix.
289
+ * Matrix product if other is NMatrix or NVector.
290
+ Scalar product if other is Numeric or NArray.
291
+ ex: NMatrix[[1,2],[3,4]] * [1,10]
292
+ == NMatrix[ [[1,2],[3,4]], [[10,20],[30,40]] ]
293
+ / Scalar division if other is Numeric or NArray.
294
+ Solve Linear Equation with LU factorization
295
+ if other is square NMatrix. a/b == b.lu.solve(a)
296
+
297
+ transpose transpose Matrix dimensions if argument omitted.
298
+ diagonal(val)
299
+ diagonal!(val) set val to diagonal elements. (set 1 if omitted)
300
+ unit set 1 to diagonal elements.
301
+ inverse Inverse matrix.
302
+ lu compute LU factorization.
303
+ return NMatrixLU class object.
304
+
305
+ NVector
306
+
307
+ Subclass of NArray. First 1 dimension is used as Vector.
308
+ Residual dimensions are treated as Multi-dimensional array.
309
+
310
+ Methods:
311
+ +,- enable if other is NVector.
312
+ * Matrix product if other is NMatrix.
313
+ Inner product if other is NVector.
314
+ Scalar product if other is Numeric or NArray.
315
+ / Scalar division if other is Numeric or NArray.
316
+ Solve Linear Equation with LU factorization
317
+ if other is square NMatrix. v/m == m.lu.solve(v)
318
+
319
+
320
+ NMatrixLU
321
+
322
+ Created by NMatrix#lu method.
323
+ Including LU (NMatrix) and pivot (NVector).
324
+
325
+ Methods:
326
+ solve(other) Solve with the result of LU factorization.
327
+ other should be NMatrix or NVector instance.