1 /* Copyright (C) 1996 Free Software Foundation, Inc.
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)
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.
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
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
68 /* These tables are a kluge that will not scale well when more
69 * vectorized subrs are added. It is tempting to steal some bits from
70 * the SCM_CAR of all subrs (like those selected by SCM_SMOBNUM) to hold an
71 * offset into a table of vectorized subrs.
74 static ra_iproc ra_rpsubrs
[] =
76 {"=", SCM_UNDEFINED
, scm_ra_eqp
},
77 {"<", SCM_UNDEFINED
, scm_ra_lessp
},
78 {"<=", SCM_UNDEFINED
, scm_ra_leqp
},
79 {">", SCM_UNDEFINED
, scm_ra_grp
},
80 {">=", SCM_UNDEFINED
, scm_ra_greqp
},
84 static ra_iproc ra_asubrs
[] =
86 {"+", SCM_UNDEFINED
, scm_ra_sum
},
87 {"-", SCM_UNDEFINED
, scm_ra_difference
},
88 {"*", SCM_UNDEFINED
, scm_ra_product
},
89 {"/", SCM_UNDEFINED
, scm_ra_divide
},
94 #define BVE_REF(a, i) ((SCM_VELTS(a)[(i)/SCM_LONG_BIT] & (1L<<((i)%SCM_LONG_BIT))) ? 1 : 0)
95 #define BVE_SET(a, i) (SCM_VELTS(a)[(i)/SCM_LONG_BIT] |= (1L<<((i)%SCM_LONG_BIT)))
96 #define BVE_CLR(a, i) (SCM_VELTS(a)[(i)/SCM_LONG_BIT] &= ~(1L<<((i)%SCM_LONG_BIT)))
98 /* Fast, recycling scm_vector ref */
99 #define RVREF(ra, i, e) (e = scm_cvref(ra, i, e))
101 /* #define RVREF(ra, i, e) (scm_cvref(ra, i, SCM_UNDEFINED)) to turn off */
103 /* IVDEP means "ignore scm_vector dependencies", meaning we guarantee that
104 elements of scm_vector operands are not aliased */
106 #define IVDEP(test, line) if (test) {_Pragma("ivdep"); line} else {line}
108 #define IVDEP(test, line) line
113 /* inds must be a uvect or ivect, no check. */
116 static scm_sizet cind
SCM_P ((SCM ra
, SCM inds
));
125 long *ve
= SCM_VELTS (inds
);
126 if (!SCM_ARRAYP (ra
))
128 i
= SCM_ARRAY_BASE (ra
);
129 for (k
= 0; k
< SCM_ARRAY_NDIM (ra
); k
++)
130 i
+= (ve
[k
] - SCM_ARRAY_DIMS (ra
)[k
].lbnd
) * SCM_ARRAY_DIMS (ra
)[k
].inc
;
135 /* Checker for scm_array mapping functions:
136 return values: 4 --> shapes, increments, and bases are the same;
137 3 --> shapes and increments are the same;
138 2 --> shapes are the same;
139 1 --> ras are at least as big as ra0;
144 scm_ra_matchp (ra0
, ras
)
150 scm_array_dim
*s0
= &dims
;
154 int exact
= 2 /* 4 */ ; /* Don't care about values >2 (yet?) */
157 switch (SCM_TYP7 (ra0
))
171 s0
->ubnd
= (long) SCM_LENGTH (ra0
) - 1;
174 if (!SCM_ARRAYP (ra0
))
176 ndim
= SCM_ARRAY_NDIM (ra0
);
177 s0
= SCM_ARRAY_DIMS (ra0
);
178 bas0
= SCM_ARRAY_BASE (ra0
);
211 if ((0 == s0
->lbnd
) && (s0
->ubnd
== SCM_LENGTH (ra1
) - 1))
215 if (s0
->lbnd
< 0 || s0
->ubnd
>= SCM_LENGTH (ra1
))
220 if (!SCM_ARRAYP (ra1
) || ndim
!= SCM_ARRAY_NDIM (ra1
))
222 s1
= SCM_ARRAY_DIMS (ra1
);
223 if (bas0
!= SCM_ARRAY_BASE (ra1
))
225 for (i
= 0; i
< ndim
; i
++)
230 if (s0
[i
].inc
!= s1
[i
].inc
)
233 if (s0
[i
].lbnd
== s1
[i
].lbnd
&& s0
[i
].ubnd
== s1
[i
].ubnd
)
237 if (s0
[i
].lbnd
< s1
[i
].lbnd
|| s0
[i
].ubnd
> s1
[i
].ubnd
)
238 return (s0
[i
].lbnd
<= s0
[i
].ubnd
? 0 : 1);
247 static char s_ra_mismatch
[] = "array shape mismatch";
250 scm_ramapc (cproc
, data
, ra0
, lra
, what
)
262 switch (scm_ra_matchp (ra0
, lra
))
266 scm_wta (ra0
, s_ra_mismatch
, what
);
269 case 4: /* Try unrolling arrays */
270 kmax
= (SCM_ARRAYP (ra0
) ? SCM_ARRAY_NDIM (ra0
) - 1 : 0);
273 vra0
= scm_array_contents (ra0
, SCM_UNDEFINED
);
276 if (!SCM_ARRAYP (vra0
))
278 vra1
= scm_make_ra (1);
279 SCM_ARRAY_BASE (vra1
) = 0;
280 SCM_ARRAY_DIMS (vra1
)->lbnd
= 0;
281 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_LENGTH (vra0
) - 1;
282 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
283 SCM_ARRAY_V (vra1
) = vra0
;
288 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
291 vra1
= scm_make_ra (1);
292 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
293 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
294 if (!SCM_ARRAYP (ra1
))
296 SCM_ARRAY_BASE (vra1
) = 0;
297 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
298 SCM_ARRAY_V (vra1
) = ra1
;
300 else if (!SCM_ARRAY_CONTP (ra1
))
304 SCM_ARRAY_BASE (vra1
) = SCM_ARRAY_BASE (ra1
);
305 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
306 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
308 *plvra
= scm_cons (vra1
, SCM_EOL
);
309 plvra
= SCM_CDRLOC (*plvra
);
311 return (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
));
313 gencase
: /* Have to loop over all dimensions. */
314 vra0
= scm_make_ra (1);
318 kmax
= SCM_ARRAY_NDIM (ra0
) - 1;
321 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
322 SCM_ARRAY_DIMS (vra0
)->ubnd
= 0;
323 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
327 SCM_ARRAY_DIMS (vra0
)->lbnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].lbnd
;
328 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].ubnd
;
329 SCM_ARRAY_DIMS (vra0
)->inc
= SCM_ARRAY_DIMS (ra0
)[kmax
].inc
;
331 SCM_ARRAY_BASE (vra0
) = SCM_ARRAY_BASE (ra0
);
332 SCM_ARRAY_V (vra0
) = SCM_ARRAY_V (ra0
);
337 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
338 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_LENGTH (ra0
) - 1;
339 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
340 SCM_ARRAY_BASE (vra0
) = 0;
341 SCM_ARRAY_V (vra0
) = ra0
;
346 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
349 vra1
= scm_make_ra (1);
350 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
351 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
356 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
357 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
361 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
362 SCM_ARRAY_V (vra1
) = ra1
;
364 *plvra
= scm_cons (vra1
, SCM_EOL
);
365 plvra
= SCM_CDRLOC (*plvra
);
367 inds
= scm_make_uve (SCM_ARRAY_NDIM (ra0
), SCM_MAKINUM (-1L));
368 vinds
= (long *) SCM_VELTS (inds
);
369 for (k
= 0; k
<= kmax
; k
++)
370 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
;
377 SCM_ARRAY_BASE (vra0
) = cind (ra0
, inds
);
378 for (z
= lvra
; SCM_NIMP (z
); z
= SCM_CDR (z
), y
= SCM_CDR (y
))
379 SCM_ARRAY_BASE (SCM_CAR (z
)) = cind (SCM_CAR (y
), inds
);
380 if (0 == (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
)))
385 if (vinds
[k
] < SCM_ARRAY_DIMS (ra0
)[k
].ubnd
)
391 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
- 1;
400 SCM_PROC(s_array_fill_x
, "array-fill!", 2, 0, 0, scm_array_fill_x
);
403 scm_array_fill_x (ra
, fill
)
407 scm_ramapc (scm_array_fill_int
, fill
, ra
, SCM_EOL
, s_array_fill_x
);
408 return SCM_UNSPECIFIED
;
413 scm_array_fill_int (ra
, fill
, ignore
)
418 scm_sizet i
, n
= SCM_ARRAY_DIMS (ra
)->ubnd
- SCM_ARRAY_DIMS (ra
)->lbnd
+ 1;
419 long inc
= SCM_ARRAY_DIMS (ra
)->inc
;
420 scm_sizet base
= SCM_ARRAY_BASE (ra
);
421 ra
= SCM_ARRAY_V (ra
);
426 for (i
= base
; n
--; i
+= inc
)
427 scm_array_set_x (ra
, fill
, SCM_MAKINUM (i
));
430 for (i
= base
; n
--; i
+= inc
)
431 SCM_VELTS (ra
)[i
] = fill
;
434 SCM_ASRTGO (SCM_ICHRP (fill
), badarg2
);
435 for (i
= base
; n
--; i
+= inc
)
436 SCM_CHARS (ra
)[i
] = SCM_ICHR (fill
);
440 long *ve
= (long *) SCM_VELTS (ra
);
441 if (1 == inc
&& (n
>= SCM_LONG_BIT
|| n
== SCM_LENGTH (ra
)))
443 i
= base
/ SCM_LONG_BIT
;
444 if (SCM_BOOL_F
== fill
)
446 if (base
% SCM_LONG_BIT
) /* leading partial word */
447 ve
[i
++] &= ~(~0L << (base
% SCM_LONG_BIT
));
448 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
450 if ((base
+ n
) % SCM_LONG_BIT
) /* trailing partial word */
451 ve
[i
] &= (~0L << ((base
+ n
) % SCM_LONG_BIT
));
453 else if (SCM_BOOL_T
== fill
)
455 if (base
% SCM_LONG_BIT
)
456 ve
[i
++] |= ~0L << (base
% SCM_LONG_BIT
);
457 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
459 if ((base
+ n
) % SCM_LONG_BIT
)
460 ve
[i
] |= ~(~0L << ((base
+ n
) % SCM_LONG_BIT
));
463 badarg2
:scm_wta (fill
, (char *) SCM_ARG2
, s_array_fill_x
);
467 if (SCM_BOOL_F
== fill
)
468 for (i
= base
; n
--; i
+= inc
)
469 ve
[i
/ SCM_LONG_BIT
] &= ~(1L << (i
% SCM_LONG_BIT
));
470 else if (SCM_BOOL_T
== fill
)
471 for (i
= base
; n
--; i
+= inc
)
472 ve
[i
/ SCM_LONG_BIT
] |= (1L << (i
% SCM_LONG_BIT
));
479 SCM_ASRTGO (0 <= SCM_INUM (fill
), badarg2
);
481 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
483 long f
= SCM_INUM (fill
), *ve
= (long *) SCM_VELTS (ra
);
484 for (i
= base
; n
--; i
+= inc
)
492 float f
, *ve
= (float *) SCM_VELTS (ra
);
493 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
494 f
= SCM_REALPART (fill
);
495 for (i
= base
; n
--; i
+= inc
)
499 #endif /* SCM_SINGLES */
502 double f
, *ve
= (double *) SCM_VELTS (ra
);
503 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
504 f
= SCM_REALPART (fill
);
505 for (i
= base
; n
--; i
+= inc
)
512 double (*ve
)[2] = (double (*)[2]) SCM_VELTS (ra
);
513 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_INEXP (fill
), badarg2
);
514 fr
= SCM_REALPART (fill
);
515 fi
= (SCM_CPLXP (fill
) ? SCM_IMAG (fill
) : 0.0);
516 for (i
= base
; n
--; i
+= inc
)
523 #endif /* SCM_FLOATS */
531 static int racp
SCM_P ((SCM dst
, SCM src
));
538 long n
= (SCM_ARRAY_DIMS (src
)->ubnd
- SCM_ARRAY_DIMS (src
)->lbnd
+ 1);
539 long inc_d
, inc_s
= SCM_ARRAY_DIMS (src
)->inc
;
540 scm_sizet i_d
, i_s
= SCM_ARRAY_BASE (src
);
542 inc_d
= SCM_ARRAY_DIMS (dst
)->inc
;
543 i_d
= SCM_ARRAY_BASE (dst
);
544 src
= SCM_ARRAY_V (src
);
545 dst
= SCM_ARRAY_V (dst
);
550 gencase
: case scm_tc7_vector
:
551 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
552 scm_array_set_x (dst
, scm_cvref (src
, i_s
, SCM_UNDEFINED
), SCM_MAKINUM (i_d
));
555 if (scm_tc7_string
!= SCM_TYP7 (dst
))
557 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
558 SCM_CHARS (dst
)[i_d
] = SCM_CHARS (src
)[i_s
];
561 if (scm_tc7_bvect
!= SCM_TYP7 (dst
))
563 if (1 == inc_d
&& 1 == inc_s
&& i_s
% SCM_LONG_BIT
== i_d
% SCM_LONG_BIT
&& n
>= SCM_LONG_BIT
)
565 long *sv
= (long *) SCM_VELTS (src
);
566 long *dv
= (long *) SCM_VELTS (dst
);
567 sv
+= i_s
/ SCM_LONG_BIT
;
568 dv
+= i_d
/ SCM_LONG_BIT
;
569 if (i_s
% SCM_LONG_BIT
)
570 { /* leading partial word */
571 *dv
= (*dv
& ~(~0L << (i_s
% SCM_LONG_BIT
))) | (*sv
& (~0L << (i_s
% SCM_LONG_BIT
)));
574 n
-= SCM_LONG_BIT
- (i_s
% SCM_LONG_BIT
);
577 for (; n
>= SCM_LONG_BIT
; n
-= SCM_LONG_BIT
, sv
++, dv
++)
579 if (n
) /* trailing partial word */
580 *dv
= (*dv
& (~0L << n
)) | (*sv
& ~(~0L << n
));
584 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
585 if (SCM_VELTS (src
)[i_s
/ SCM_LONG_BIT
] & (1L << (i_s
% SCM_LONG_BIT
)))
586 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] |= (1L << (i_d
% SCM_LONG_BIT
));
588 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] &= ~(1L << (i_d
% SCM_LONG_BIT
));
592 if (scm_tc7_uvect
!= SCM_TYP7 (src
))
596 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
598 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
603 if (scm_tc7_uvect
!= SCM_TYP7 (src
) && scm_tc7_ivect
!= SCM_TYP7 (src
))
607 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
609 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
617 float *d
= (float *) SCM_VELTS (dst
);
618 float *s
= (float *) SCM_VELTS (src
);
627 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
628 d
[i_d
] = ((long *) s
)[i_s
];)
632 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
637 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
638 d
[i_d
] = ((double *) s
)[i_s
];)
643 #endif /* SCM_SINGLES */
646 double *d
= (double *) SCM_VELTS (dst
);
647 double *s
= (double *) SCM_VELTS (src
);
656 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
657 d
[i_d
] = ((long *) s
)[i_s
];)
661 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
662 d
[i_d
] = ((float *) s
)[i_s
];)
666 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
674 double (*d
)[2] = (double (*)[2]) SCM_VELTS (dst
);
675 double (*s
)[2] = (double (*)[2]) SCM_VELTS (src
);
684 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
686 d
[i_d
][0] = ((long *) s
)[i_s
];
693 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
695 d
[i_d
][0] = ((float *) s
)[i_s
];
702 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
704 d
[i_d
][0] = ((double *) s
)[i_s
];
711 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
713 d
[i_d
][0] = s
[i_s
][0];
714 d
[i_d
][1] = s
[i_s
][1];
721 #endif /* SCM_FLOATS */
726 SCM_PROC(s_serial_array_copy_x
, "serial-array-copy!", 2, 0, 0, scm_array_copy_x
);
727 SCM_PROC(s_array_copy_x
, "array-copy!", 2, 0, 0, scm_array_copy_x
);
730 scm_array_copy_x (src
, dst
)
734 scm_ramapc (racp
, SCM_UNDEFINED
, src
, scm_cons (dst
, SCM_EOL
), s_array_copy_x
);
735 return SCM_UNSPECIFIED
;
738 /* Functions callable by ARRAY-MAP! */
742 scm_ra_eqp (ra0
, ras
)
746 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
747 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
748 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
749 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
750 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
751 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
752 ra0
= SCM_ARRAY_V (ra0
);
753 ra1
= SCM_ARRAY_V (ra1
);
754 ra2
= SCM_ARRAY_V (ra2
);
755 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
759 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
760 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
764 (scm_eq_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)))
770 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
773 if (SCM_VELTS (ra1
)[i1
] != SCM_VELTS (ra2
)[i2
])
779 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
782 if (((float *) SCM_VELTS (ra1
))[i1
] != ((float *) SCM_VELTS (ra2
))[i2
])
785 #endif /*SCM_SINGLES*/
787 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
790 if (((double *) SCM_VELTS (ra1
))[i1
] != ((double *) SCM_VELTS (ra2
))[i2
])
794 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
797 if (((double *) SCM_VELTS (ra1
))[2 * i1
] != ((double *) SCM_VELTS (ra2
))[2 * i2
] ||
798 ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1] != ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1])
801 #endif /*SCM_FLOATS*/
806 /* opt 0 means <, nonzero means >= */
808 static int ra_compare
SCM_P ((SCM ra0
, SCM ra1
, SCM ra2
, int opt
));
811 ra_compare (ra0
, ra1
, ra2
, opt
)
817 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
818 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
819 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
820 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
821 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
822 ra0
= SCM_ARRAY_V (ra0
);
823 ra1
= SCM_ARRAY_V (ra1
);
824 ra2
= SCM_ARRAY_V (ra2
);
825 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
829 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
830 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
834 SCM_NFALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))) :
835 SCM_FALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
841 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
846 SCM_VELTS (ra1
)[i1
] < SCM_VELTS (ra2
)[i2
] :
847 SCM_VELTS (ra1
)[i1
] >= SCM_VELTS (ra2
)[i2
])
854 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
858 ((float *) SCM_VELTS (ra1
))[i1
] < ((float *) SCM_VELTS (ra2
))[i2
] :
859 ((float *) SCM_VELTS (ra1
))[i1
] >= ((float *) SCM_VELTS (ra2
))[i2
])
862 #endif /*SCM_SINGLES*/
864 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
868 ((double *) SCM_VELTS (ra1
))[i1
] < ((double *) SCM_VELTS (ra2
))[i2
] :
869 ((double *) SCM_VELTS (ra1
))[i1
] >= ((double *) SCM_VELTS (ra2
))[i2
])
872 #endif /*SCM_FLOATS*/
880 scm_ra_lessp (ra0
, ras
)
884 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 0);
889 scm_ra_leqp (ra0
, ras
)
893 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 1);
898 scm_ra_grp (ra0
, ras
)
902 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 0);
907 scm_ra_greqp (ra0
, ras
)
911 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 1);
917 scm_ra_sum (ra0
, ras
)
921 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
922 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
923 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
924 ra0
= SCM_ARRAY_V (ra0
);
928 SCM ra1
= SCM_CAR (ras
);
929 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
930 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
931 ra1
= SCM_ARRAY_V (ra1
);
932 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
936 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
937 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
938 scm_array_set_x (ra0
, scm_sum (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
945 long *v0
= SCM_VELTS (ra0
);
946 long *v1
= SCM_VELTS (ra1
);
948 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
956 float *v0
= (float *) SCM_VELTS (ra0
);
957 float *v1
= (float *) SCM_VELTS (ra1
);
959 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
963 #endif /* SCM_SINGLES */
966 double *v0
= (double *) SCM_VELTS (ra0
);
967 double *v1
= (double *) SCM_VELTS (ra1
);
969 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
975 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
976 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
978 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
980 v0
[i0
][0] += v1
[i1
][0];
981 v0
[i0
][1] += v1
[i1
][1];
986 #endif /* SCM_FLOATS */
995 scm_ra_difference (ra0
, ras
)
999 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1000 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1001 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1002 ra0
= SCM_ARRAY_V (ra0
);
1011 SCM e0
= SCM_UNDEFINED
;
1012 for (; n
-- > 0; i0
+= inc0
)
1013 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1020 float *v0
= (float *) SCM_VELTS (ra0
);
1021 for (; n
-- > 0; i0
+= inc0
)
1025 #endif /* SCM_SINGLES */
1028 double *v0
= (double *) SCM_VELTS (ra0
);
1029 for (; n
-- > 0; i0
+= inc0
)
1035 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1036 for (; n
-- > 0; i0
+= inc0
)
1038 v0
[i0
][0] = -v0
[i0
][0];
1039 v0
[i0
][1] = -v0
[i0
][1];
1043 #endif /* SCM_FLOATS */
1048 SCM ra1
= SCM_CAR (ras
);
1049 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1050 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1051 ra1
= SCM_ARRAY_V (ra1
);
1052 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1056 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1057 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1058 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1065 float *v0
= (float *) SCM_VELTS (ra0
);
1066 float *v1
= (float *) SCM_VELTS (ra1
);
1068 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1072 #endif /* SCM_SINGLES */
1075 double *v0
= (double *) SCM_VELTS (ra0
);
1076 double *v1
= (double *) SCM_VELTS (ra1
);
1078 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1084 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1085 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1087 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1089 v0
[i0
][0] -= v1
[i1
][0];
1090 v0
[i0
][1] -= v1
[i1
][1];
1095 #endif /* SCM_FLOATS */
1104 scm_ra_product (ra0
, ras
)
1108 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1109 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1110 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1111 ra0
= SCM_ARRAY_V (ra0
);
1115 SCM ra1
= SCM_CAR (ras
);
1116 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1117 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1118 ra1
= SCM_ARRAY_V (ra1
);
1119 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1123 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1124 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1125 scm_array_set_x (ra0
, scm_product (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1132 long *v0
= SCM_VELTS (ra0
);
1133 long *v1
= SCM_VELTS (ra1
);
1135 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1143 float *v0
= (float *) SCM_VELTS (ra0
);
1144 float *v1
= (float *) SCM_VELTS (ra1
);
1146 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1150 #endif /* SCM_SINGLES */
1153 double *v0
= (double *) SCM_VELTS (ra0
);
1154 double *v1
= (double *) SCM_VELTS (ra1
);
1156 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1162 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1164 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1166 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1168 r
= v0
[i0
][0] * v1
[i1
][0] - v0
[i0
][1] * v1
[i1
][1];
1169 v0
[i0
][1] = v0
[i0
][0] * v1
[i1
][1] + v0
[i0
][1] * v1
[i1
][0];
1175 #endif /* SCM_FLOATS */
1183 scm_ra_divide (ra0
, ras
)
1187 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1188 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1189 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1190 ra0
= SCM_ARRAY_V (ra0
);
1199 SCM e0
= SCM_UNDEFINED
;
1200 for (; n
-- > 0; i0
+= inc0
)
1201 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1208 float *v0
= (float *) SCM_VELTS (ra0
);
1209 for (; n
-- > 0; i0
+= inc0
)
1210 v0
[i0
] = 1.0 / v0
[i0
];
1213 #endif /* SCM_SINGLES */
1216 double *v0
= (double *) SCM_VELTS (ra0
);
1217 for (; n
-- > 0; i0
+= inc0
)
1218 v0
[i0
] = 1.0 / v0
[i0
];
1224 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1225 for (; n
-- > 0; i0
+= inc0
)
1227 d
= v0
[i0
][0] * v0
[i0
][0] + v0
[i0
][1] * v0
[i0
][1];
1233 #endif /* SCM_FLOATS */
1238 SCM ra1
= SCM_CAR (ras
);
1239 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1240 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1241 ra1
= SCM_ARRAY_V (ra1
);
1242 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1246 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1247 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1248 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1255 float *v0
= (float *) SCM_VELTS (ra0
);
1256 float *v1
= (float *) SCM_VELTS (ra1
);
1258 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1262 #endif /* SCM_SINGLES */
1265 double *v0
= (double *) SCM_VELTS (ra0
);
1266 double *v1
= (double *) SCM_VELTS (ra1
);
1268 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1274 register double d
, r
;
1275 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1276 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1278 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1280 d
= v1
[i1
][0] * v1
[i1
][0] + v1
[i1
][1] * v1
[i1
][1];
1281 r
= (v0
[i0
][0] * v1
[i1
][0] + v0
[i0
][1] * v1
[i1
][1]) / d
;
1282 v0
[i0
][1] = (v0
[i0
][1] * v1
[i1
][0] - v0
[i0
][0] * v1
[i1
][1]) / d
;
1288 #endif /* SCM_FLOATS */
1296 scm_array_identity (dst
, src
)
1300 return racp (SCM_CAR (src
), scm_cons (dst
, SCM_EOL
));
1305 static int ramap
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1308 ramap (ra0
, proc
, ras
)
1313 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1314 long inc
= SCM_ARRAY_DIMS (ra0
)->inc
;
1315 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1316 long base
= SCM_ARRAY_BASE (ra0
) - i
* inc
;
1317 ra0
= SCM_ARRAY_V (ra0
);
1321 scm_array_set_x (ra0
, scm_apply (proc
, SCM_EOL
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1324 SCM ra1
= SCM_CAR (ras
);
1325 SCM args
, *ve
= &ras
;
1326 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1327 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1328 ra1
= SCM_ARRAY_V (ra1
);
1329 ras
= SCM_CDR (ras
);
1335 ras
= scm_vector (ras
);
1336 ve
= SCM_VELTS (ras
);
1338 for (; i
<= n
; i
++, i1
+= inc1
)
1341 for (k
= SCM_LENGTH (ras
); k
--;)
1342 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1343 args
= scm_cons (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1344 scm_array_set_x (ra0
, scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1351 static int ramap_cxr
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1354 ramap_cxr (ra0
, proc
, ras
)
1359 SCM ra1
= SCM_CAR (ras
);
1360 SCM e1
= SCM_UNDEFINED
;
1361 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1362 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1363 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra1
)->lbnd
+ 1;
1364 ra0
= SCM_ARRAY_V (ra0
);
1365 ra1
= SCM_ARRAY_V (ra1
);
1371 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1372 scm_array_set_x (ra0
, scm_apply (proc
, RVREF (ra1
, i1
, e1
), scm_listofnull
), SCM_MAKINUM (i0
));
1378 float *dst
= (float *) SCM_VELTS (ra0
);
1385 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1386 dst
[i0
] = SCM_DSUBRF (proc
) ((double) ((float *) SCM_VELTS (ra1
))[i1
]);
1390 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1391 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1396 #endif /* SCM_SINGLES */
1399 double *dst
= (double *) SCM_VELTS (ra0
);
1406 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1407 dst
[i0
] = SCM_DSUBRF (proc
) (((double *) SCM_VELTS (ra1
))[i1
]);
1411 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1412 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1417 #endif /* SCM_FLOATS */
1424 static int ramap_rp
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1427 ramap_rp (ra0
, proc
, ras
)
1432 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
1433 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
1434 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1435 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
1436 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1437 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1438 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
1439 ra0
= SCM_ARRAY_V (ra0
);
1440 ra1
= SCM_ARRAY_V (ra1
);
1441 ra2
= SCM_ARRAY_V (ra2
);
1442 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
1445 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1449 (SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)))
1454 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1459 (SCM_SUBRF (proc
) (SCM_MAKINUM (SCM_VELTS (ra1
)[i1
]),
1460 SCM_MAKINUM (SCM_VELTS (ra2
)[i2
])))
1468 SCM a1
= scm_makflo (1.0), a2
= scm_makflo (1.0);
1469 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1473 SCM_FLO (a1
) = ((float *) SCM_VELTS (ra1
))[i1
];
1474 SCM_FLO (a2
) = ((float *) SCM_VELTS (ra2
))[i2
];
1476 (SCM_SUBRF (proc
) (a1
, a2
))
1481 #endif /*SCM_SINGLES*/
1484 SCM a1
= scm_makdbl (1.0 / 3.0, 0.0), a2
= scm_makdbl (1.0 / 3.0, 0.0);
1485 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1489 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[i1
];
1490 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[i2
];
1492 (SCM_SUBRF (proc
) (a1
, a2
))
1499 SCM a1
= scm_makdbl (1.0, 1.0), a2
= scm_makdbl (1.0, 1.0);
1500 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1504 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
];
1505 SCM_IMAG (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1];
1506 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
];
1507 SCM_IMAG (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1];
1509 (SCM_SUBRF (proc
) (a1
, a2
))
1514 #endif /*SCM_FLOATS*/
1521 static int ramap_1
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1524 ramap_1 (ra0
, proc
, ras
)
1529 SCM ra1
= SCM_CAR (ras
);
1530 SCM e1
= SCM_UNDEFINED
;
1531 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1532 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1533 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1534 ra0
= SCM_ARRAY_V (ra0
);
1535 ra1
= SCM_ARRAY_V (ra1
);
1536 if (scm_tc7_vector
== SCM_TYP7 (ra0
))
1537 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1538 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
)), SCM_MAKINUM (i0
));
1540 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1541 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1547 static int ramap_2o
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1550 ramap_2o (ra0
, proc
, ras
)
1555 SCM ra1
= SCM_CAR (ras
);
1556 SCM e1
= SCM_UNDEFINED
;
1557 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1558 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1559 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1560 ra0
= SCM_ARRAY_V (ra0
);
1561 ra1
= SCM_ARRAY_V (ra1
);
1562 ras
= SCM_CDR (ras
);
1566 if (scm_tc7_vector
== SCM_TYP7 (ra0
))
1567 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1568 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), SCM_UNDEFINED
),
1571 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1572 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), SCM_UNDEFINED
),
1577 SCM ra2
= SCM_CAR (ras
);
1578 SCM e2
= SCM_UNDEFINED
;
1579 scm_sizet i2
= SCM_ARRAY_BASE (ra2
);
1580 long inc2
= SCM_ARRAY_DIMS (ra2
)->inc
;
1581 ra2
= SCM_ARRAY_V (ra2
);
1582 if (scm_tc7_vector
== SCM_TYP7 (ra0
))
1583 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1584 scm_array_set_x (ra0
,
1585 SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), scm_cvref (ra2
, i2
, SCM_UNDEFINED
)),
1588 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1589 scm_array_set_x (ra0
,
1590 SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)),
1598 static int ramap_a
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1601 ramap_a (ra0
, proc
, ras
)
1606 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1607 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1608 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1609 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1610 ra0
= SCM_ARRAY_V (ra0
);
1613 for (; n
-- > 0; i0
+= inc0
)
1614 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1617 SCM ra1
= SCM_CAR (ras
);
1618 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1619 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1620 ra1
= SCM_ARRAY_V (ra1
);
1621 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1622 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1628 SCM_PROC(s_serial_array_map
, "serial-array-map", 2, 0, 1, scm_array_map
);
1629 SCM_PROC(s_array_map
, "array-map", 2, 0, 1, scm_array_map
);
1632 scm_array_map (ra0
, proc
, lra
)
1637 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
, s_array_map
);
1638 switch (SCM_TYP7 (proc
))
1642 scm_ramapc (ramap
, proc
, ra0
, lra
, s_array_map
);
1643 return SCM_UNSPECIFIED
;
1644 case scm_tc7_subr_1
:
1645 scm_ramapc (ramap_1
, proc
, ra0
, lra
, s_array_map
);
1646 return SCM_UNSPECIFIED
;
1647 case scm_tc7_subr_2
:
1648 case scm_tc7_subr_2o
:
1649 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map
);
1650 return SCM_UNSPECIFIED
;
1652 if (!SCM_SUBRF (proc
))
1654 scm_ramapc (ramap_cxr
, proc
, ra0
, lra
, s_array_map
);
1655 return SCM_UNSPECIFIED
;
1656 case scm_tc7_rpsubr
:
1659 if (SCM_FALSEP (scm_array_p (ra0
, SCM_BOOL_T
)))
1661 scm_array_fill_x (ra0
, SCM_BOOL_T
);
1662 for (p
= ra_rpsubrs
; p
->name
; p
++)
1663 if (proc
== p
->sproc
)
1665 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1667 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map
);
1668 lra
= SCM_CDR (lra
);
1670 return SCM_UNSPECIFIED
;
1672 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1674 scm_ramapc (ramap_rp
, proc
, ra0
, lra
, s_array_map
);
1675 lra
= SCM_CDR (lra
);
1677 return SCM_UNSPECIFIED
;
1683 SCM prot
, fill
= SCM_SUBRF (proc
) (SCM_UNDEFINED
, SCM_UNDEFINED
);
1687 prot
= scm_array_prototype (ra0
);
1688 if (SCM_NIMP (prot
) && SCM_INEXP (prot
))
1689 fill
= scm_makdbl ((double) SCM_INUM (fill
), 0.0);
1692 scm_array_fill_x (ra0
, fill
);
1696 SCM tail
, ra1
= SCM_CAR (lra
);
1697 SCM v0
= (SCM_NIMP (ra0
) && SCM_ARRAYP (ra0
) ? SCM_ARRAY_V (ra0
) : ra0
);
1699 /* Check to see if order might matter.
1700 This might be an argument for a separate
1701 SERIAL-ARRAY-MAP! */
1702 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1703 if (ra0
!= ra1
|| (SCM_ARRAYP(ra0
) && !SCM_ARRAY_CONTP(ra0
)))
1705 for (tail
= SCM_CDR (lra
); SCM_NNULLP (tail
); tail
= SCM_CDR (tail
))
1707 ra1
= SCM_CAR (tail
);
1708 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1711 for (p
= ra_asubrs
; p
->name
; p
++)
1712 if (proc
== p
->sproc
)
1714 if (ra0
!= SCM_CAR (lra
))
1715 scm_ramapc (scm_array_identity
, SCM_UNDEFINED
, ra0
, scm_cons (SCM_CAR (lra
), SCM_EOL
), s_array_map
);
1716 lra
= SCM_CDR (lra
);
1719 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map
);
1720 if (SCM_IMP (lra
) || SCM_IMP (SCM_CDR (lra
)))
1721 return SCM_UNSPECIFIED
;
1722 lra
= SCM_CDR (lra
);
1725 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map
);
1726 lra
= SCM_CDR (lra
);
1729 for (lra
= SCM_CDR (lra
); SCM_NIMP (lra
); lra
= SCM_CDR (lra
))
1730 scm_ramapc (ramap_a
, proc
, ra0
, lra
, s_array_map
);
1732 return SCM_UNSPECIFIED
;
1737 static int rafe
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1740 rafe (ra0
, proc
, ras
)
1745 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1746 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1747 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1748 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1749 ra0
= SCM_ARRAY_V (ra0
);
1752 for (; i
<= n
; i
++, i0
+= inc0
)
1753 scm_apply (proc
, scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_listofnull
);
1756 SCM ra1
= SCM_CAR (ras
);
1757 SCM args
, *ve
= &ras
;
1758 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1759 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1760 ra1
= SCM_ARRAY_V (ra1
);
1761 ras
= SCM_CDR (ras
);
1767 ras
= scm_vector (ras
);
1768 ve
= SCM_VELTS (ras
);
1770 for (; i
<= n
; i
++, i0
+= inc0
, i1
+= inc1
)
1773 for (k
= SCM_LENGTH (ras
); k
--;)
1774 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1775 args
= scm_cons2 (scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1776 scm_apply (proc
, args
, SCM_EOL
);
1783 SCM_PROC(s_array_for_each
, "array-for-each", 2, 0, 1, scm_array_for_each
);
1786 scm_array_for_each (proc
, ra0
, lra
)
1791 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG1
, s_array_for_each
);
1792 scm_ramapc (rafe
, proc
, ra0
, lra
, s_array_for_each
);
1793 return SCM_UNSPECIFIED
;
1796 SCM_PROC(s_array_index_map_x
, "array-index-map!", 2, 0, 0, scm_array_index_map_x
);
1799 scm_array_index_map_x (ra
, proc
)
1804 SCM_ASSERT (SCM_NIMP (ra
), ra
, SCM_ARG1
, s_array_index_map_x
);
1805 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
, s_array_index_map_x
);
1810 badarg
:scm_wta (ra
, (char *) SCM_ARG1
, s_array_index_map_x
);
1811 case scm_tc7_vector
:
1813 SCM
*ve
= SCM_VELTS (ra
);
1814 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1815 ve
[i
] = scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
);
1816 return SCM_UNSPECIFIED
;
1818 case scm_tc7_string
:
1825 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1826 scm_array_set_x (ra
, scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
), SCM_MAKINUM (i
));
1827 return SCM_UNSPECIFIED
;
1829 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
1832 SCM inds
= scm_make_uve (SCM_ARRAY_NDIM (ra
), SCM_MAKINUM (-1L));
1833 long *vinds
= SCM_VELTS (inds
);
1834 int j
, k
, kmax
= SCM_ARRAY_NDIM (ra
) - 1;
1835 for (k
= 0; k
<= kmax
; k
++)
1836 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1842 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1843 i
= cind (ra
, inds
);
1844 for (; vinds
[k
] <= SCM_ARRAY_DIMS (ra
)[k
].ubnd
; vinds
[k
]++)
1846 for (j
= kmax
+ 1, args
= SCM_EOL
; j
--;)
1847 args
= scm_cons (SCM_MAKINUM (vinds
[j
]), args
);
1848 scm_array_set_x (SCM_ARRAY_V (ra
), scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
));
1849 i
+= SCM_ARRAY_DIMS (ra
)[k
].inc
;
1854 if (vinds
[k
] < SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
1860 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
- 1;
1864 return SCM_UNSPECIFIED
;
1870 static int raeql_1
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
1873 raeql_1 (ra0
, as_equal
, ra1
)
1878 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1879 scm_sizet i0
= 0, i1
= 0;
1880 long inc0
= 1, inc1
= 1;
1881 scm_sizet n
= SCM_LENGTH (ra0
);
1882 ra1
= SCM_CAR (ra1
);
1886 n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1887 i0
= SCM_ARRAY_BASE (ra0
);
1888 inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1889 ra0
= SCM_ARRAY_V (ra0
);
1894 i1
= SCM_ARRAY_BASE (ra1
);
1895 inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1896 ra1
= SCM_ARRAY_V (ra1
);
1901 case scm_tc7_vector
:
1903 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1909 (scm_array_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)))
1913 (scm_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)))
1917 case scm_tc7_string
:
1919 char *v0
= SCM_CHARS (ra0
) + i0
;
1920 char *v1
= SCM_CHARS (ra1
) + i1
;
1921 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1927 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1928 if (BVE_REF (ra0
, i0
) != BVE_REF (ra1
, i1
))
1934 long *v0
= (long *) SCM_VELTS (ra0
) + i0
;
1935 long *v1
= (long *) SCM_VELTS (ra1
) + i1
;
1936 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1945 float *v0
= (float *) SCM_VELTS (ra0
) + i0
;
1946 float *v1
= (float *) SCM_VELTS (ra1
) + i1
;
1947 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1952 #endif /* SCM_SINGLES */
1955 double *v0
= (double *) SCM_VELTS (ra0
) + i0
;
1956 double *v1
= (double *) SCM_VELTS (ra1
) + i1
;
1957 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1964 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
) + i0
;
1965 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
) + i1
;
1966 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1968 if ((*v0
)[0] != (*v1
)[0])
1970 if ((*v0
)[1] != (*v1
)[1])
1975 #endif /* SCM_FLOATS */
1981 static int raeql
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
1984 raeql (ra0
, as_equal
, ra1
)
1989 SCM v0
= ra0
, v1
= ra1
;
1990 scm_array_dim dim0
, dim1
;
1991 scm_array_dim
*s0
= &dim0
, *s1
= &dim1
;
1992 scm_sizet bas0
= 0, bas1
= 0;
1993 int k
, unroll
= 1, vlen
= 1, ndim
= 1;
1997 ndim
= SCM_ARRAY_NDIM (ra0
);
1998 s0
= SCM_ARRAY_DIMS (ra0
);
1999 bas0
= SCM_ARRAY_BASE (ra0
);
2000 v0
= SCM_ARRAY_V (ra0
);
2006 s0
->ubnd
= SCM_LENGTH (v0
) - 1;
2012 if (ndim
!= SCM_ARRAY_NDIM (ra1
))
2014 s1
= SCM_ARRAY_DIMS (ra1
);
2015 bas1
= SCM_ARRAY_BASE (ra1
);
2016 v1
= SCM_ARRAY_V (ra1
);
2024 s1
->ubnd
= SCM_LENGTH (v1
) - 1;
2027 if (SCM_TYP7 (v0
) != SCM_TYP7 (v1
))
2029 for (k
= ndim
; k
--;)
2031 if (s0
[k
].lbnd
!= s1
[k
].lbnd
|| s0
[k
].ubnd
!= s1
[k
].ubnd
)
2035 unroll
= (s0
[k
].inc
== s1
[k
].inc
);
2036 vlen
*= s0
[k
].ubnd
- s1
[k
].lbnd
+ 1;
2039 if (unroll
&& bas0
== bas1
&& v0
== v1
)
2041 return scm_ramapc (raeql_1
, as_equal
, ra0
, scm_cons (ra1
, SCM_EOL
), "");
2046 scm_raequal (ra0
, ra1
)
2050 return (raeql (ra0
, SCM_BOOL_T
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2053 static char s_array_equal_p
[] = "array-equal?";
2057 scm_array_equal_p (ra0
, ra1
)
2061 if (SCM_IMP (ra0
) || SCM_IMP (ra1
))
2062 callequal
:return scm_equal_p (ra0
, ra1
);
2069 case scm_tc7_string
:
2075 case scm_tc7_vector
:
2078 if (!SCM_ARRAYP (ra0
))
2087 case scm_tc7_string
:
2093 case scm_tc7_vector
:
2096 if (!SCM_ARRAYP (ra1
))
2099 return (raeql (ra0
, SCM_BOOL_F
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2105 init_raprocs (subra
)
2108 for (; subra
->name
; subra
++)
2109 subra
->sproc
= SCM_CDR (scm_intern (subra
->name
, strlen (subra
->name
)));
2116 init_raprocs (ra_rpsubrs
);
2117 init_raprocs (ra_asubrs
);
2118 scm_make_subr (s_array_equal_p
, scm_tc7_rpsubr
, scm_array_equal_p
);
2119 scm_smobs
[0x0ff & (scm_tc16_array
>> 8)].equalp
= scm_raequal
;
2121 scm_add_feature (s_array_for_each
);