narray 0.5.9.4
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.
- data/src/ChangeLog +614 -0
- data/src/MANIFEST +82 -0
- data/src/README.en +54 -0
- data/src/README.ja +63 -0
- data/src/SPEC.en +300 -0
- data/src/SPEC.ja +284 -0
- data/src/depend +14 -0
- data/src/extconf.rb +111 -0
- data/src/lib/narray_ext.rb +211 -0
- data/src/lib/nmatrix.rb +244 -0
- data/src/mkmath.rb +780 -0
- data/src/mknafunc.rb +190 -0
- data/src/mkop.rb +638 -0
- data/src/na_array.c +644 -0
- data/src/na_func.c +1624 -0
- data/src/na_index.c +988 -0
- data/src/na_linalg.c +616 -0
- data/src/na_random.c +409 -0
- data/src/narray.c +1308 -0
- data/src/narray.def +29 -0
- data/src/narray.h +170 -0
- data/src/narray_local.h +210 -0
- data/src/nimage/README.en +38 -0
- data/src/nimage/demo/fits.rb +97 -0
- data/src/nimage/demo/fits_convol.rb +28 -0
- data/src/nimage/demo/fits_fftdemo.rb +27 -0
- data/src/nimage/demo/fitsdemo1.rb +13 -0
- data/src/nimage/demo/fitsdemo2.rb +30 -0
- data/src/nimage/demo/fitsdemo3.rb +26 -0
- data/src/nimage/demo/fitsmorph.rb +39 -0
- data/src/nimage/demo/life_na.rb +57 -0
- data/src/nimage/demo/mandel.rb +41 -0
- data/src/nimage/extconf.rb +12 -0
- data/src/nimage/lib/nimage.rb +51 -0
- data/src/nimage/nimage.c +328 -0
- data/src/speed/add.py +12 -0
- data/src/speed/add.rb +8 -0
- data/src/speed/add_int.py +12 -0
- data/src/speed/add_int.rb +9 -0
- data/src/speed/lu.m +14 -0
- data/src/speed/lu.rb +22 -0
- data/src/speed/mat.m +23 -0
- data/src/speed/mat.rb +28 -0
- data/src/speed/mul.py +12 -0
- data/src/speed/mul.rb +9 -0
- data/src/speed/mul2.py +15 -0
- data/src/speed/mul2.rb +13 -0
- data/src/speed/mul_comp.py +12 -0
- data/src/speed/mul_comp.rb +9 -0
- data/src/speed/mul_int.py +12 -0
- data/src/speed/mul_int.rb +9 -0
- data/src/speed/mybench.py +15 -0
- data/src/speed/mybench.rb +31 -0
- data/src/speed/solve.m +18 -0
- data/src/speed/solve.py +16 -0
- data/src/speed/solve.rb +21 -0
- data/src/test/statistics.rb +22 -0
- data/src/test/testarray.rb +20 -0
- data/src/test/testbit.rb +27 -0
- data/src/test/testcast.rb +14 -0
- data/src/test/testcomplex.rb +35 -0
- data/src/test/testfftw.rb +16 -0
- data/src/test/testindex.rb +11 -0
- data/src/test/testindexary.rb +26 -0
- data/src/test/testindexset.rb +55 -0
- data/src/test/testmask.rb +40 -0
- data/src/test/testmath.rb +48 -0
- data/src/test/testmath2.rb +46 -0
- data/src/test/testmatrix.rb +13 -0
- data/src/test/testmatrix2.rb +33 -0
- data/src/test/testmatrix3.rb +19 -0
- data/src/test/testminmax.rb +46 -0
- data/src/test/testobject.rb +29 -0
- data/src/test/testpow.rb +19 -0
- data/src/test/testrandom.rb +23 -0
- data/src/test/testround.rb +11 -0
- data/src/test/testsort.rb +37 -0
- data/src/test/teststr.rb +13 -0
- data/src/test/testtrans.rb +18 -0
- data/src/test/testwhere.rb +27 -0
- metadata +127 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# NArray demo : life game
|
2
|
+
# by Masahiro Tanaka <masa@ir.isas.ac.jp> 2001-01-18
|
3
|
+
|
4
|
+
require 'narray'
|
5
|
+
require 'nimage'
|
6
|
+
|
7
|
+
class NArray
|
8
|
+
def magnify(n)
|
9
|
+
src = shape.collect{|x| [1,x]}.flatten
|
10
|
+
dst = shape.collect{|x| [n,x]}.flatten
|
11
|
+
a = NArray.new(typecode,*dst)
|
12
|
+
a[*[true]*(rank*2)] = self.reshape(*src)
|
13
|
+
a.reshape!(*NArray[*shape]*n)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class LifeGame
|
18
|
+
def initialize(nx,ny)
|
19
|
+
@d = NArray.byte(nx,ny)
|
20
|
+
w = 50
|
21
|
+
@d[nx/2-w,ny/2-w] = NArray.byte(w*2+1,w*2+1).random!(2)
|
22
|
+
@step = 0
|
23
|
+
@win = NImage.show @d #.magnify(2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def life_step
|
27
|
+
sum =
|
28
|
+
@d[0..-3,0..-3] + @d[0..-3,1..-2] + @d[0..-3,2..-1] +
|
29
|
+
@d[1..-2,0..-3] + @d[1..-2,2..-1] +
|
30
|
+
@d[2..-1,0..-3] + @d[2..-1,1..-2] + @d[2..-1,2..-1]
|
31
|
+
@d[1,1] =
|
32
|
+
(sum.eq 3) | ((sum.eq 2) & @d[1..-2,1..-2])
|
33
|
+
@step += 1
|
34
|
+
@win.update( (@d*(NImage.ncolors-1)).to_s )
|
35
|
+
end
|
36
|
+
|
37
|
+
def close
|
38
|
+
@win.close
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :step
|
42
|
+
end
|
43
|
+
|
44
|
+
srand(1)
|
45
|
+
a = LifeGame.new(200,200)
|
46
|
+
|
47
|
+
print "Hit return key to start..."
|
48
|
+
STDIN.getc
|
49
|
+
|
50
|
+
begin
|
51
|
+
loop{ a.life_step }
|
52
|
+
ensure
|
53
|
+
printf "step=%i\n",a.step
|
54
|
+
print "Hit return key..."
|
55
|
+
STDIN.getc
|
56
|
+
a.close
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# NArray demo : Mandelbrot
|
2
|
+
|
3
|
+
require 'narray'
|
4
|
+
|
5
|
+
def mandel(w,h)
|
6
|
+
zoom=3.5
|
7
|
+
|
8
|
+
z = ( NArray.scomplex(w,1).indgen!/w-0.65 )*zoom +
|
9
|
+
( NArray.scomplex(1,h).indgen!/h-0.5 )*(zoom*1.im)
|
10
|
+
c = z.dup
|
11
|
+
a = NArray.sint(h,w)
|
12
|
+
idx = NArray.int(h,w).indgen!
|
13
|
+
|
14
|
+
for i in 1..30
|
15
|
+
z = z**2+c
|
16
|
+
idx_t,idx_f = (z.abs>2).where2
|
17
|
+
print i," size=",idx_t.size,"\n"
|
18
|
+
ii = idx[idx_t]
|
19
|
+
a[ii] = i
|
20
|
+
break if idx_f.size==0
|
21
|
+
idx = idx[idx_f]
|
22
|
+
z = z[idx_f]
|
23
|
+
c = c[idx_f]
|
24
|
+
end
|
25
|
+
a
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
#
|
30
|
+
# TEST TEST TEST
|
31
|
+
#
|
32
|
+
if __FILE__ == $0
|
33
|
+
|
34
|
+
require 'nimage'
|
35
|
+
|
36
|
+
win = NImage.show mandel(400,400)
|
37
|
+
|
38
|
+
print "Hit return key..."
|
39
|
+
STDIN.getc
|
40
|
+
win.close
|
41
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
# configure options:
|
4
|
+
# --with-x11-dir=path
|
5
|
+
# --with-x11-include=path
|
6
|
+
# --with-x11-lib=path
|
7
|
+
dir_config("x11")
|
8
|
+
|
9
|
+
#have_header("X11/Xlib.h")
|
10
|
+
#have_header("X11/Xutil.h")
|
11
|
+
have_library("X11", "XOpenDisplay")
|
12
|
+
create_makefile("nimage_c")
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "narray"
|
2
|
+
require "nimage_c"
|
3
|
+
|
4
|
+
def NImage.show image
|
5
|
+
|
6
|
+
r1 = image.min
|
7
|
+
r2 = image.max
|
8
|
+
b = NArray.byte(*image.shape)
|
9
|
+
b[]= (image.to_f-r1)/(r2-r1)*(NImage.ncolors-1)
|
10
|
+
|
11
|
+
NImage.new b.to_s, *b.shape
|
12
|
+
end
|
13
|
+
|
14
|
+
def NImage.standard_color
|
15
|
+
ncol = 32/4
|
16
|
+
t = NArray.byte(ncol).indgen! * (255.0/ncol)
|
17
|
+
r = NArray.byte(ncol,4)
|
18
|
+
g = NArray.byte(ncol,4)
|
19
|
+
b = NArray.byte(ncol,4)
|
20
|
+
|
21
|
+
# Color map
|
22
|
+
r[0..-1,1] =
|
23
|
+
g[0..-1,2] =
|
24
|
+
b[0..-1,0] =
|
25
|
+
b[-1..0,1] =
|
26
|
+
b[0..-1,3] = t
|
27
|
+
r[0..-1,2] =
|
28
|
+
r[0..-1,3] =
|
29
|
+
g[0..-1,3] = 255
|
30
|
+
|
31
|
+
NImage.colormap r.to_s, g.to_s, b.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
# Initalize colormap
|
35
|
+
#NImage.standard_color
|
36
|
+
|
37
|
+
#
|
38
|
+
# TEST TEST TEST
|
39
|
+
#
|
40
|
+
if __FILE__ == $0
|
41
|
+
|
42
|
+
x = NArray.sfloat(200,1).indgen!(-100)/50*3.1415
|
43
|
+
y = NArray.sfloat(1,200).indgen!(-100)/50*3.1415
|
44
|
+
z = NMath.cos(x) * NMath.sin(y)
|
45
|
+
|
46
|
+
v = NImage.show z
|
47
|
+
|
48
|
+
print "Hit return key..."
|
49
|
+
STDIN.getc
|
50
|
+
v.close
|
51
|
+
end
|
data/src/nimage/nimage.c
ADDED
@@ -0,0 +1,328 @@
|
|
1
|
+
/*
|
2
|
+
NImage
|
3
|
+
--- A Ruby Extension Library for displaying Images on X11
|
4
|
+
(C) Copyright 2000 by Masahiro TANAKA
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <X11/Xlib.h>
|
9
|
+
#include <X11/Xutil.h>
|
10
|
+
#include "ruby.h"
|
11
|
+
|
12
|
+
static VALUE cNImage;
|
13
|
+
|
14
|
+
struct NIMG {
|
15
|
+
char *image;
|
16
|
+
int width;
|
17
|
+
int height;
|
18
|
+
Window window;
|
19
|
+
};
|
20
|
+
|
21
|
+
#define MAX_COLOR 256
|
22
|
+
|
23
|
+
static Display *display;
|
24
|
+
static GC gc=NULL;
|
25
|
+
static XColor color[MAX_COLOR];
|
26
|
+
|
27
|
+
static int ncolor = 32;
|
28
|
+
static int color_allocated = 0;
|
29
|
+
|
30
|
+
static void color_alloc_gray()
|
31
|
+
{
|
32
|
+
int i;
|
33
|
+
Colormap cmap;
|
34
|
+
|
35
|
+
cmap = DefaultColormap(display, 0);
|
36
|
+
for (i=0; i<ncolor; i++) {
|
37
|
+
color[i].red =
|
38
|
+
color[i].green =
|
39
|
+
color[i].blue = (i*65535)/ncolor;
|
40
|
+
if ( !XAllocColor( display, cmap, &color[i] ) )
|
41
|
+
rb_raise(rb_eRuntimeError, "ERROR: cannot allocate Color\n" );
|
42
|
+
}
|
43
|
+
color_allocated = 1;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
static void color_alloc(int n, char *r, char *g, char *b)
|
48
|
+
{
|
49
|
+
int i;
|
50
|
+
Colormap cmap;
|
51
|
+
|
52
|
+
cmap = DefaultColormap(display, 0);
|
53
|
+
for (i=0; i<n; i++) {
|
54
|
+
color[i].red = r[i]*256;
|
55
|
+
color[i].green = g[i]*256;
|
56
|
+
color[i].blue = b[i]*256;
|
57
|
+
if ( !XAllocColor( display, cmap, &color[i] ) )
|
58
|
+
rb_raise(rb_eRuntimeError, "ERROR: cannot allocate Color\n" );
|
59
|
+
}
|
60
|
+
ncolor = n;
|
61
|
+
color_allocated = 1;
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
static void color_free()
|
66
|
+
{
|
67
|
+
int i;
|
68
|
+
Colormap cmap;
|
69
|
+
|
70
|
+
if (color_allocated) {
|
71
|
+
cmap = DefaultColormap(display, 0);
|
72
|
+
for (i=0; i<ncolor; i++)
|
73
|
+
XFreeColors(display, cmap, &color[i].pixel, 1, 0);
|
74
|
+
color_allocated = 0;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE nimg_colormap(VALUE self, VALUE val_r, VALUE val_g, VALUE val_b)
|
79
|
+
{
|
80
|
+
char *r, *g, *b;
|
81
|
+
int nr, ng, nb, n;
|
82
|
+
|
83
|
+
r = RSTRING(val_r)->ptr;
|
84
|
+
nr = RSTRING(val_r)->len;
|
85
|
+
g = RSTRING(val_g)->ptr;
|
86
|
+
ng = RSTRING(val_g)->len;
|
87
|
+
b = RSTRING(val_b)->ptr;
|
88
|
+
nb = RSTRING(val_b)->len;
|
89
|
+
|
90
|
+
n = (nr<ng) ? nr:ng;
|
91
|
+
n = (n <nb) ? n :nb;
|
92
|
+
if (n > MAX_COLOR)
|
93
|
+
rb_raise(rb_eArgError, "exceed maximum # of colors");
|
94
|
+
|
95
|
+
color_free();
|
96
|
+
color_alloc(n,r,g,b);
|
97
|
+
XFlush(display);
|
98
|
+
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
static VALUE nimg_ncolors(VALUE self)
|
103
|
+
{
|
104
|
+
return INT2NUM(ncolor);
|
105
|
+
}
|
106
|
+
|
107
|
+
static XImage *create_ximage(struct NIMG *nimg)
|
108
|
+
{
|
109
|
+
XImage *image;
|
110
|
+
Visual *visual;
|
111
|
+
int malloc_len;
|
112
|
+
int depth;
|
113
|
+
|
114
|
+
depth = DefaultDepth(display, DefaultScreen(display));
|
115
|
+
visual = CopyFromParent;
|
116
|
+
|
117
|
+
image = XCreateImage( display, visual, depth,
|
118
|
+
ZPixmap, 0, 0, nimg->width, nimg->height,
|
119
|
+
32, 0 );
|
120
|
+
|
121
|
+
malloc_len = image->bytes_per_line * image->height;
|
122
|
+
image->data = (unsigned char*) malloc(malloc_len);
|
123
|
+
memset(image->data, 0, malloc_len);
|
124
|
+
|
125
|
+
return image;
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
static void nimg_put_image(struct NIMG *nimg)
|
130
|
+
{
|
131
|
+
XImage *ximage;
|
132
|
+
int i, j, k;
|
133
|
+
|
134
|
+
if (!color_allocated)
|
135
|
+
color_alloc_gray();
|
136
|
+
|
137
|
+
ximage = create_ximage(nimg);
|
138
|
+
|
139
|
+
k=0;
|
140
|
+
for (j=nimg->height-1; j>=0; j--)
|
141
|
+
for (i=0; i<nimg->width; i++)
|
142
|
+
XPutPixel(ximage, i,j, color[nimg->image[k++]].pixel);
|
143
|
+
|
144
|
+
XPutImage( display, nimg->window, gc,
|
145
|
+
ximage, 0, 0,
|
146
|
+
0,0, nimg->width, nimg->height );
|
147
|
+
|
148
|
+
XFlush(display);
|
149
|
+
XDestroyImage(ximage);
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
static void init_display(void)
|
154
|
+
{
|
155
|
+
display = XOpenDisplay( NULL );
|
156
|
+
if ( display==NULL )
|
157
|
+
rb_raise(rb_eRuntimeError, "ERROR: cannot open display\n");
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
static void init_wm(struct NIMG *nimg)
|
162
|
+
{
|
163
|
+
XTextProperty text;
|
164
|
+
XSizeHints size;
|
165
|
+
|
166
|
+
/* for window managers */
|
167
|
+
text.value = (unsigned char*)"NImage";
|
168
|
+
text.encoding = 31;
|
169
|
+
text.format = 8;
|
170
|
+
text.nitems = strlen( (char*)text.value );
|
171
|
+
|
172
|
+
size.flags = PPosition | PMinSize | PMaxSize;
|
173
|
+
/*size.flags = PPosition | PSize;*/
|
174
|
+
size.width =
|
175
|
+
size.min_width =
|
176
|
+
size.max_width = nimg->width;
|
177
|
+
size.height =
|
178
|
+
size.min_height =
|
179
|
+
size.max_height = nimg->height;
|
180
|
+
size.x = 0;
|
181
|
+
size.y = 0;
|
182
|
+
|
183
|
+
XSetWMProperties( display, nimg->window,
|
184
|
+
&text, &text, NULL, 0, &size, NULL, NULL );
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
static void show_window(Window window)
|
189
|
+
{
|
190
|
+
XEvent event;
|
191
|
+
/* show window */
|
192
|
+
XMapWindow( display, window );
|
193
|
+
do XNextEvent( display, &event );
|
194
|
+
while ( event.type != Expose );
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
static void nimg_init_window(struct NIMG *nimg)
|
199
|
+
{
|
200
|
+
int screen, depth;
|
201
|
+
Window parent, window;
|
202
|
+
Visual *visual;
|
203
|
+
XSetWindowAttributes attr;
|
204
|
+
unsigned long bgcolor;
|
205
|
+
unsigned long mask = CWBackingStore | CWEventMask;
|
206
|
+
unsigned long event_mask =
|
207
|
+
ExposureMask
|
208
|
+
| ButtonPressMask
|
209
|
+
| ButtonReleaseMask
|
210
|
+
| EnterWindowMask
|
211
|
+
| LeaveWindowMask
|
212
|
+
| KeyPressMask
|
213
|
+
| KeyReleaseMask
|
214
|
+
| PointerMotionMask
|
215
|
+
| StructureNotifyMask ;
|
216
|
+
|
217
|
+
screen = DefaultScreen( display );
|
218
|
+
parent = RootWindow( display, screen );
|
219
|
+
depth = DefaultDepth( display, screen );
|
220
|
+
visual = DefaultVisual( display, screen );
|
221
|
+
bgcolor = BlackPixel( display, screen );
|
222
|
+
|
223
|
+
attr.backing_store = /*Always*/ WhenMapped;
|
224
|
+
attr.event_mask = event_mask;
|
225
|
+
|
226
|
+
nimg->window =
|
227
|
+
XCreateWindow( display, parent,
|
228
|
+
0, 0, nimg->width, nimg->height,
|
229
|
+
1, depth, InputOutput, visual,
|
230
|
+
mask, &attr);
|
231
|
+
if (gc==NULL)
|
232
|
+
gc = XCreateGC( display, nimg->window, 0, 0 );
|
233
|
+
|
234
|
+
XSetWindowBackground( display, nimg->window, bgcolor );
|
235
|
+
|
236
|
+
init_wm( nimg );
|
237
|
+
show_window( nimg->window );
|
238
|
+
}
|
239
|
+
|
240
|
+
|
241
|
+
/* free contents */
|
242
|
+
static void
|
243
|
+
nimg_free(struct NIMG* nimg)
|
244
|
+
{
|
245
|
+
free( nimg->image );
|
246
|
+
free( nimg );
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
static VALUE
|
251
|
+
nimg_new( VALUE self, VALUE val_image, VALUE val_wid, VALUE val_hei )
|
252
|
+
{
|
253
|
+
struct NIMG *nimg;
|
254
|
+
char *data;
|
255
|
+
int i, len;
|
256
|
+
|
257
|
+
data = RSTRING(val_image)->ptr;
|
258
|
+
len = RSTRING(val_image)->len;
|
259
|
+
|
260
|
+
nimg = ALLOC( struct NIMG );
|
261
|
+
nimg->image = ALLOC_N( char, len );
|
262
|
+
MEMCPY( nimg->image, data, char, len );
|
263
|
+
|
264
|
+
nimg->width = NUM2INT(val_wid);
|
265
|
+
nimg->height = NUM2INT(val_hei);
|
266
|
+
|
267
|
+
if (len != nimg->width * nimg->height)
|
268
|
+
rb_raise(rb_eArgError, "Image size mismatch");
|
269
|
+
|
270
|
+
nimg_init_window(nimg);
|
271
|
+
nimg_put_image(nimg);
|
272
|
+
|
273
|
+
return Data_Wrap_Struct(cNImage, NULL, nimg_free, nimg);
|
274
|
+
}
|
275
|
+
|
276
|
+
|
277
|
+
static VALUE
|
278
|
+
nimg_update( VALUE self, VALUE val_image )
|
279
|
+
{
|
280
|
+
struct NIMG *nimg;
|
281
|
+
char *data;
|
282
|
+
int i, len;
|
283
|
+
|
284
|
+
Data_Get_Struct( self, struct NIMG, nimg );
|
285
|
+
data = RSTRING(val_image)->ptr;
|
286
|
+
len = RSTRING(val_image)->len;
|
287
|
+
|
288
|
+
if (len != nimg->width * nimg->height)
|
289
|
+
rb_raise(rb_eArgError, "Image size mismatch");
|
290
|
+
|
291
|
+
MEMCPY( nimg->image, data, char, len );
|
292
|
+
|
293
|
+
nimg_put_image(nimg);
|
294
|
+
return Qnil;
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
static VALUE
|
299
|
+
nimg_close( VALUE self )
|
300
|
+
{
|
301
|
+
struct NIMG *nimg;
|
302
|
+
|
303
|
+
Data_Get_Struct( self, struct NIMG, nimg );
|
304
|
+
XDestroyWindow( display, nimg->window );
|
305
|
+
nimg->window = 0;
|
306
|
+
XFlush( display );
|
307
|
+
return self;
|
308
|
+
}
|
309
|
+
|
310
|
+
|
311
|
+
void
|
312
|
+
Init_nimage_c()
|
313
|
+
{
|
314
|
+
/* open display, etc. */
|
315
|
+
init_display();
|
316
|
+
|
317
|
+
/* define NImage class */
|
318
|
+
cNImage = rb_define_class( "NImage", rb_cObject );
|
319
|
+
|
320
|
+
/* class methods */
|
321
|
+
rb_define_singleton_method( cNImage, "new", nimg_new, 3 );
|
322
|
+
rb_define_singleton_method( cNImage, "colormap", nimg_colormap, 3 );
|
323
|
+
rb_define_singleton_method( cNImage, "ncolors", nimg_ncolors, 0 );
|
324
|
+
|
325
|
+
/* method */
|
326
|
+
rb_define_method( cNImage, "update", nimg_update, 1 );
|
327
|
+
rb_define_method( cNImage, "close", nimg_close, 0 );
|
328
|
+
}
|
data/src/speed/add.py
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from mybench import *
|
2
|
+
|
3
|
+
a = bench_array()
|
4
|
+
b = bench_array()
|
5
|
+
|
6
|
+
print "a.typecode:",a.typecode(),", a.shape:",a.shape
|
7
|
+
print "b.typecode:",b.typecode(),", b.shape:",b.shape
|
8
|
+
print "calculating c = a+b ..."
|
9
|
+
|
10
|
+
def bench_body(a=a,b=b): c=a+b
|
11
|
+
|
12
|
+
bench_time(bench_body)
|
data/src/speed/add.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from mybench import *
|
2
|
+
|
3
|
+
a = arrayrange(ARRSZ)
|
4
|
+
b = arrayrange(ARRSZ)
|
5
|
+
|
6
|
+
print "a.typecode:",a.typecode(),", a.shape:",a.shape
|
7
|
+
print "b.typecode:",b.typecode(),", b.shape:",b.shape
|
8
|
+
print "calculating c = a+b ..."
|
9
|
+
|
10
|
+
def bench_body(a=a,b=b): c=a+b
|
11
|
+
|
12
|
+
bench_time(bench_body)
|
data/src/speed/lu.m
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# mesuring performance of Octave
|
2
|
+
|
3
|
+
n = 1000;
|
4
|
+
m = linspace(0,n*n-1,n*n);
|
5
|
+
m = rem(m, n+1) + 1;
|
6
|
+
m = reshape(m,n,n);
|
7
|
+
|
8
|
+
printf ("executing %ix%i LU...\n",n,n);
|
9
|
+
[t1, u1, s1] = cputime ();
|
10
|
+
[l,u,p] = lu(m);
|
11
|
+
[t2, u2, s2] = cputime ();
|
12
|
+
printf (" Time: %5.2f sec\n", u2 - u1);
|
13
|
+
# Time: 20.43 sec, GNU Octave, version 2.0.16 (sparc-sun-solaris2.7).
|
14
|
+
exit
|
data/src/speed/lu.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'mybench'
|
2
|
+
|
3
|
+
n = 1000
|
4
|
+
m = NArray.float(n,n).indgen!
|
5
|
+
m = m % (n+1) + 1
|
6
|
+
m = NMatrix.ref(m).transpose
|
7
|
+
|
8
|
+
puts 'm ='
|
9
|
+
p m
|
10
|
+
|
11
|
+
printf "executing %ix%i LU...\n",n,n
|
12
|
+
bench_time(1){lu = m.lu}
|
13
|
+
exit
|
14
|
+
|
15
|
+
puts 'lu='
|
16
|
+
p lu
|
17
|
+
puts 'y='
|
18
|
+
p y
|
19
|
+
puts 'm*y='
|
20
|
+
p m*y
|
21
|
+
|
22
|
+
#system "ps -v"
|
data/src/speed/mat.m
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# mesuring performance of Octave
|
2
|
+
|
3
|
+
n = 500;
|
4
|
+
|
5
|
+
a = linspace(0,n*n-1,n*n);
|
6
|
+
a = rem(a, n+1) + 1;
|
7
|
+
a = reshape(a,n,n);
|
8
|
+
|
9
|
+
b = linspace(0,n*n-1,n*n);
|
10
|
+
b = rem(b, n-1) + 1;
|
11
|
+
b = reshape(b,n,n);
|
12
|
+
|
13
|
+
printf ("executing product of %ix%i Matrix...\n",n,n);
|
14
|
+
printf ("c=a*b\n");
|
15
|
+
|
16
|
+
[t1, u1, s1] = cputime ();
|
17
|
+
c = a*b;
|
18
|
+
[t2, u2, s2] = cputime ();
|
19
|
+
|
20
|
+
printf (" Time: %f\n", u2 - u1);
|
21
|
+
# Time: 7.280000
|
22
|
+
# GNU Octave, version 2.0.16 (sparc-sun-solaris2.7).
|
23
|
+
exit
|
data/src/speed/mat.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mybench'
|
2
|
+
|
3
|
+
n = 500
|
4
|
+
|
5
|
+
a = NArray.float(n,n).indgen!
|
6
|
+
a = a % (n+1) + 1
|
7
|
+
a = NMatrix.ref(a)#.transpose
|
8
|
+
|
9
|
+
b = NArray.float(n,n).indgen!
|
10
|
+
b = b % (n-1) + 1
|
11
|
+
b = NMatrix.ref(b)#.transpose
|
12
|
+
|
13
|
+
c = 0
|
14
|
+
|
15
|
+
puts 'a='
|
16
|
+
p a
|
17
|
+
puts 'b='
|
18
|
+
p b
|
19
|
+
|
20
|
+
printf "executing %ix%i Matrix product...\n",n,n
|
21
|
+
puts 'c=a*b'
|
22
|
+
|
23
|
+
bench_time(1) { c=a*b }
|
24
|
+
|
25
|
+
# time: 4.21 sec
|
26
|
+
|
27
|
+
puts 'c='
|
28
|
+
p c
|
data/src/speed/mul.py
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from mybench import *
|
2
|
+
|
3
|
+
a = bench_array()
|
4
|
+
b = bench_array()
|
5
|
+
|
6
|
+
print "a.typecode:",a.typecode(),", a.shape:",a.shape
|
7
|
+
print "b.typecode:",b.typecode(),", b.shape:",b.shape
|
8
|
+
print "calculating c = a*b ..."
|
9
|
+
|
10
|
+
def bench_body(a=a,b=b): c=a*b
|
11
|
+
|
12
|
+
bench_time(bench_body)
|
data/src/speed/mul.rb
ADDED
data/src/speed/mul2.py
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
from mybench import *
|
2
|
+
|
3
|
+
a = reshape(arrayrange(1000),(1000,1)).astype(Float64)
|
4
|
+
b = reshape(arrayrange(1000),(1,1000)).astype(Float64)
|
5
|
+
|
6
|
+
print "a.typecode:",a.typecode(),", a.shape:",a.shape
|
7
|
+
print "b.typecode:",b.typecode(),", b.shape:",b.shape
|
8
|
+
print "calculating c = a*b ..."
|
9
|
+
|
10
|
+
def bench_body(a=a,b=b): c=a*b
|
11
|
+
|
12
|
+
bench_time(bench_body)
|
13
|
+
|
14
|
+
c = a*b
|
15
|
+
print "c.shape:", c.shape,"\n"
|
data/src/speed/mul2.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from mybench import *
|
2
|
+
|
3
|
+
a = bench_array(Complex64)
|
4
|
+
b = bench_array(Complex64)
|
5
|
+
|
6
|
+
print "a.typecode:",a.typecode(),", a.shape:",a.shape
|
7
|
+
print "b.typecode:",b.typecode(),", b.shape:",b.shape
|
8
|
+
print "calculating c = a*b ..."
|
9
|
+
|
10
|
+
def bench_body(a=a,b=b): c=a*b
|
11
|
+
|
12
|
+
bench_time(bench_body)
|