*** empty log message ***
[bpt/guile.git] / libguile / ramap.c
CommitLineData
7dc6e754 1/* Copyright (C) 1996, 1998 Free Software Foundation, Inc.
0f2d19dd
JB
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
82892bed
JB
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
0f2d19dd
JB
17 *
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
82892bed 40 * If you do not wish that, delete this exception notice. */
0f2d19dd
JB
41\f
42
43
44\f
45
46#include <stdio.h>
47#include "_scm.h"
20e6290e
JB
48#include "unif.h"
49#include "smob.h"
50#include "chars.h"
51#include "eq.h"
52#include "eval.h"
53#include "feature.h"
0f2d19dd 54
20e6290e 55#include "ramap.h"
0f2d19dd
JB
56\f
57
0f2d19dd
JB
58typedef struct
59{
60 char *name;
61 SCM sproc;
62 int (*vproc) ();
63} ra_iproc;
64
ad310508
MD
65
66/* These tables are a kluge that will not scale well when more
67 * vectorized subrs are added. It is tempting to steal some bits from
68 * the SCM_CAR of all subrs (like those selected by SCM_SMOBNUM) to hold an
69 * offset into a table of vectorized subrs.
70 */
71
72static ra_iproc ra_rpsubrs[] =
73{
74 {"=", SCM_UNDEFINED, scm_ra_eqp},
75 {"<", SCM_UNDEFINED, scm_ra_lessp},
76 {"<=", SCM_UNDEFINED, scm_ra_leqp},
77 {">", SCM_UNDEFINED, scm_ra_grp},
78 {">=", SCM_UNDEFINED, scm_ra_greqp},
79 {0, 0, 0}
80};
81
82static ra_iproc ra_asubrs[] =
83{
84 {"+", SCM_UNDEFINED, scm_ra_sum},
85 {"-", SCM_UNDEFINED, scm_ra_difference},
86 {"*", SCM_UNDEFINED, scm_ra_product},
87 {"/", SCM_UNDEFINED, scm_ra_divide},
88 {0, 0, 0}
89};
90
0f2d19dd
JB
91
92#define BVE_REF(a, i) ((SCM_VELTS(a)[(i)/SCM_LONG_BIT] & (1L<<((i)%SCM_LONG_BIT))) ? 1 : 0)
93#define BVE_SET(a, i) (SCM_VELTS(a)[(i)/SCM_LONG_BIT] |= (1L<<((i)%SCM_LONG_BIT)))
94#define BVE_CLR(a, i) (SCM_VELTS(a)[(i)/SCM_LONG_BIT] &= ~(1L<<((i)%SCM_LONG_BIT)))
95
96/* Fast, recycling scm_vector ref */
97#define RVREF(ra, i, e) (e = scm_cvref(ra, i, e))
98
99/* #define RVREF(ra, i, e) (scm_cvref(ra, i, SCM_UNDEFINED)) to turn off */
100
101/* IVDEP means "ignore scm_vector dependencies", meaning we guarantee that
102 elements of scm_vector operands are not aliased */
103#ifdef _UNICOS
104#define IVDEP(test, line) if (test) {_Pragma("ivdep"); line} else {line}
105#else
106#define IVDEP(test, line) line
107#endif
108
109\f
110
111/* inds must be a uvect or ivect, no check. */
112
1cc91f1b
JB
113
114static scm_sizet cind SCM_P ((SCM ra, SCM inds));
115
0f2d19dd
JB
116static scm_sizet
117cind (ra, inds)
118 SCM ra;
119 SCM inds;
0f2d19dd
JB
120{
121 scm_sizet i;
122 int k;
123 long *ve = SCM_VELTS (inds);
124 if (!SCM_ARRAYP (ra))
125 return *ve;
126 i = SCM_ARRAY_BASE (ra);
127 for (k = 0; k < SCM_ARRAY_NDIM (ra); k++)
128 i += (ve[k] - SCM_ARRAY_DIMS (ra)[k].lbnd) * SCM_ARRAY_DIMS (ra)[k].inc;
129 return i;
130}
131
132
133/* Checker for scm_array mapping functions:
134 return values: 4 --> shapes, increments, and bases are the same;
135 3 --> shapes and increments are the same;
136 2 --> shapes are the same;
137 1 --> ras are at least as big as ra0;
138 0 --> no match.
139 */
1cc91f1b 140
0f2d19dd
JB
141int
142scm_ra_matchp (ra0, ras)
143 SCM ra0;
144 SCM ras;
0f2d19dd
JB
145{
146 SCM ra1;
147 scm_array_dim dims;
148 scm_array_dim *s0 = &dims;
149 scm_array_dim *s1;
150 scm_sizet bas0 = 0;
151 int i, ndim = 1;
152 int exact = 2 /* 4 */ ; /* Don't care about values >2 (yet?) */
ff467021 153 if (SCM_IMP (ra0)) return 0;
0f2d19dd
JB
154 switch (SCM_TYP7 (ra0))
155 {
156 default:
157 return 0;
158 case scm_tc7_vector:
95f5b0f5 159 case scm_tc7_wvect:
0f2d19dd 160 case scm_tc7_string:
b1d24656 161 case scm_tc7_byvect:
0f2d19dd
JB
162 case scm_tc7_bvect:
163 case scm_tc7_uvect:
164 case scm_tc7_ivect:
05f92e0f 165 case scm_tc7_svect:
5c11cc9d 166#ifdef HAVE_LONG_LONGS
05f92e0f
JB
167 case scm_tc7_llvect:
168#endif
0f2d19dd
JB
169 case scm_tc7_fvect:
170 case scm_tc7_dvect:
171 case scm_tc7_cvect:
172 s0->lbnd = 0;
173 s0->inc = 1;
174 s0->ubnd = (long) SCM_LENGTH (ra0) - 1;
175 break;
176 case scm_tc7_smob:
177 if (!SCM_ARRAYP (ra0))
178 return 0;
179 ndim = SCM_ARRAY_NDIM (ra0);
180 s0 = SCM_ARRAY_DIMS (ra0);
181 bas0 = SCM_ARRAY_BASE (ra0);
182 break;
183 }
184 while SCM_NIMP
185 (ras)
186 {
187 ra1 = SCM_CAR (ras);
ff467021
JB
188 if (SCM_IMP (ra1))
189 return 0;
0f2d19dd
JB
190 switch SCM_TYP7
191 (ra1)
192 {
193 default:
194 return 0;
195 case scm_tc7_vector:
95f5b0f5 196 case scm_tc7_wvect:
0f2d19dd 197 case scm_tc7_string:
b1d24656 198 case scm_tc7_byvect:
0f2d19dd
JB
199 case scm_tc7_bvect:
200 case scm_tc7_uvect:
201 case scm_tc7_ivect:
05f92e0f 202 case scm_tc7_svect:
5c11cc9d 203#ifdef HAVE_LONG_LONGS
05f92e0f
JB
204 case scm_tc7_llvect:
205#endif
0f2d19dd
JB
206 case scm_tc7_fvect:
207 case scm_tc7_dvect:
208 case scm_tc7_cvect:
209 if (1 != ndim)
210 return 0;
211 switch (exact)
212 {
213 case 4:
214 if (0 != bas0)
215 exact = 3;
216 case 3:
217 if (1 != s0->inc)
218 exact = 2;
219 case 2:
220 if ((0 == s0->lbnd) && (s0->ubnd == SCM_LENGTH (ra1) - 1))
221 break;
222 exact = 1;
223 case 1:
224 if (s0->lbnd < 0 || s0->ubnd >= SCM_LENGTH (ra1))
225 return 0;
226 }
227 break;
228 case scm_tc7_smob:
229 if (!SCM_ARRAYP (ra1) || ndim != SCM_ARRAY_NDIM (ra1))
230 return 0;
231 s1 = SCM_ARRAY_DIMS (ra1);
232 if (bas0 != SCM_ARRAY_BASE (ra1))
233 exact = 3;
234 for (i = 0; i < ndim; i++)
235 switch (exact)
236 {
237 case 4:
238 case 3:
239 if (s0[i].inc != s1[i].inc)
240 exact = 2;
241 case 2:
242 if (s0[i].lbnd == s1[i].lbnd && s0[i].ubnd == s1[i].ubnd)
243 break;
244 exact = 1;
245 default:
246 if (s0[i].lbnd < s1[i].lbnd || s0[i].ubnd > s1[i].ubnd)
247 return (s0[i].lbnd <= s0[i].ubnd ? 0 : 1);
248 }
249 break;
250 }
251 ras = SCM_CDR (ras);
252 }
253 return exact;
254}
255
1d7bdb25 256/* array mapper: apply cproc to each dimension of the given arrays?. */
0f2d19dd
JB
257int
258scm_ramapc (cproc, data, ra0, lra, what)
1d7bdb25 259 int (*cproc) (); /* procedure to call on unrolled arrays?
5c11cc9d
GH
260 cproc (dest, source list) or
261 cproc (dest, data, source list). */
262 SCM data; /* data to give to cproc or unbound. */
263 SCM ra0; /* destination array. */
264 SCM lra; /* list of source arrays. */
265 const char *what; /* caller, for error reporting. */
0f2d19dd
JB
266{
267 SCM inds, z;
268 SCM vra0, ra1, vra1;
269 SCM lvra, *plvra;
270 long *vinds;
271 int k, kmax;
272 switch (scm_ra_matchp (ra0, lra))
273 {
274 default:
275 case 0:
5c11cc9d 276 scm_wta (ra0, "array shape mismatch", what);
0f2d19dd
JB
277 case 2:
278 case 3:
279 case 4: /* Try unrolling arrays */
280 kmax = (SCM_ARRAYP (ra0) ? SCM_ARRAY_NDIM (ra0) - 1 : 0);
281 if (kmax < 0)
282 goto gencase;
283 vra0 = scm_array_contents (ra0, SCM_UNDEFINED);
ff467021 284 if (SCM_IMP (vra0)) goto gencase;
0f2d19dd
JB
285 if (!SCM_ARRAYP (vra0))
286 {
287 vra1 = scm_make_ra (1);
288 SCM_ARRAY_BASE (vra1) = 0;
289 SCM_ARRAY_DIMS (vra1)->lbnd = 0;
290 SCM_ARRAY_DIMS (vra1)->ubnd = SCM_LENGTH (vra0) - 1;
291 SCM_ARRAY_DIMS (vra1)->inc = 1;
292 SCM_ARRAY_V (vra1) = vra0;
293 vra0 = vra1;
294 }
295 lvra = SCM_EOL;
296 plvra = &lvra;
297 for (z = lra; SCM_NIMP (z); z = SCM_CDR (z))
298 {
299 ra1 = SCM_CAR (z);
300 vra1 = scm_make_ra (1);
301 SCM_ARRAY_DIMS (vra1)->lbnd = SCM_ARRAY_DIMS (vra0)->lbnd;
302 SCM_ARRAY_DIMS (vra1)->ubnd = SCM_ARRAY_DIMS (vra0)->ubnd;
303 if (!SCM_ARRAYP (ra1))
304 {
305 SCM_ARRAY_BASE (vra1) = 0;
306 SCM_ARRAY_DIMS (vra1)->inc = 1;
307 SCM_ARRAY_V (vra1) = ra1;
308 }
309 else if (!SCM_ARRAY_CONTP (ra1))
310 goto gencase;
311 else
312 {
313 SCM_ARRAY_BASE (vra1) = SCM_ARRAY_BASE (ra1);
314 SCM_ARRAY_DIMS (vra1)->inc = SCM_ARRAY_DIMS (ra1)[kmax].inc;
315 SCM_ARRAY_V (vra1) = SCM_ARRAY_V (ra1);
316 }
317 *plvra = scm_cons (vra1, SCM_EOL);
25d8012c 318 plvra = SCM_CDRLOC (*plvra);
0f2d19dd
JB
319 }
320 return (SCM_UNBNDP (data) ? cproc(vra0, lvra) : cproc(vra0, data, lvra));
321 case 1:
322 gencase: /* Have to loop over all dimensions. */
323 vra0 = scm_make_ra (1);
ff467021 324 if (SCM_ARRAYP (ra0))
0f2d19dd
JB
325 {
326 kmax = SCM_ARRAY_NDIM (ra0) - 1;
327 if (kmax < 0)
328 {
329 SCM_ARRAY_DIMS (vra0)->lbnd = 0;
330 SCM_ARRAY_DIMS (vra0)->ubnd = 0;
331 SCM_ARRAY_DIMS (vra0)->inc = 1;
332 }
333 else
334 {
335 SCM_ARRAY_DIMS (vra0)->lbnd = SCM_ARRAY_DIMS (ra0)[kmax].lbnd;
336 SCM_ARRAY_DIMS (vra0)->ubnd = SCM_ARRAY_DIMS (ra0)[kmax].ubnd;
337 SCM_ARRAY_DIMS (vra0)->inc = SCM_ARRAY_DIMS (ra0)[kmax].inc;
338 }
339 SCM_ARRAY_BASE (vra0) = SCM_ARRAY_BASE (ra0);
340 SCM_ARRAY_V (vra0) = SCM_ARRAY_V (ra0);
341 }
342 else
343 {
344 kmax = 0;
345 SCM_ARRAY_DIMS (vra0)->lbnd = 0;
346 SCM_ARRAY_DIMS (vra0)->ubnd = SCM_LENGTH (ra0) - 1;
347 SCM_ARRAY_DIMS (vra0)->inc = 1;
348 SCM_ARRAY_BASE (vra0) = 0;
349 SCM_ARRAY_V (vra0) = ra0;
350 ra0 = vra0;
351 }
352 lvra = SCM_EOL;
353 plvra = &lvra;
354 for (z = lra; SCM_NIMP (z); z = SCM_CDR (z))
355 {
356 ra1 = SCM_CAR (z);
357 vra1 = scm_make_ra (1);
358 SCM_ARRAY_DIMS (vra1)->lbnd = SCM_ARRAY_DIMS (vra0)->lbnd;
359 SCM_ARRAY_DIMS (vra1)->ubnd = SCM_ARRAY_DIMS (vra0)->ubnd;
ff467021 360 if (SCM_ARRAYP (ra1))
0f2d19dd
JB
361 {
362 if (kmax >= 0)
363 SCM_ARRAY_DIMS (vra1)->inc = SCM_ARRAY_DIMS (ra1)[kmax].inc;
364 SCM_ARRAY_V (vra1) = SCM_ARRAY_V (ra1);
365 }
366 else
367 {
368 SCM_ARRAY_DIMS (vra1)->inc = 1;
369 SCM_ARRAY_V (vra1) = ra1;
370 }
371 *plvra = scm_cons (vra1, SCM_EOL);
25d8012c 372 plvra = SCM_CDRLOC (*plvra);
0f2d19dd
JB
373 }
374 inds = scm_make_uve (SCM_ARRAY_NDIM (ra0), SCM_MAKINUM (-1L));
375 vinds = (long *) SCM_VELTS (inds);
376 for (k = 0; k <= kmax; k++)
377 vinds[k] = SCM_ARRAY_DIMS (ra0)[k].lbnd;
378 k = kmax;
379 do
380 {
381 if (k == kmax)
382 {
383 SCM y = lra;
384 SCM_ARRAY_BASE (vra0) = cind (ra0, inds);
385 for (z = lvra; SCM_NIMP (z); z = SCM_CDR (z), y = SCM_CDR (y))
386 SCM_ARRAY_BASE (SCM_CAR (z)) = cind (SCM_CAR (y), inds);
387 if (0 == (SCM_UNBNDP (data) ? cproc(vra0, lvra) : cproc(vra0, data, lvra)))
388 return 0;
389 k--;
390 continue;
391 }
392 if (vinds[k] < SCM_ARRAY_DIMS (ra0)[k].ubnd)
393 {
394 vinds[k]++;
395 k++;
396 continue;
397 }
398 vinds[k] = SCM_ARRAY_DIMS (ra0)[k].lbnd - 1;
399 k--;
400 }
401 while (k >= 0);
402 return 1;
403 }
404}
405
406
ad310508
MD
407SCM_PROC(s_array_fill_x, "array-fill!", 2, 0, 0, scm_array_fill_x);
408
409SCM
410scm_array_fill_x (ra, fill)
411 SCM ra;
412 SCM fill;
413{
414 scm_ramapc (scm_array_fill_int, fill, ra, SCM_EOL, s_array_fill_x);
415 return SCM_UNSPECIFIED;
416}
417
5c11cc9d
GH
418/* to be used as cproc in scm_ramapc to fill an array dimension with
419 "fill". */
0f2d19dd
JB
420int
421scm_array_fill_int (ra, fill, ignore)
422 SCM ra;
423 SCM fill;
424 SCM ignore;
0f2d19dd 425{
5c11cc9d
GH
426 scm_sizet i;
427 scm_sizet n = SCM_ARRAY_DIMS (ra)->ubnd - SCM_ARRAY_DIMS (ra)->lbnd + 1;
0f2d19dd
JB
428 long inc = SCM_ARRAY_DIMS (ra)->inc;
429 scm_sizet base = SCM_ARRAY_BASE (ra);
5c11cc9d 430
0f2d19dd 431 ra = SCM_ARRAY_V (ra);
5c11cc9d
GH
432 switch SCM_TYP7 (ra)
433 {
434 default:
435 for (i = base; n--; i += inc)
436 scm_array_set_x (ra, fill, SCM_MAKINUM (i));
437 break;
438 case scm_tc7_vector:
439 case scm_tc7_wvect:
440 for (i = base; n--; i += inc)
441 SCM_VELTS (ra)[i] = fill;
442 break;
443 case scm_tc7_string:
444 SCM_ASRTGO (SCM_ICHRP (fill), badarg2);
445 for (i = base; n--; i += inc)
446 SCM_CHARS (ra)[i] = SCM_ICHR (fill);
447 break;
448 case scm_tc7_byvect:
449 if (SCM_ICHRP (fill))
450 fill = SCM_MAKINUM ((char) SCM_ICHR (fill));
451 SCM_ASRTGO (SCM_INUMP (fill)
452 && -128 <= SCM_INUM (fill) && SCM_INUM (fill) < 128,
453 badarg2);
454 for (i = base; n--; i += inc)
455 SCM_CHARS (ra)[i] = SCM_INUM (fill);
456 break;
457 case scm_tc7_bvect:
0f2d19dd 458 {
5c11cc9d
GH
459 long *ve = (long *) SCM_VELTS (ra);
460 if (1 == inc && (n >= SCM_LONG_BIT || n == SCM_LENGTH (ra)))
461 {
462 i = base / SCM_LONG_BIT;
463 if (SCM_BOOL_F == fill)
464 {
465 if (base % SCM_LONG_BIT) /* leading partial word */
466 ve[i++] &= ~(~0L << (base % SCM_LONG_BIT));
467 for (; i < (base + n) / SCM_LONG_BIT; i++)
468 ve[i] = 0L;
469 if ((base + n) % SCM_LONG_BIT) /* trailing partial word */
470 ve[i] &= (~0L << ((base + n) % SCM_LONG_BIT));
471 }
472 else if (SCM_BOOL_T == fill)
473 {
474 if (base % SCM_LONG_BIT)
475 ve[i++] |= ~0L << (base % SCM_LONG_BIT);
476 for (; i < (base + n) / SCM_LONG_BIT; i++)
477 ve[i] = ~0L;
478 if ((base + n) % SCM_LONG_BIT)
479 ve[i] |= ~(~0L << ((base + n) % SCM_LONG_BIT));
480 }
481 else
482 badarg2:scm_wta (fill, (char *) SCM_ARG2, s_array_fill_x);
483 }
484 else
485 {
486 if (SCM_BOOL_F == fill)
487 for (i = base; n--; i += inc)
488 ve[i / SCM_LONG_BIT] &= ~(1L << (i % SCM_LONG_BIT));
489 else if (SCM_BOOL_T == fill)
490 for (i = base; n--; i += inc)
491 ve[i / SCM_LONG_BIT] |= (1L << (i % SCM_LONG_BIT));
492 else
493 goto badarg2;
494 }
495 break;
496 }
497 case scm_tc7_uvect:
498 {
499 unsigned long f = scm_num2ulong (fill, (char *) SCM_ARG2,
500 s_array_fill_x);
501 unsigned long *ve = (long *) SCM_VELTS (ra);
502
0f2d19dd 503 for (i = base; n--; i += inc)
5c11cc9d 504 ve[i] = f;
0f2d19dd 505 break;
5c11cc9d
GH
506 }
507 case scm_tc7_ivect:
508 {
509 long f = scm_num2long (fill, (char *) SCM_ARG2, s_array_fill_x);
510 long *ve = (long *) SCM_VELTS (ra);
511
0f2d19dd 512 for (i = base; n--; i += inc)
5c11cc9d 513 ve[i] = f;
0f2d19dd 514 break;
5c11cc9d
GH
515 }
516 case scm_tc7_svect:
517 SCM_ASRTGO (SCM_INUMP (fill), badarg2);
518 {
519 short f = SCM_INUM (fill);
520 short *ve = (short *) SCM_VELTS (ra);
521
522 if (f != SCM_INUM (fill))
523 scm_out_of_range (s_array_fill_x, fill);
0f2d19dd 524 for (i = base; n--; i += inc)
5c11cc9d 525 ve[i] = f;
0f2d19dd 526 break;
5c11cc9d
GH
527 }
528#ifdef HAVE_LONG_LONGS
529 case scm_tc7_llvect:
530 {
531 long long f = scm_num2long_long (fill, (char *) SCM_ARG2,
532 s_array_fill_x);
533 long long *ve = (long long *) SCM_VELTS (ra);
534
b1d24656 535 for (i = base; n--; i += inc)
5c11cc9d 536 ve[i] = f;
b1d24656 537 break;
5c11cc9d 538 }
05f92e0f 539#endif
0f2d19dd
JB
540#ifdef SCM_FLOATS
541#ifdef SCM_SINGLES
5c11cc9d
GH
542 case scm_tc7_fvect:
543 {
544 float f, *ve = (float *) SCM_VELTS (ra);
545 SCM_ASRTGO (SCM_NIMP (fill) && SCM_REALP (fill), badarg2);
546 f = SCM_REALPART (fill);
547 for (i = base; n--; i += inc)
548 ve[i] = f;
549 break;
550 }
0f2d19dd 551#endif /* SCM_SINGLES */
5c11cc9d
GH
552 case scm_tc7_dvect:
553 {
554 double f, *ve = (double *) SCM_VELTS (ra);
555 SCM_ASRTGO (SCM_NIMP (fill) && SCM_REALP (fill), badarg2);
556 f = SCM_REALPART (fill);
557 for (i = base; n--; i += inc)
558 ve[i] = f;
559 break;
560 }
561 case scm_tc7_cvect:
562 {
563 double fr, fi;
564 double (*ve)[2] = (double (*)[2]) SCM_VELTS (ra);
565 SCM_ASRTGO (SCM_NIMP (fill) && SCM_INEXP (fill), badarg2);
566 fr = SCM_REALPART (fill);
567 fi = (SCM_CPLXP (fill) ? SCM_IMAG (fill) : 0.0);
568 for (i = base; n--; i += inc)
569 {
570 ve[i][0] = fr;
571 ve[i][1] = fi;
572 }
573 break;
0f2d19dd 574 }
5c11cc9d
GH
575#endif /* SCM_FLOATS */
576 }
0f2d19dd
JB
577 return 1;
578}
579
0f2d19dd
JB
580
581
1cc91f1b
JB
582
583static int racp SCM_P ((SCM dst, SCM src));
584
0f2d19dd
JB
585static int
586racp (src, dst)
587 SCM dst;
588 SCM src;
0f2d19dd
JB
589{
590 long n = (SCM_ARRAY_DIMS (src)->ubnd - SCM_ARRAY_DIMS (src)->lbnd + 1);
591 long inc_d, inc_s = SCM_ARRAY_DIMS (src)->inc;
592 scm_sizet i_d, i_s = SCM_ARRAY_BASE (src);
593 dst = SCM_CAR (dst);
594 inc_d = SCM_ARRAY_DIMS (dst)->inc;
595 i_d = SCM_ARRAY_BASE (dst);
596 src = SCM_ARRAY_V (src);
597 dst = SCM_ARRAY_V (dst);
598 switch SCM_TYP7
599 (dst)
600 {
601 default:
95f5b0f5
MD
602 gencase:
603 case scm_tc7_vector:
604 case scm_tc7_wvect:
605
0f2d19dd
JB
606 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
607 scm_array_set_x (dst, scm_cvref (src, i_s, SCM_UNDEFINED), SCM_MAKINUM (i_d));
608 break;
609 case scm_tc7_string:
b1d24656 610 case scm_tc7_byvect:
0f2d19dd
JB
611 if (scm_tc7_string != SCM_TYP7 (dst))
612 goto gencase;
613 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
614 SCM_CHARS (dst)[i_d] = SCM_CHARS (src)[i_s];
615 break;
616 case scm_tc7_bvect:
617 if (scm_tc7_bvect != SCM_TYP7 (dst))
618 goto gencase;
619 if (1 == inc_d && 1 == inc_s && i_s % SCM_LONG_BIT == i_d % SCM_LONG_BIT && n >= SCM_LONG_BIT)
620 {
621 long *sv = (long *) SCM_VELTS (src);
622 long *dv = (long *) SCM_VELTS (dst);
623 sv += i_s / SCM_LONG_BIT;
624 dv += i_d / SCM_LONG_BIT;
625 if (i_s % SCM_LONG_BIT)
626 { /* leading partial word */
627 *dv = (*dv & ~(~0L << (i_s % SCM_LONG_BIT))) | (*sv & (~0L << (i_s % SCM_LONG_BIT)));
628 dv++;
629 sv++;
630 n -= SCM_LONG_BIT - (i_s % SCM_LONG_BIT);
631 }
632 IVDEP (src != dst,
633 for (; n >= SCM_LONG_BIT; n -= SCM_LONG_BIT, sv++, dv++)
634 * dv = *sv;)
635 if (n) /* trailing partial word */
636 *dv = (*dv & (~0L << n)) | (*sv & ~(~0L << n));
637 }
638 else
639 {
640 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
641 if (SCM_VELTS (src)[i_s / SCM_LONG_BIT] & (1L << (i_s % SCM_LONG_BIT)))
642 SCM_VELTS (dst)[i_d / SCM_LONG_BIT] |= (1L << (i_d % SCM_LONG_BIT));
643 else
644 SCM_VELTS (dst)[i_d / SCM_LONG_BIT] &= ~(1L << (i_d % SCM_LONG_BIT));
645 }
646 break;
647 case scm_tc7_uvect:
648 if (scm_tc7_uvect != SCM_TYP7 (src))
649 goto gencase;
650 else
651 {
652 long *d = (long *) SCM_VELTS (dst), *s = (long *) SCM_VELTS (src);
653 IVDEP (src != dst,
654 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
655 d[i_d] = s[i_s];)
656 break;
657 }
658 case scm_tc7_ivect:
659 if (scm_tc7_uvect != SCM_TYP7 (src) && scm_tc7_ivect != SCM_TYP7 (src))
660 goto gencase;
661 else
662 {
663 long *d = (long *) SCM_VELTS (dst), *s = (long *) SCM_VELTS (src);
664 IVDEP (src != dst,
665 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
666 d[i_d] = s[i_s];)
667 break;
668 }
669#ifdef SCM_FLOATS
670#ifdef SCM_SINGLES
671 case scm_tc7_fvect:
672 {
673 float *d = (float *) SCM_VELTS (dst);
674 float *s = (float *) SCM_VELTS (src);
675 switch SCM_TYP7
676 (src)
677 {
678 default:
679 goto gencase;
680 case scm_tc7_ivect:
681 case scm_tc7_uvect:
682 IVDEP (src != dst,
683 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
684 d[i_d] = ((long *) s)[i_s];)
685 break;
686 case scm_tc7_fvect:
687 IVDEP (src != dst,
688 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
689 d[i_d] = s[i_s];)
690 break;
691 case scm_tc7_dvect:
692 IVDEP (src != dst,
693 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
694 d[i_d] = ((double *) s)[i_s];)
695 break;
696 }
697 break;
698 }
699#endif /* SCM_SINGLES */
700 case scm_tc7_dvect:
701 {
702 double *d = (double *) SCM_VELTS (dst);
703 double *s = (double *) SCM_VELTS (src);
704 switch SCM_TYP7
705 (src)
706 {
707 default:
708 goto gencase;
709 case scm_tc7_ivect:
710 case scm_tc7_uvect:
711 IVDEP (src != dst,
712 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
713 d[i_d] = ((long *) s)[i_s];)
714 break;
715 case scm_tc7_fvect:
716 IVDEP (src != dst,
717 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
718 d[i_d] = ((float *) s)[i_s];)
719 break;
720 case scm_tc7_dvect:
721 IVDEP (src != dst,
722 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
723 d[i_d] = s[i_s];)
724 break;
725 }
726 break;
727 }
728 case scm_tc7_cvect:
729 {
730 double (*d)[2] = (double (*)[2]) SCM_VELTS (dst);
731 double (*s)[2] = (double (*)[2]) SCM_VELTS (src);
732 switch SCM_TYP7
733 (src)
734 {
735 default:
736 goto gencase;
737 case scm_tc7_ivect:
738 case scm_tc7_uvect:
739 IVDEP (src != dst,
740 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
741 {
742 d[i_d][0] = ((long *) s)[i_s];
743 d[i_d][1] = 0.0;
744 }
745 )
746 break;
747 case scm_tc7_fvect:
748 IVDEP (src != dst,
749 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
750 {
751 d[i_d][0] = ((float *) s)[i_s];
752 d[i_d][1] = 0.0;
753 }
754 )
755 break;
756 case scm_tc7_dvect:
757 IVDEP (src != dst,
758 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
759 {
760 d[i_d][0] = ((double *) s)[i_s];
761 d[i_d][1] = 0.0;
762 }
763 )
764 break;
765 case scm_tc7_cvect:
766 IVDEP (src != dst,
767 for (; n-- > 0; i_s += inc_s, i_d += inc_d)
768 {
769 d[i_d][0] = s[i_s][0];
770 d[i_d][1] = s[i_s][1];
771 }
772 )
773 }
774 break;
775 }
776 }
777#endif /* SCM_FLOATS */
778 return 1;
779}
780
781
dba2ab49 782/* This name is obsolete. Will go away in release 1.5. */
0f2d19dd 783SCM_PROC(s_serial_array_copy_x, "serial-array-copy!", 2, 0, 0, scm_array_copy_x);
dba2ab49 784SCM_PROC(s_array_copy_in_order_x, "array-copy-in-order!", 2, 0, 0, scm_array_copy_x);
0f2d19dd 785SCM_PROC(s_array_copy_x, "array-copy!", 2, 0, 0, scm_array_copy_x);
1cc91f1b 786
0f2d19dd
JB
787SCM
788scm_array_copy_x (src, dst)
789 SCM src;
790 SCM dst;
0f2d19dd
JB
791{
792 scm_ramapc (racp, SCM_UNDEFINED, src, scm_cons (dst, SCM_EOL), s_array_copy_x);
793 return SCM_UNSPECIFIED;
794}
795
796/* Functions callable by ARRAY-MAP! */
797
1cc91f1b 798
0f2d19dd
JB
799int
800scm_ra_eqp (ra0, ras)
801 SCM ra0;
802 SCM ras;
0f2d19dd
JB
803{
804 SCM ra1 = SCM_CAR (ras), ra2 = SCM_CAR (SCM_CDR (ras));
805 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
806 scm_sizet i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1), i2 = SCM_ARRAY_BASE (ra2);
807 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
808 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
809 long inc2 = SCM_ARRAY_DIMS (ra1)->inc;
810 ra0 = SCM_ARRAY_V (ra0);
811 ra1 = SCM_ARRAY_V (ra1);
812 ra2 = SCM_ARRAY_V (ra2);
813 switch (SCM_TYP7 (ra1) == SCM_TYP7 (ra2) ? SCM_TYP7 (ra1) : 0)
814 {
815 default:
816 {
817 SCM e1 = SCM_UNDEFINED, e2 = SCM_UNDEFINED;
818 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021
JB
819 if (BVE_REF (ra0, i0))
820 if (SCM_FALSEP(scm_eq_p (RVREF (ra1, i1, e1), RVREF (ra2, i2, e2))))
0f2d19dd
JB
821 BVE_CLR (ra0, i0);
822 break;
823 }
824 case scm_tc7_uvect:
825 case scm_tc7_ivect:
826 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 827 if (BVE_REF (ra0, i0))
0f2d19dd
JB
828 if (SCM_VELTS (ra1)[i1] != SCM_VELTS (ra2)[i2])
829 BVE_CLR (ra0, i0);
830 break;
831#ifdef SCM_FLOATS
832#ifdef SCM_SINGLES
833 case scm_tc7_fvect:
834 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 835 if (BVE_REF (ra0, i0))
0f2d19dd
JB
836 if (((float *) SCM_VELTS (ra1))[i1] != ((float *) SCM_VELTS (ra2))[i2])
837 BVE_CLR (ra0, i0);
838 break;
839#endif /*SCM_SINGLES*/
840 case scm_tc7_dvect:
841 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 842 if (BVE_REF (ra0, i0))
0f2d19dd
JB
843 if (((double *) SCM_VELTS (ra1))[i1] != ((double *) SCM_VELTS (ra2))[i2])
844 BVE_CLR (ra0, i0);
845 break;
846 case scm_tc7_cvect:
847 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 848 if (BVE_REF (ra0, i0))
0f2d19dd
JB
849 if (((double *) SCM_VELTS (ra1))[2 * i1] != ((double *) SCM_VELTS (ra2))[2 * i2] ||
850 ((double *) SCM_VELTS (ra1))[2 * i1 + 1] != ((double *) SCM_VELTS (ra2))[2 * i2 + 1])
851 BVE_CLR (ra0, i0);
852 break;
853#endif /*SCM_FLOATS*/
854 }
855 return 1;
856}
857
858/* opt 0 means <, nonzero means >= */
1cc91f1b
JB
859
860static int ra_compare SCM_P ((SCM ra0, SCM ra1, SCM ra2, int opt));
861
0f2d19dd
JB
862static int
863ra_compare (ra0, ra1, ra2, opt)
864 SCM ra0;
865 SCM ra1;
866 SCM ra2;
867 int opt;
0f2d19dd
JB
868{
869 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
870 scm_sizet i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1), i2 = SCM_ARRAY_BASE (ra2);
871 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
872 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
873 long inc2 = SCM_ARRAY_DIMS (ra1)->inc;
874 ra0 = SCM_ARRAY_V (ra0);
875 ra1 = SCM_ARRAY_V (ra1);
876 ra2 = SCM_ARRAY_V (ra2);
877 switch (SCM_TYP7 (ra1) == SCM_TYP7 (ra2) ? SCM_TYP7 (ra1) : 0)
878 {
879 default:
880 {
881 SCM e1 = SCM_UNDEFINED, e2 = SCM_UNDEFINED;
882 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 883 if (BVE_REF (ra0, i0))
0f2d19dd
JB
884 if (opt ?
885 SCM_NFALSEP (scm_less_p (RVREF (ra1, i1, e1), RVREF (ra2, i2, e2))) :
886 SCM_FALSEP (scm_less_p (RVREF (ra1, i1, e1), RVREF (ra2, i2, e2))))
887 BVE_CLR (ra0, i0);
888 break;
889 }
890 case scm_tc7_uvect:
891 case scm_tc7_ivect:
892 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
893 {
ff467021 894 if (BVE_REF (ra0, i0))
0f2d19dd
JB
895 if (opt ?
896 SCM_VELTS (ra1)[i1] < SCM_VELTS (ra2)[i2] :
897 SCM_VELTS (ra1)[i1] >= SCM_VELTS (ra2)[i2])
898 BVE_CLR (ra0, i0);
899 }
900 break;
901#ifdef SCM_FLOATS
902#ifdef SCM_SINGLES
903 case scm_tc7_fvect:
904 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 905 if (BVE_REF(ra0, i0))
0f2d19dd
JB
906 if (opt ?
907 ((float *) SCM_VELTS (ra1))[i1] < ((float *) SCM_VELTS (ra2))[i2] :
908 ((float *) SCM_VELTS (ra1))[i1] >= ((float *) SCM_VELTS (ra2))[i2])
909 BVE_CLR (ra0, i0);
910 break;
911#endif /*SCM_SINGLES*/
912 case scm_tc7_dvect:
913 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 914 if (BVE_REF (ra0, i0))
0f2d19dd
JB
915 if (opt ?
916 ((double *) SCM_VELTS (ra1))[i1] < ((double *) SCM_VELTS (ra2))[i2] :
917 ((double *) SCM_VELTS (ra1))[i1] >= ((double *) SCM_VELTS (ra2))[i2])
918 BVE_CLR (ra0, i0);
919 break;
920#endif /*SCM_FLOATS*/
921 }
922 return 1;
923}
924
925
1cc91f1b 926
0f2d19dd
JB
927int
928scm_ra_lessp (ra0, ras)
929 SCM ra0;
930 SCM ras;
0f2d19dd
JB
931{
932 return ra_compare (ra0, SCM_CAR (ras), SCM_CAR (SCM_CDR (ras)), 0);
933}
934
1cc91f1b 935
0f2d19dd
JB
936int
937scm_ra_leqp (ra0, ras)
938 SCM ra0;
939 SCM ras;
0f2d19dd
JB
940{
941 return ra_compare (ra0, SCM_CAR (SCM_CDR (ras)), SCM_CAR (ras), 1);
942}
943
1cc91f1b 944
0f2d19dd
JB
945int
946scm_ra_grp (ra0, ras)
947 SCM ra0;
948 SCM ras;
0f2d19dd
JB
949{
950 return ra_compare (ra0, SCM_CAR (SCM_CDR (ras)), SCM_CAR (ras), 0);
951}
952
1cc91f1b 953
0f2d19dd
JB
954int
955scm_ra_greqp (ra0, ras)
956 SCM ra0;
957 SCM ras;
0f2d19dd
JB
958{
959 return ra_compare (ra0, SCM_CAR (ras), SCM_CAR (SCM_CDR (ras)), 1);
960}
961
962
1cc91f1b 963
0f2d19dd
JB
964int
965scm_ra_sum (ra0, ras)
966 SCM ra0;
967 SCM ras;
0f2d19dd
JB
968{
969 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
970 scm_sizet i0 = SCM_ARRAY_BASE (ra0);
971 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
972 ra0 = SCM_ARRAY_V (ra0);
ff467021 973 if (SCM_NNULLP(ras))
0f2d19dd
JB
974 {
975 SCM ra1 = SCM_CAR (ras);
976 scm_sizet i1 = SCM_ARRAY_BASE (ra1);
977 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
978 ra1 = SCM_ARRAY_V (ra1);
979 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
980 {
981 default:
982 {
983 SCM e0 = SCM_UNDEFINED, e1 = SCM_UNDEFINED;
984 for (; n-- > 0; i0 += inc0, i1 += inc1)
985 scm_array_set_x (ra0, scm_sum (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1)),
986 SCM_MAKINUM (i0));
987 break;
988 }
989 case scm_tc7_uvect:
990 case scm_tc7_ivect:
991 {
992 long *v0 = SCM_VELTS (ra0);
993 long *v1 = SCM_VELTS (ra1);
994 IVDEP (ra0 != ra1,
995 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 996 v0[i0] += v1[i1];)
0f2d19dd
JB
997 break;
998 }
999#ifdef SCM_FLOATS
1000#ifdef SCM_SINGLES
1001 case scm_tc7_fvect:
1002 {
1003 float *v0 = (float *) SCM_VELTS (ra0);
1004 float *v1 = (float *) SCM_VELTS (ra1);
1005 IVDEP (ra0 != ra1,
1006 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1007 v0[i0] += v1[i1];)
0f2d19dd
JB
1008 break;
1009 }
1010#endif /* SCM_SINGLES */
1011 case scm_tc7_dvect:
1012 {
1013 double *v0 = (double *) SCM_VELTS (ra0);
1014 double *v1 = (double *) SCM_VELTS (ra1);
1015 IVDEP (ra0 != ra1,
1016 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1017 v0[i0] += v1[i1];)
0f2d19dd
JB
1018 break;
1019 }
1020 case scm_tc7_cvect:
1021 {
1022 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0);
1023 double (*v1)[2] = (double (*)[2]) SCM_VELTS (ra1);
1024 IVDEP (ra0 != ra1,
1025 for (; n-- > 0; i0 += inc0, i1 += inc1)
1026 {
1027 v0[i0][0] += v1[i1][0];
1028 v0[i0][1] += v1[i1][1];
1029 }
1030 );
1031 break;
1032 }
1033#endif /* SCM_FLOATS */
1034 }
1035 }
1036 return 1;
1037}
1038
1039
1cc91f1b 1040
0f2d19dd
JB
1041int
1042scm_ra_difference (ra0, ras)
1043 SCM ra0;
1044 SCM ras;
0f2d19dd
JB
1045{
1046 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1047 scm_sizet i0 = SCM_ARRAY_BASE (ra0);
1048 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1049 ra0 = SCM_ARRAY_V (ra0);
ff467021 1050 if (SCM_NULLP (ras))
0f2d19dd 1051 {
ff467021 1052 switch (SCM_TYP7 (ra0))
0f2d19dd
JB
1053 {
1054 default:
1055 {
1056 SCM e0 = SCM_UNDEFINED;
1057 for (; n-- > 0; i0 += inc0)
1058 scm_array_set_x (ra0, scm_difference (RVREF (ra0, i0, e0), SCM_UNDEFINED), SCM_MAKINUM (i0));
1059 break;
1060 }
1061#ifdef SCM_FLOATS
1062#ifdef SCM_SINGLES
1063 case scm_tc7_fvect:
1064 {
1065 float *v0 = (float *) SCM_VELTS (ra0);
1066 for (; n-- > 0; i0 += inc0)
1067 v0[i0] = -v0[i0];
1068 break;
1069 }
1070#endif /* SCM_SINGLES */
1071 case scm_tc7_dvect:
1072 {
1073 double *v0 = (double *) SCM_VELTS (ra0);
1074 for (; n-- > 0; i0 += inc0)
1075 v0[i0] = -v0[i0];
1076 break;
1077 }
1078 case scm_tc7_cvect:
1079 {
1080 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0);
1081 for (; n-- > 0; i0 += inc0)
1082 {
1083 v0[i0][0] = -v0[i0][0];
1084 v0[i0][1] = -v0[i0][1];
1085 }
1086 break;
1087 }
1088#endif /* SCM_FLOATS */
1089 }
1090 }
1091 else
1092 {
1093 SCM ra1 = SCM_CAR (ras);
1094 scm_sizet i1 = SCM_ARRAY_BASE (ra1);
1095 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1096 ra1 = SCM_ARRAY_V (ra1);
1097 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
1098 {
1099 default:
1100 {
1101 SCM e0 = SCM_UNDEFINED, e1 = SCM_UNDEFINED;
1102 for (; n-- > 0; i0 += inc0, i1 += inc1)
1103 scm_array_set_x (ra0, scm_difference (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1)), SCM_MAKINUM (i0));
1104 break;
1105 }
1106#ifdef SCM_FLOATS
1107#ifdef SCM_SINGLES
1108 case scm_tc7_fvect:
1109 {
1110 float *v0 = (float *) SCM_VELTS (ra0);
1111 float *v1 = (float *) SCM_VELTS (ra1);
1112 IVDEP (ra0 != ra1,
1113 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1114 v0[i0] -= v1[i1];)
0f2d19dd
JB
1115 break;
1116 }
1117#endif /* SCM_SINGLES */
1118 case scm_tc7_dvect:
1119 {
1120 double *v0 = (double *) SCM_VELTS (ra0);
1121 double *v1 = (double *) SCM_VELTS (ra1);
1122 IVDEP (ra0 != ra1,
1123 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1124 v0[i0] -= v1[i1];)
0f2d19dd
JB
1125 break;
1126 }
1127 case scm_tc7_cvect:
1128 {
1129 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0);
1130 double (*v1)[2] = (double (*)[2]) SCM_VELTS (ra1);
1131 IVDEP (ra0 != ra1,
1132 for (; n-- > 0; i0 += inc0, i1 += inc1)
1133 {
1134 v0[i0][0] -= v1[i1][0];
1135 v0[i0][1] -= v1[i1][1];
1136 }
1137 )
1138 break;
1139 }
1140#endif /* SCM_FLOATS */
1141 }
1142 }
1143 return 1;
1144}
1145
1146
1cc91f1b 1147
0f2d19dd
JB
1148int
1149scm_ra_product (ra0, ras)
1150 SCM ra0;
1151 SCM ras;
0f2d19dd
JB
1152{
1153 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1154 scm_sizet i0 = SCM_ARRAY_BASE (ra0);
1155 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1156 ra0 = SCM_ARRAY_V (ra0);
ff467021 1157 if (SCM_NNULLP (ras))
0f2d19dd
JB
1158 {
1159 SCM ra1 = SCM_CAR (ras);
1160 scm_sizet i1 = SCM_ARRAY_BASE (ra1);
1161 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1162 ra1 = SCM_ARRAY_V (ra1);
1163 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
1164 {
1165 default:
1166 {
1167 SCM e0 = SCM_UNDEFINED, e1 = SCM_UNDEFINED;
1168 for (; n-- > 0; i0 += inc0, i1 += inc1)
1169 scm_array_set_x (ra0, scm_product (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1)),
1170 SCM_MAKINUM (i0));
1171 break;
1172 }
1173 case scm_tc7_uvect:
1174 case scm_tc7_ivect:
1175 {
1176 long *v0 = SCM_VELTS (ra0);
1177 long *v1 = SCM_VELTS (ra1);
1178 IVDEP (ra0 != ra1,
1179 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1180 v0[i0] *= v1[i1];)
0f2d19dd
JB
1181 break;
1182 }
1183#ifdef SCM_FLOATS
1184#ifdef SCM_SINGLES
1185 case scm_tc7_fvect:
1186 {
1187 float *v0 = (float *) SCM_VELTS (ra0);
1188 float *v1 = (float *) SCM_VELTS (ra1);
1189 IVDEP (ra0 != ra1,
1190 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1191 v0[i0] *= v1[i1];)
0f2d19dd
JB
1192 break;
1193 }
1194#endif /* SCM_SINGLES */
1195 case scm_tc7_dvect:
1196 {
1197 double *v0 = (double *) SCM_VELTS (ra0);
1198 double *v1 = (double *) SCM_VELTS (ra1);
1199 IVDEP (ra0 != ra1,
1200 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1201 v0[i0] *= v1[i1];)
0f2d19dd
JB
1202 break;
1203 }
1204 case scm_tc7_cvect:
1205 {
1206 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0);
1207 register double r;
1208 double (*v1)[2] = (double (*)[2]) SCM_VELTS (ra1);
1209 IVDEP (ra0 != ra1,
1210 for (; n-- > 0; i0 += inc0, i1 += inc1)
1211 {
1212 r = v0[i0][0] * v1[i1][0] - v0[i0][1] * v1[i1][1];
1213 v0[i0][1] = v0[i0][0] * v1[i1][1] + v0[i0][1] * v1[i1][0];
1214 v0[i0][0] = r;
1215 }
1216 );
1217 break;
1218 }
1219#endif /* SCM_FLOATS */
1220 }
1221 }
1222 return 1;
1223}
1224
1cc91f1b 1225
0f2d19dd
JB
1226int
1227scm_ra_divide (ra0, ras)
1228 SCM ra0;
1229 SCM ras;
0f2d19dd
JB
1230{
1231 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1232 scm_sizet i0 = SCM_ARRAY_BASE (ra0);
1233 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1234 ra0 = SCM_ARRAY_V (ra0);
ff467021 1235 if (SCM_NULLP (ras))
0f2d19dd 1236 {
ff467021 1237 switch (SCM_TYP7 (ra0))
0f2d19dd
JB
1238 {
1239 default:
1240 {
1241 SCM e0 = SCM_UNDEFINED;
1242 for (; n-- > 0; i0 += inc0)
1243 scm_array_set_x (ra0, scm_divide (RVREF (ra0, i0, e0), SCM_UNDEFINED), SCM_MAKINUM (i0));
1244 break;
1245 }
1246#ifdef SCM_FLOATS
1247#ifdef SCM_SINGLES
1248 case scm_tc7_fvect:
1249 {
1250 float *v0 = (float *) SCM_VELTS (ra0);
1251 for (; n-- > 0; i0 += inc0)
1252 v0[i0] = 1.0 / v0[i0];
1253 break;
1254 }
1255#endif /* SCM_SINGLES */
1256 case scm_tc7_dvect:
1257 {
1258 double *v0 = (double *) SCM_VELTS (ra0);
1259 for (; n-- > 0; i0 += inc0)
1260 v0[i0] = 1.0 / v0[i0];
1261 break;
1262 }
1263 case scm_tc7_cvect:
1264 {
1265 register double d;
1266 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0);
1267 for (; n-- > 0; i0 += inc0)
1268 {
1269 d = v0[i0][0] * v0[i0][0] + v0[i0][1] * v0[i0][1];
1270 v0[i0][0] /= d;
1271 v0[i0][1] /= -d;
1272 }
1273 break;
1274 }
1275#endif /* SCM_FLOATS */
1276 }
1277 }
1278 else
1279 {
1280 SCM ra1 = SCM_CAR (ras);
1281 scm_sizet i1 = SCM_ARRAY_BASE (ra1);
1282 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1283 ra1 = SCM_ARRAY_V (ra1);
1284 switch (SCM_TYP7 (ra0) == SCM_TYP7 (ra1) ? SCM_TYP7 (ra0) : 0)
1285 {
1286 default:
1287 {
1288 SCM e0 = SCM_UNDEFINED, e1 = SCM_UNDEFINED;
1289 for (; n-- > 0; i0 += inc0, i1 += inc1)
1290 scm_array_set_x (ra0, scm_divide (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1)), SCM_MAKINUM (i0));
1291 break;
1292 }
1293#ifdef SCM_FLOATS
1294#ifdef SCM_SINGLES
1295 case scm_tc7_fvect:
1296 {
1297 float *v0 = (float *) SCM_VELTS (ra0);
1298 float *v1 = (float *) SCM_VELTS (ra1);
1299 IVDEP (ra0 != ra1,
1300 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1301 v0[i0] /= v1[i1];)
0f2d19dd
JB
1302 break;
1303 }
1304#endif /* SCM_SINGLES */
1305 case scm_tc7_dvect:
1306 {
1307 double *v0 = (double *) SCM_VELTS (ra0);
1308 double *v1 = (double *) SCM_VELTS (ra1);
1309 IVDEP (ra0 != ra1,
1310 for (; n-- > 0; i0 += inc0, i1 += inc1)
01e2a66d 1311 v0[i0] /= v1[i1];)
0f2d19dd
JB
1312 break;
1313 }
1314 case scm_tc7_cvect:
1315 {
1316 register double d, r;
1317 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0);
1318 double (*v1)[2] = (double (*)[2]) SCM_VELTS (ra1);
1319 IVDEP (ra0 != ra1,
1320 for (; n-- > 0; i0 += inc0, i1 += inc1)
1321 {
1322 d = v1[i1][0] * v1[i1][0] + v1[i1][1] * v1[i1][1];
1323 r = (v0[i0][0] * v1[i1][0] + v0[i0][1] * v1[i1][1]) / d;
1324 v0[i0][1] = (v0[i0][1] * v1[i1][0] - v0[i0][0] * v1[i1][1]) / d;
1325 v0[i0][0] = r;
1326 }
1327 )
1328 break;
1329 }
1330#endif /* SCM_FLOATS */
1331 }
1332 }
1333 return 1;
1334}
1335
1cc91f1b 1336
0f2d19dd
JB
1337int
1338scm_array_identity (dst, src)
1339 SCM src;
1340 SCM dst;
0f2d19dd
JB
1341{
1342 return racp (SCM_CAR (src), scm_cons (dst, SCM_EOL));
1343}
1344
1345
1cc91f1b
JB
1346
1347static int ramap SCM_P ((SCM ra0, SCM proc, SCM ras));
1348
0f2d19dd
JB
1349static int
1350ramap (ra0, proc, ras)
1351 SCM ra0;
1352 SCM proc;
1353 SCM ras;
0f2d19dd
JB
1354{
1355 long i = SCM_ARRAY_DIMS (ra0)->lbnd;
1356 long inc = SCM_ARRAY_DIMS (ra0)->inc;
1357 long n = SCM_ARRAY_DIMS (ra0)->ubnd;
1358 long base = SCM_ARRAY_BASE (ra0) - i * inc;
1359 ra0 = SCM_ARRAY_V (ra0);
ff467021 1360 if (SCM_NULLP (ras))
0f2d19dd
JB
1361 for (; i <= n; i++)
1362 scm_array_set_x (ra0, scm_apply (proc, SCM_EOL, SCM_EOL), SCM_MAKINUM (i * inc + base));
1363 else
1364 {
1365 SCM ra1 = SCM_CAR (ras);
1366 SCM args, *ve = &ras;
1367 scm_sizet k, i1 = SCM_ARRAY_BASE (ra1);
1368 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1369 ra1 = SCM_ARRAY_V (ra1);
1370 ras = SCM_CDR (ras);
ff467021 1371 if (SCM_NULLP(ras))
0f2d19dd
JB
1372 ras = scm_nullvect;
1373 else
1374 {
1375 ras = scm_vector (ras);
1376 ve = SCM_VELTS (ras);
1377 }
1378 for (; i <= n; i++, i1 += inc1)
1379 {
1380 args = SCM_EOL;
1381 for (k = SCM_LENGTH (ras); k--;)
1382 args = scm_cons (scm_uniform_vector_ref (ve[k], SCM_MAKINUM (i)), args);
1383 args = scm_cons (scm_cvref (ra1, i1, SCM_UNDEFINED), args);
1384 scm_array_set_x (ra0, scm_apply (proc, args, SCM_EOL), SCM_MAKINUM (i * inc + base));
1385 }
1386 }
1387 return 1;
1388}
1389
1cc91f1b
JB
1390
1391static int ramap_cxr SCM_P ((SCM ra0, SCM proc, SCM ras));
1392
0f2d19dd
JB
1393static int
1394ramap_cxr (ra0, proc, ras)
1395 SCM ra0;
1396 SCM proc;
1397 SCM ras;
0f2d19dd
JB
1398{
1399 SCM ra1 = SCM_CAR (ras);
1400 SCM e1 = SCM_UNDEFINED;
1401 scm_sizet i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1);
1402 long inc0 = SCM_ARRAY_DIMS (ra0)->inc, inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1403 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra1)->lbnd + 1;
1404 ra0 = SCM_ARRAY_V (ra0);
1405 ra1 = SCM_ARRAY_V (ra1);
ff467021 1406 switch (SCM_TYP7 (ra0))
0f2d19dd
JB
1407 {
1408 default:
1409 gencase:
1410 for (; n-- > 0; i0 += inc0, i1 += inc1)
1411 scm_array_set_x (ra0, scm_apply (proc, RVREF (ra1, i1, e1), scm_listofnull), SCM_MAKINUM (i0));
1412 break;
1413#ifdef SCM_FLOATS
1414#ifdef SCM_SINGLES
1415 case scm_tc7_fvect:
1416 {
1417 float *dst = (float *) SCM_VELTS (ra0);
ff467021 1418 switch (SCM_TYP7 (ra1))
0f2d19dd
JB
1419 {
1420 default:
1421 goto gencase;
1422 case scm_tc7_fvect:
1423 for (; n-- > 0; i0 += inc0, i1 += inc1)
1424 dst[i0] = SCM_DSUBRF (proc) ((double) ((float *) SCM_VELTS (ra1))[i1]);
1425 break;
1426 case scm_tc7_uvect:
1427 case scm_tc7_ivect:
1428 for (; n-- > 0; i0 += inc0, i1 += inc1)
1429 dst[i0] = SCM_DSUBRF (proc) ((double) SCM_VELTS (ra1)[i1]);
1430 break;
1431 }
1432 break;
1433 }
1434#endif /* SCM_SINGLES */
1435 case scm_tc7_dvect:
1436 {
1437 double *dst = (double *) SCM_VELTS (ra0);
ff467021 1438 switch (SCM_TYP7 (ra1))
0f2d19dd
JB
1439 {
1440 default:
1441 goto gencase;
1442 case scm_tc7_dvect:
1443 for (; n-- > 0; i0 += inc0, i1 += inc1)
1444 dst[i0] = SCM_DSUBRF (proc) (((double *) SCM_VELTS (ra1))[i1]);
1445 break;
1446 case scm_tc7_uvect:
1447 case scm_tc7_ivect:
1448 for (; n-- > 0; i0 += inc0, i1 += inc1)
1449 dst[i0] = SCM_DSUBRF (proc) ((double) SCM_VELTS (ra1)[i1]);
1450 break;
1451 }
1452 break;
1453 }
1454#endif /* SCM_FLOATS */
1455 }
1456 return 1;
1457}
1458
1459
1cc91f1b
JB
1460
1461static int ramap_rp SCM_P ((SCM ra0, SCM proc, SCM ras));
1462
0f2d19dd
JB
1463static int
1464ramap_rp (ra0, proc, ras)
1465 SCM ra0;
1466 SCM proc;
1467 SCM ras;
0f2d19dd
JB
1468{
1469 SCM ra1 = SCM_CAR (ras), ra2 = SCM_CAR (SCM_CDR (ras));
1470 SCM e1 = SCM_UNDEFINED, e2 = SCM_UNDEFINED;
1471 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1472 scm_sizet i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1), i2 = SCM_ARRAY_BASE (ra2);
1473 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1474 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1475 long inc2 = SCM_ARRAY_DIMS (ra1)->inc;
1476 ra0 = SCM_ARRAY_V (ra0);
1477 ra1 = SCM_ARRAY_V (ra1);
1478 ra2 = SCM_ARRAY_V (ra2);
1479 switch (SCM_TYP7 (ra1) == SCM_TYP7 (ra2) ? SCM_TYP7 (ra1) : 0)
1480 {
1481 default:
1482 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021
JB
1483 if (BVE_REF (ra0, i0))
1484 if (SCM_FALSEP (SCM_SUBRF (proc) (RVREF (ra1, i1, e1), RVREF (ra2, i2, e2))))
0f2d19dd
JB
1485 BVE_CLR (ra0, i0);
1486 break;
1487 case scm_tc7_uvect:
1488 case scm_tc7_ivect:
1489 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 1490 if (BVE_REF (ra0, i0))
0f2d19dd 1491 {
ff467021
JB
1492 if (SCM_FALSEP (SCM_SUBRF (proc) (SCM_MAKINUM (SCM_VELTS (ra1)[i1]),
1493 SCM_MAKINUM (SCM_VELTS (ra2)[i2]))))
0f2d19dd
JB
1494 BVE_CLR (ra0, i0);
1495 }
1496 break;
1497#ifdef SCM_FLOATS
1498#ifdef SCM_SINGLES
1499 case scm_tc7_fvect:
1500 {
1501 SCM a1 = scm_makflo (1.0), a2 = scm_makflo (1.0);
1502 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 1503 if (BVE_REF (ra0, i0))
0f2d19dd
JB
1504 {
1505 SCM_FLO (a1) = ((float *) SCM_VELTS (ra1))[i1];
1506 SCM_FLO (a2) = ((float *) SCM_VELTS (ra2))[i2];
ff467021 1507 if (SCM_FALSEP (SCM_SUBRF (proc) (a1, a2)))
0f2d19dd
JB
1508 BVE_CLR (ra0, i0);
1509 }
1510 break;
1511 }
1512#endif /*SCM_SINGLES*/
1513 case scm_tc7_dvect:
1514 {
1515 SCM a1 = scm_makdbl (1.0 / 3.0, 0.0), a2 = scm_makdbl (1.0 / 3.0, 0.0);
1516 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 1517 if (BVE_REF (ra0, i0))
0f2d19dd
JB
1518 {
1519 SCM_REAL (a1) = ((double *) SCM_VELTS (ra1))[i1];
1520 SCM_REAL (a2) = ((double *) SCM_VELTS (ra2))[i2];
ff467021 1521 if (SCM_FALSEP (SCM_SUBRF (proc) (a1, a2)))
0f2d19dd
JB
1522 BVE_CLR (ra0, i0);
1523 }
1524 break;
1525 }
1526 case scm_tc7_cvect:
1527 {
1528 SCM a1 = scm_makdbl (1.0, 1.0), a2 = scm_makdbl (1.0, 1.0);
1529 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
ff467021 1530 if (BVE_REF (ra0, i0))
0f2d19dd
JB
1531 {
1532 SCM_REAL (a1) = ((double *) SCM_VELTS (ra1))[2 * i1];
1533 SCM_IMAG (a1) = ((double *) SCM_VELTS (ra1))[2 * i1 + 1];
1534 SCM_REAL (a2) = ((double *) SCM_VELTS (ra2))[2 * i2];
1535 SCM_IMAG (a2) = ((double *) SCM_VELTS (ra2))[2 * i2 + 1];
ff467021 1536 if (SCM_FALSEP (SCM_SUBRF (proc) (a1, a2)))
0f2d19dd
JB
1537 BVE_CLR (ra0, i0);
1538 }
1539 break;
1540 }
1541#endif /*SCM_FLOATS*/
1542 }
1543 return 1;
1544}
1545
1546
1cc91f1b
JB
1547
1548static int ramap_1 SCM_P ((SCM ra0, SCM proc, SCM ras));
1549
0f2d19dd
JB
1550static int
1551ramap_1 (ra0, proc, ras)
1552 SCM ra0;
1553 SCM proc;
1554 SCM ras;
0f2d19dd
JB
1555{
1556 SCM ra1 = SCM_CAR (ras);
1557 SCM e1 = SCM_UNDEFINED;
1558 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1559 scm_sizet i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1);
1560 long inc0 = SCM_ARRAY_DIMS (ra0)->inc, inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1561 ra0 = SCM_ARRAY_V (ra0);
1562 ra1 = SCM_ARRAY_V (ra1);
95f5b0f5 1563 if (scm_tc7_vector == SCM_TYP7 (ra0) || scm_tc7_wvect == SCM_TYP7 (ra0))
0f2d19dd
JB
1564 for (; n-- > 0; i0 += inc0, i1 += inc1)
1565 scm_array_set_x (ra0, SCM_SUBRF (proc) (scm_cvref (ra1, i1, SCM_UNDEFINED)), SCM_MAKINUM (i0));
1566 else
1567 for (; n-- > 0; i0 += inc0, i1 += inc1)
1568 scm_array_set_x (ra0, SCM_SUBRF (proc) (RVREF (ra1, i1, e1)), SCM_MAKINUM (i0));
1569 return 1;
1570}
1571
1572
1cc91f1b
JB
1573
1574static int ramap_2o SCM_P ((SCM ra0, SCM proc, SCM ras));
1575
0f2d19dd
JB
1576static int
1577ramap_2o (ra0, proc, ras)
1578 SCM ra0;
1579 SCM proc;
1580 SCM ras;
0f2d19dd
JB
1581{
1582 SCM ra1 = SCM_CAR (ras);
1583 SCM e1 = SCM_UNDEFINED;
1584 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1585 scm_sizet i0 = SCM_ARRAY_BASE (ra0), i1 = SCM_ARRAY_BASE (ra1);
1586 long inc0 = SCM_ARRAY_DIMS (ra0)->inc, inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1587 ra0 = SCM_ARRAY_V (ra0);
1588 ra1 = SCM_ARRAY_V (ra1);
1589 ras = SCM_CDR (ras);
ff467021 1590 if (SCM_NULLP (ras))
0f2d19dd 1591 {
95f5b0f5
MD
1592 if (scm_tc7_vector == SCM_TYP7 (ra0)
1593 || scm_tc7_wvect == SCM_TYP7 (ra0))
1594
0f2d19dd
JB
1595 for (; n-- > 0; i0 += inc0, i1 += inc1)
1596 scm_array_set_x (ra0, SCM_SUBRF (proc) (scm_cvref (ra1, i1, SCM_UNDEFINED), SCM_UNDEFINED),
1597 SCM_MAKINUM (i0));
1598 else
1599 for (; n-- > 0; i0 += inc0, i1 += inc1)
1600 scm_array_set_x (ra0, SCM_SUBRF (proc) (RVREF (ra1, i1, e1), SCM_UNDEFINED),
1601 SCM_MAKINUM (i0));
1602 }
1603 else
1604 {
1605 SCM ra2 = SCM_CAR (ras);
1606 SCM e2 = SCM_UNDEFINED;
1607 scm_sizet i2 = SCM_ARRAY_BASE (ra2);
1608 long inc2 = SCM_ARRAY_DIMS (ra2)->inc;
1609 ra2 = SCM_ARRAY_V (ra2);
95f5b0f5 1610 if (scm_tc7_vector == SCM_TYP7 (ra0) || scm_tc7_wvect == SCM_TYP7 (ra0))
0f2d19dd
JB
1611 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
1612 scm_array_set_x (ra0,
1613 SCM_SUBRF (proc) (scm_cvref (ra1, i1, SCM_UNDEFINED), scm_cvref (ra2, i2, SCM_UNDEFINED)),
1614 SCM_MAKINUM (i0));
1615 else
1616 for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
1617 scm_array_set_x (ra0,
1618 SCM_SUBRF (proc) (RVREF (ra1, i1, e1), RVREF (ra2, i2, e2)),
1619 SCM_MAKINUM (i0));
1620 }
1621 return 1;
1622}
1623
1624
1cc91f1b
JB
1625
1626static int ramap_a SCM_P ((SCM ra0, SCM proc, SCM ras));
1627
0f2d19dd
JB
1628static int
1629ramap_a (ra0, proc, ras)
1630 SCM ra0;
1631 SCM proc;
1632 SCM ras;
0f2d19dd
JB
1633{
1634 SCM e0 = SCM_UNDEFINED, e1 = SCM_UNDEFINED;
1635 long n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1636 scm_sizet i0 = SCM_ARRAY_BASE (ra0);
1637 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1638 ra0 = SCM_ARRAY_V (ra0);
ff467021 1639 if (SCM_NULLP (ras))
0f2d19dd
JB
1640 for (; n-- > 0; i0 += inc0)
1641 scm_array_set_x (ra0, SCM_SUBRF (proc) (RVREF (ra0, i0, e0), SCM_UNDEFINED), SCM_MAKINUM (i0));
1642 else
1643 {
1644 SCM ra1 = SCM_CAR (ras);
1645 scm_sizet i1 = SCM_ARRAY_BASE (ra1);
1646 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1647 ra1 = SCM_ARRAY_V (ra1);
1648 for (; n-- > 0; i0 += inc0, i1 += inc1)
1649 scm_array_set_x (ra0, SCM_SUBRF (proc) (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1)),
1650 SCM_MAKINUM (i0));
1651 }
1652 return 1;
1653}
1654
dba2ab49 1655/* This name is obsolete. Will go away in release 1.5. */
7e790400 1656SCM_PROC(s_serial_array_map_x, "serial-array-map!", 2, 0, 1, scm_array_map_x);
dba2ab49 1657SCM_PROC(s_array_map_in_order_x, "array-map-in-order!", 2, 0, 1, scm_array_map_x);
7e790400 1658SCM_PROC(s_array_map_x, "array-map!", 2, 0, 1, scm_array_map_x);
1cc91f1b 1659
0f2d19dd 1660SCM
7e790400 1661scm_array_map_x (ra0, proc, lra)
0f2d19dd
JB
1662 SCM ra0;
1663 SCM proc;
1664 SCM lra;
0f2d19dd 1665{
7e790400 1666 SCM_ASSERT (SCM_BOOL_T == scm_procedure_p (proc), proc, SCM_ARG2, s_array_map_x);
0f2d19dd
JB
1667 switch (SCM_TYP7 (proc))
1668 {
1669 default:
1670 gencase:
7e790400 1671 scm_ramapc (ramap, proc, ra0, lra, s_array_map_x);
0f2d19dd
JB
1672 return SCM_UNSPECIFIED;
1673 case scm_tc7_subr_1:
7e790400 1674 scm_ramapc (ramap_1, proc, ra0, lra, s_array_map_x);
0f2d19dd
JB
1675 return SCM_UNSPECIFIED;
1676 case scm_tc7_subr_2:
1677 case scm_tc7_subr_2o:
7e790400 1678 scm_ramapc (ramap_2o, proc, ra0, lra, s_array_map_x);
0f2d19dd
JB
1679 return SCM_UNSPECIFIED;
1680 case scm_tc7_cxr:
1681 if (!SCM_SUBRF (proc))
1682 goto gencase;
7e790400 1683 scm_ramapc (ramap_cxr, proc, ra0, lra, s_array_map_x);
0f2d19dd
JB
1684 return SCM_UNSPECIFIED;
1685 case scm_tc7_rpsubr:
1686 {
1687 ra_iproc *p;
1688 if (SCM_FALSEP (scm_array_p (ra0, SCM_BOOL_T)))
1689 goto gencase;
1690 scm_array_fill_x (ra0, SCM_BOOL_T);
1691 for (p = ra_rpsubrs; p->name; p++)
1692 if (proc == p->sproc)
1693 {
1694 while (SCM_NNULLP (lra) && SCM_NNULLP (SCM_CDR (lra)))
1695 {
7e790400 1696 scm_ramapc (p->vproc, SCM_UNDEFINED, ra0, lra, s_array_map_x);
0f2d19dd
JB
1697 lra = SCM_CDR (lra);
1698 }
1699 return SCM_UNSPECIFIED;
1700 }
1701 while (SCM_NNULLP (lra) && SCM_NNULLP (SCM_CDR (lra)))
1702 {
7e790400 1703 scm_ramapc (ramap_rp, proc, ra0, lra, s_array_map_x);
0f2d19dd
JB
1704 lra = SCM_CDR (lra);
1705 }
1706 return SCM_UNSPECIFIED;
1707 }
1708 case scm_tc7_asubr:
ff467021 1709 if (SCM_NULLP (lra))
0f2d19dd
JB
1710 {
1711 SCM prot, fill = SCM_SUBRF (proc) (SCM_UNDEFINED, SCM_UNDEFINED);
ff467021 1712 if (SCM_INUMP(fill))
0f2d19dd
JB
1713 {
1714 prot = scm_array_prototype (ra0);
1715 if (SCM_NIMP (prot) && SCM_INEXP (prot))
1716 fill = scm_makdbl ((double) SCM_INUM (fill), 0.0);
1717 }
1718
1719 scm_array_fill_x (ra0, fill);
1720 }
1721 else
1722 {
1723 SCM tail, ra1 = SCM_CAR (lra);
1724 SCM v0 = (SCM_NIMP (ra0) && SCM_ARRAYP (ra0) ? SCM_ARRAY_V (ra0) : ra0);
1725 ra_iproc *p;
1726 /* Check to see if order might matter.
1727 This might be an argument for a separate
1728 SERIAL-ARRAY-MAP! */
1729 if (v0 == ra1 || (SCM_NIMP (ra1) && SCM_ARRAYP (ra1) && v0 == SCM_ARRAY_V (ra1)))
1730 if (ra0 != ra1 || (SCM_ARRAYP(ra0) && !SCM_ARRAY_CONTP(ra0)))
1731 goto gencase;
1732 for (tail = SCM_CDR (lra); SCM_NNULLP (tail); tail = SCM_CDR (tail))
1733 {
1734 ra1 = SCM_CAR (tail);
1735 if (v0 == ra1 || (SCM_NIMP (ra1) && SCM_ARRAYP (ra1) && v0 == SCM_ARRAY_V (ra1)))
1736 goto gencase;
1737 }
1738 for (p = ra_asubrs; p->name; p++)
1739 if (proc == p->sproc)
1740 {
1741 if (ra0 != SCM_CAR (lra))
7e790400 1742 scm_ramapc (scm_array_identity, SCM_UNDEFINED, ra0, scm_cons (SCM_CAR (lra), SCM_EOL), s_array_map_x);
0f2d19dd
JB
1743 lra = SCM_CDR (lra);
1744 while (1)
1745 {
7e790400 1746 scm_ramapc (p->vproc, SCM_UNDEFINED, ra0, lra, s_array_map_x);
0f2d19dd
JB
1747 if (SCM_IMP (lra) || SCM_IMP (SCM_CDR (lra)))
1748 return SCM_UNSPECIFIED;
1749 lra = SCM_CDR (lra);
1750 }
1751 }
7e790400 1752 scm_ramapc (ramap_2o, proc, ra0, lra, s_array_map_x);
0f2d19dd 1753 lra = SCM_CDR (lra);
ff467021 1754 if (SCM_NIMP (lra))
0f2d19dd 1755 for (lra = SCM_CDR (lra); SCM_NIMP (lra); lra = SCM_CDR (lra))
7e790400 1756 scm_ramapc (ramap_a, proc, ra0, lra, s_array_map_x);
0f2d19dd
JB
1757 }
1758 return SCM_UNSPECIFIED;
1759 }
1760}
1761
1cc91f1b
JB
1762
1763static int rafe SCM_P ((SCM ra0, SCM proc, SCM ras));
1764
0f2d19dd
JB
1765static int
1766rafe (ra0, proc, ras)
1767 SCM ra0;
1768 SCM proc;
1769 SCM ras;
0f2d19dd
JB
1770{
1771 long i = SCM_ARRAY_DIMS (ra0)->lbnd;
1772 scm_sizet i0 = SCM_ARRAY_BASE (ra0);
1773 long inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1774 long n = SCM_ARRAY_DIMS (ra0)->ubnd;
1775 ra0 = SCM_ARRAY_V (ra0);
ff467021 1776 if (SCM_NULLP (ras))
0f2d19dd
JB
1777 for (; i <= n; i++, i0 += inc0)
1778 scm_apply (proc, scm_cvref (ra0, i0, SCM_UNDEFINED), scm_listofnull);
1779 else
1780 {
1781 SCM ra1 = SCM_CAR (ras);
1782 SCM args, *ve = &ras;
1783 scm_sizet k, i1 = SCM_ARRAY_BASE (ra1);
1784 long inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1785 ra1 = SCM_ARRAY_V (ra1);
1786 ras = SCM_CDR (ras);
ff467021 1787 if (SCM_NULLP(ras))
0f2d19dd
JB
1788 ras = scm_nullvect;
1789 else
1790 {
1791 ras = scm_vector (ras);
1792 ve = SCM_VELTS (ras);
1793 }
1794 for (; i <= n; i++, i0 += inc0, i1 += inc1)
1795 {
1796 args = SCM_EOL;
1797 for (k = SCM_LENGTH (ras); k--;)
1798 args = scm_cons (scm_uniform_vector_ref (ve[k], SCM_MAKINUM (i)), args);
1799 args = scm_cons2 (scm_cvref (ra0, i0, SCM_UNDEFINED), scm_cvref (ra1, i1, SCM_UNDEFINED), args);
1800 scm_apply (proc, args, SCM_EOL);
1801 }
1802 }
1803 return 1;
1804}
1805
1806
1807SCM_PROC(s_array_for_each, "array-for-each", 2, 0, 1, scm_array_for_each);
1cc91f1b 1808
0f2d19dd
JB
1809SCM
1810scm_array_for_each (proc, ra0, lra)
1811 SCM proc;
1812 SCM ra0;
1813 SCM lra;
0f2d19dd
JB
1814{
1815 SCM_ASSERT (SCM_BOOL_T == scm_procedure_p (proc), proc, SCM_ARG1, s_array_for_each);
1816 scm_ramapc (rafe, proc, ra0, lra, s_array_for_each);
1817 return SCM_UNSPECIFIED;
1818}
1819
1820SCM_PROC(s_array_index_map_x, "array-index-map!", 2, 0, 0, scm_array_index_map_x);
1cc91f1b 1821
0f2d19dd
JB
1822SCM
1823scm_array_index_map_x (ra, proc)
1824 SCM ra;
1825 SCM proc;
0f2d19dd
JB
1826{
1827 scm_sizet i;
1828 SCM_ASSERT (SCM_NIMP (ra), ra, SCM_ARG1, s_array_index_map_x);
e42c09cc
RS
1829 SCM_ASSERT (SCM_BOOL_T == scm_procedure_p (proc), proc, SCM_ARG2,
1830 s_array_index_map_x);
1831 switch (SCM_TYP7(ra))
1832 {
1833 default:
1834 badarg:scm_wta (ra, (char *) SCM_ARG1, s_array_index_map_x);
1835 case scm_tc7_vector:
1836 case scm_tc7_wvect:
0f2d19dd 1837 {
e42c09cc 1838 SCM *ve = SCM_VELTS (ra);
0f2d19dd 1839 for (i = 0; i < SCM_LENGTH (ra); i++)
e42c09cc
RS
1840 ve[i] = scm_apply (proc, SCM_MAKINUM (i), scm_listofnull);
1841 return SCM_UNSPECIFIED;
1842 }
1843 case scm_tc7_string:
1844 case scm_tc7_byvect:
1845 case scm_tc7_bvect:
1846 case scm_tc7_uvect:
1847 case scm_tc7_ivect:
05f92e0f 1848 case scm_tc7_svect:
5c11cc9d 1849#ifdef HAVE_LONG_LONGS
05f92e0f
JB
1850 case scm_tc7_llvect:
1851#endif
e42c09cc
RS
1852 case scm_tc7_fvect:
1853 case scm_tc7_dvect:
1854 case scm_tc7_cvect:
1855 for (i = 0; i < SCM_LENGTH (ra); i++)
1856 scm_array_set_x (ra, scm_apply (proc, SCM_MAKINUM (i), scm_listofnull),
1857 SCM_MAKINUM (i));
1858 return SCM_UNSPECIFIED;
1859 case scm_tc7_smob:
1860 SCM_ASRTGO (SCM_ARRAYP (ra), badarg);
1861 {
1862 SCM args = SCM_EOL;
1863 SCM inds = scm_make_uve (SCM_ARRAY_NDIM (ra), SCM_MAKINUM (-1L));
1864 long *vinds = SCM_VELTS (inds);
1865 int j, k, kmax = SCM_ARRAY_NDIM (ra) - 1;
1866 if (kmax < 0)
1867 return scm_array_set_x (ra, scm_apply(proc, SCM_EOL, SCM_EOL),
1868 SCM_EOL);
1869 for (k = 0; k <= kmax; k++)
1870 vinds[k] = SCM_ARRAY_DIMS (ra)[k].lbnd;
1871 k = kmax;
1872 do
1873 {
1874 if (k == kmax)
1875 {
1876 vinds[k] = SCM_ARRAY_DIMS (ra)[k].lbnd;
1877 i = cind (ra, inds);
1878 for (; vinds[k] <= SCM_ARRAY_DIMS (ra)[k].ubnd; vinds[k]++)
1879 {
1880 for (j = kmax + 1, args = SCM_EOL; j--;)
1881 args = scm_cons (SCM_MAKINUM (vinds[j]), args);
1882 scm_array_set_x (SCM_ARRAY_V (ra),
1883 scm_apply (proc, args, SCM_EOL),
1884 SCM_MAKINUM (i));
1885 i += SCM_ARRAY_DIMS (ra)[k].inc;
1886 }
1887 k--;
1888 continue;
1889 }
1890 if (vinds[k] < SCM_ARRAY_DIMS (ra)[k].ubnd)
1891 {
1892 vinds[k]++;
1893 k++;
1894 continue;
1895 }
1896 vinds[k] = SCM_ARRAY_DIMS (ra)[k].lbnd - 1;
1897 k--;
1898 }
1899 while (k >= 0);
0f2d19dd 1900 return SCM_UNSPECIFIED;
0f2d19dd 1901 }
e42c09cc 1902 }
0f2d19dd
JB
1903}
1904
1cc91f1b
JB
1905
1906static int raeql_1 SCM_P ((SCM ra0, SCM as_equal, SCM ra1));
1907
0f2d19dd
JB
1908static int
1909raeql_1 (ra0, as_equal, ra1)
1910 SCM ra0;
1911 SCM as_equal;
1912 SCM ra1;
0f2d19dd
JB
1913{
1914 SCM e0 = SCM_UNDEFINED, e1 = SCM_UNDEFINED;
1915 scm_sizet i0 = 0, i1 = 0;
1916 long inc0 = 1, inc1 = 1;
1917 scm_sizet n = SCM_LENGTH (ra0);
1918 ra1 = SCM_CAR (ra1);
ff467021 1919 if (SCM_ARRAYP(ra0))
0f2d19dd
JB
1920 {
1921 n = SCM_ARRAY_DIMS (ra0)->ubnd - SCM_ARRAY_DIMS (ra0)->lbnd + 1;
1922 i0 = SCM_ARRAY_BASE (ra0);
1923 inc0 = SCM_ARRAY_DIMS (ra0)->inc;
1924 ra0 = SCM_ARRAY_V (ra0);
1925 }
ff467021 1926 if (SCM_ARRAYP (ra1))
0f2d19dd
JB
1927 {
1928 i1 = SCM_ARRAY_BASE (ra1);
1929 inc1 = SCM_ARRAY_DIMS (ra1)->inc;
1930 ra1 = SCM_ARRAY_V (ra1);
1931 }
ff467021 1932 switch (SCM_TYP7 (ra0))
0f2d19dd
JB
1933 {
1934 case scm_tc7_vector:
95f5b0f5 1935 case scm_tc7_wvect:
0f2d19dd
JB
1936 default:
1937 for (; n--; i0 += inc0, i1 += inc1)
1938 {
ff467021 1939 if (SCM_FALSEP (as_equal))
0f2d19dd 1940 {
ff467021 1941 if (SCM_FALSEP (scm_array_equal_p (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1))))
0f2d19dd
JB
1942 return 0;
1943 }
ff467021 1944 else if (SCM_FALSEP (scm_equal_p (RVREF (ra0, i0, e0), RVREF (ra1, i1, e1))))
0f2d19dd
JB
1945 return 0;
1946 }
1947 return 1;
1948 case scm_tc7_string:
b1d24656 1949 case scm_tc7_byvect:
0f2d19dd
JB
1950 {
1951 char *v0 = SCM_CHARS (ra0) + i0;
1952 char *v1 = SCM_CHARS (ra1) + i1;
1953 for (; n--; v0 += inc0, v1 += inc1)
1954 if (*v0 != *v1)
1955 return 0;
1956 return 1;
1957 }
1958 case scm_tc7_bvect:
1959 for (; n--; i0 += inc0, i1 += inc1)
1960 if (BVE_REF (ra0, i0) != BVE_REF (ra1, i1))
1961 return 0;
1962 return 1;
1963 case scm_tc7_uvect:
1964 case scm_tc7_ivect:
1965 {
1966 long *v0 = (long *) SCM_VELTS (ra0) + i0;
1967 long *v1 = (long *) SCM_VELTS (ra1) + i1;
1968 for (; n--; v0 += inc0, v1 += inc1)
1969 if (*v0 != *v1)
1970 return 0;
1971 return 1;
1972 }
05f92e0f
JB
1973 case scm_tc7_svect:
1974 {
1975 short *v0 = (short *) SCM_VELTS (ra0) + i0;
1976 short *v1 = (short *) SCM_VELTS (ra1) + i1;
1977 for (; n--; v0 += inc0, v1 += inc1)
1978 if (*v0 != *v1)
1979 return 0;
1980 return 1;
1981 }
5c11cc9d 1982#ifdef HAVE_LONG_LONGS
05f92e0f
JB
1983 case scm_tc7_llvect:
1984 {
1985 long long *v0 = (long long *) SCM_VELTS (ra0) + i0;
1986 long long *v1 = (long long *) SCM_VELTS (ra1) + i1;
1987 for (; n--; v0 += inc0, v1 += inc1)
1988 if (*v0 != *v1)
1989 return 0;
1990 return 1;
1991 }
1992#endif
0f2d19dd
JB
1993#ifdef SCM_FLOATS
1994#ifdef SCM_SINGLES
1995 case scm_tc7_fvect:
1996 {
1997 float *v0 = (float *) SCM_VELTS (ra0) + i0;
1998 float *v1 = (float *) SCM_VELTS (ra1) + i1;
1999 for (; n--; v0 += inc0, v1 += inc1)
2000 if (*v0 != *v1)
2001 return 0;
2002 return 1;
2003 }
2004#endif /* SCM_SINGLES */
2005 case scm_tc7_dvect:
2006 {
2007 double *v0 = (double *) SCM_VELTS (ra0) + i0;
2008 double *v1 = (double *) SCM_VELTS (ra1) + i1;
2009 for (; n--; v0 += inc0, v1 += inc1)
2010 if (*v0 != *v1)
2011 return 0;
2012 return 1;
2013 }
2014 case scm_tc7_cvect:
2015 {
2016 double (*v0)[2] = (double (*)[2]) SCM_VELTS (ra0) + i0;
2017 double (*v1)[2] = (double (*)[2]) SCM_VELTS (ra1) + i1;
2018 for (; n--; v0 += inc0, v1 += inc1)
2019 {
2020 if ((*v0)[0] != (*v1)[0])
2021 return 0;
2022 if ((*v0)[1] != (*v1)[1])
2023 return 0;
2024 }
2025 return 1;
2026 }
2027#endif /* SCM_FLOATS */
2028 }
2029}
2030
2031
1cc91f1b
JB
2032
2033static int raeql SCM_P ((SCM ra0, SCM as_equal, SCM ra1));
2034
0f2d19dd
JB
2035static int
2036raeql (ra0, as_equal, ra1)
2037 SCM ra0;
2038 SCM as_equal;
2039 SCM ra1;
0f2d19dd
JB
2040{
2041 SCM v0 = ra0, v1 = ra1;
2042 scm_array_dim dim0, dim1;
2043 scm_array_dim *s0 = &dim0, *s1 = &dim1;
2044 scm_sizet bas0 = 0, bas1 = 0;
2045 int k, unroll = 1, vlen = 1, ndim = 1;
ff467021 2046 if (SCM_ARRAYP (ra0))
0f2d19dd
JB
2047 {
2048 ndim = SCM_ARRAY_NDIM (ra0);
2049 s0 = SCM_ARRAY_DIMS (ra0);
2050 bas0 = SCM_ARRAY_BASE (ra0);
2051 v0 = SCM_ARRAY_V (ra0);
2052 }
2053 else
2054 {
2055 s0->inc = 1;
2056 s0->lbnd = 0;
2057 s0->ubnd = SCM_LENGTH (v0) - 1;
2058 unroll = 0;
2059 }
ff467021 2060 if (SCM_ARRAYP (ra1))
0f2d19dd
JB
2061 {
2062 if (ndim != SCM_ARRAY_NDIM (ra1))
2063 return 0;
2064 s1 = SCM_ARRAY_DIMS (ra1);
2065 bas1 = SCM_ARRAY_BASE (ra1);
2066 v1 = SCM_ARRAY_V (ra1);
2067 }
2068 else
2069 {
2070 if (1 != ndim)
2071 return SCM_BOOL_F;
2072 s1->inc = 1;
2073 s1->lbnd = 0;
2074 s1->ubnd = SCM_LENGTH (v1) - 1;
2075 unroll = 0;
2076 }
2077 if (SCM_TYP7 (v0) != SCM_TYP7 (v1))
2078 return 0;
2079 for (k = ndim; k--;)
2080 {
2081 if (s0[k].lbnd != s1[k].lbnd || s0[k].ubnd != s1[k].ubnd)
2082 return 0;
2083 if (unroll)
2084 {
2085 unroll = (s0[k].inc == s1[k].inc);
2086 vlen *= s0[k].ubnd - s1[k].lbnd + 1;
2087 }
2088 }
2089 if (unroll && bas0 == bas1 && v0 == v1)
2090 return SCM_BOOL_T;
2091 return scm_ramapc (raeql_1, as_equal, ra0, scm_cons (ra1, SCM_EOL), "");
2092}
2093
1cc91f1b 2094
0f2d19dd
JB
2095SCM
2096scm_raequal (ra0, ra1)
2097 SCM ra0;
2098 SCM ra1;
0f2d19dd
JB
2099{
2100 return (raeql (ra0, SCM_BOOL_T, ra1) ? SCM_BOOL_T : SCM_BOOL_F);
2101}
2102
2103static char s_array_equal_p[] = "array-equal?";
2104
1cc91f1b 2105
0f2d19dd
JB
2106SCM
2107scm_array_equal_p (ra0, ra1)
2108 SCM ra0;
2109 SCM ra1;
0f2d19dd
JB
2110{
2111 if (SCM_IMP (ra0) || SCM_IMP (ra1))
2112 callequal:return scm_equal_p (ra0, ra1);
ff467021 2113 switch (SCM_TYP7(ra0))
0f2d19dd
JB
2114 {
2115 default:
2116 goto callequal;
2117 case scm_tc7_bvect:
2118 case scm_tc7_string:
b1d24656 2119 case scm_tc7_byvect:
0f2d19dd
JB
2120 case scm_tc7_uvect:
2121 case scm_tc7_ivect:
2122 case scm_tc7_fvect:
2123 case scm_tc7_dvect:
2124 case scm_tc7_cvect:
2125 case scm_tc7_vector:
95f5b0f5 2126 case scm_tc7_wvect:
0f2d19dd
JB
2127 break;
2128 case scm_tc7_smob:
2129 if (!SCM_ARRAYP (ra0))
2130 goto callequal;
2131 }
ff467021 2132 switch (SCM_TYP7 (ra1))
0f2d19dd
JB
2133 {
2134 default:
2135 goto callequal;
2136 case scm_tc7_bvect:
2137 case scm_tc7_string:
b1d24656 2138 case scm_tc7_byvect:
0f2d19dd
JB
2139 case scm_tc7_uvect:
2140 case scm_tc7_ivect:
2141 case scm_tc7_fvect:
2142 case scm_tc7_dvect:
2143 case scm_tc7_cvect:
2144 case scm_tc7_vector:
95f5b0f5 2145 case scm_tc7_wvect:
0f2d19dd
JB
2146 break;
2147 case scm_tc7_smob:
2148 if (!SCM_ARRAYP (ra1))
2149 goto callequal;
2150 }
2151 return (raeql (ra0, SCM_BOOL_F, ra1) ? SCM_BOOL_T : SCM_BOOL_F);
2152}
2153
2154
2155
1cc91f1b
JB
2156static void
2157init_raprocs (subra)
0f2d19dd
JB
2158 ra_iproc *subra;
2159{
2160 for (; subra->name; subra++)
2161 subra->sproc = SCM_CDR (scm_intern (subra->name, strlen (subra->name)));
2162}
2163
1cc91f1b 2164
0f2d19dd
JB
2165void
2166scm_init_ramap ()
0f2d19dd
JB
2167{
2168 init_raprocs (ra_rpsubrs);
2169 init_raprocs (ra_asubrs);
2170 scm_make_subr (s_array_equal_p, scm_tc7_rpsubr, scm_array_equal_p);
2171 scm_smobs[0x0ff & (scm_tc16_array >> 8)].equalp = scm_raequal;
2172#include "ramap.x"
2173 scm_add_feature (s_array_for_each);
2174}