narray 0.5.9.4 → 0.5.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/src/ChangeLog +29 -0
- data/src/MANIFEST +7 -36
- data/src/README.en +1 -5
- data/src/README.ja +1 -2
- data/src/SPEC.en +15 -8
- data/src/SPEC.ja +5 -2
- data/src/bench/all.rb +88 -0
- data/src/bench/bench.m +61 -0
- data/src/bench/bench.py +89 -0
- data/src/bench/bench.rb +59 -0
- data/src/bench/dummy.m +0 -0
- data/src/bench/dummy.py +13 -0
- data/src/bench/dummy.rb +0 -0
- data/src/lib/narray_ext.rb +36 -2
- data/src/mkmath.rb +4 -4
- data/src/mkop.rb +16 -16
- data/src/na_array.c +32 -32
- data/src/na_func.c +50 -50
- data/src/na_index.c +26 -32
- data/src/na_linalg.c +23 -26
- data/src/na_random.c +15 -18
- data/src/narray.c +22 -32
- data/src/narray.h +3 -3
- data/src/narray_local.h +1 -1
- metadata +10 -39
- data/src/nimage/README.en +0 -38
- data/src/nimage/demo/fits.rb +0 -97
- data/src/nimage/demo/fits_convol.rb +0 -28
- data/src/nimage/demo/fits_fftdemo.rb +0 -27
- data/src/nimage/demo/fitsdemo1.rb +0 -13
- data/src/nimage/demo/fitsdemo2.rb +0 -30
- data/src/nimage/demo/fitsdemo3.rb +0 -26
- data/src/nimage/demo/fitsmorph.rb +0 -39
- data/src/nimage/demo/life_na.rb +0 -57
- data/src/nimage/demo/mandel.rb +0 -41
- data/src/nimage/extconf.rb +0 -12
- data/src/nimage/lib/nimage.rb +0 -51
- data/src/nimage/nimage.c +0 -328
- data/src/speed/add.py +0 -12
- data/src/speed/add.rb +0 -8
- data/src/speed/add_int.py +0 -12
- data/src/speed/add_int.rb +0 -9
- data/src/speed/lu.m +0 -14
- data/src/speed/lu.rb +0 -22
- data/src/speed/mat.m +0 -23
- data/src/speed/mat.rb +0 -28
- data/src/speed/mul.py +0 -12
- data/src/speed/mul.rb +0 -9
- data/src/speed/mul2.py +0 -15
- data/src/speed/mul2.rb +0 -13
- data/src/speed/mul_comp.py +0 -12
- data/src/speed/mul_comp.rb +0 -9
- data/src/speed/mul_int.py +0 -12
- data/src/speed/mul_int.rb +0 -9
- data/src/speed/mybench.py +0 -15
- data/src/speed/mybench.rb +0 -31
- data/src/speed/solve.m +0 -18
- data/src/speed/solve.py +0 -16
- data/src/speed/solve.rb +0 -21
data/src/nimage/demo/mandel.rb
DELETED
@@ -1,41 +0,0 @@
|
|
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
|
data/src/nimage/extconf.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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")
|
data/src/nimage/lib/nimage.rb
DELETED
@@ -1,51 +0,0 @@
|
|
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
DELETED
@@ -1,328 +0,0 @@
|
|
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
DELETED
@@ -1,12 +0,0 @@
|
|
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)
|