1 /* Copyright (C) 1996, 1998 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, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
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.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
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.
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.
40 * 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
))
177 s0
->ubnd
= (long) SCM_LENGTH (ra0
) - 1;
180 if (!SCM_ARRAYP (ra0
))
182 ndim
= SCM_ARRAY_NDIM (ra0
);
183 s0
= SCM_ARRAY_DIMS (ra0
);
184 bas0
= SCM_ARRAY_BASE (ra0
);
223 if ((0 == s0
->lbnd
) && (s0
->ubnd
== SCM_LENGTH (ra1
) - 1))
227 if (s0
->lbnd
< 0 || s0
->ubnd
>= SCM_LENGTH (ra1
))
232 if (!SCM_ARRAYP (ra1
) || ndim
!= SCM_ARRAY_NDIM (ra1
))
234 s1
= SCM_ARRAY_DIMS (ra1
);
235 if (bas0
!= SCM_ARRAY_BASE (ra1
))
237 for (i
= 0; i
< ndim
; i
++)
242 if (s0
[i
].inc
!= s1
[i
].inc
)
245 if (s0
[i
].lbnd
== s1
[i
].lbnd
&& s0
[i
].ubnd
== s1
[i
].ubnd
)
249 if (s0
[i
].lbnd
< s1
[i
].lbnd
|| s0
[i
].ubnd
> s1
[i
].ubnd
)
250 return (s0
[i
].lbnd
<= s0
[i
].ubnd
? 0 : 1);
259 static char s_ra_mismatch
[] = "array shape mismatch";
262 scm_ramapc (cproc
, data
, ra0
, lra
, what
)
274 switch (scm_ra_matchp (ra0
, lra
))
278 scm_wta (ra0
, s_ra_mismatch
, what
);
281 case 4: /* Try unrolling arrays */
282 kmax
= (SCM_ARRAYP (ra0
) ? SCM_ARRAY_NDIM (ra0
) - 1 : 0);
285 vra0
= scm_array_contents (ra0
, SCM_UNDEFINED
);
288 if (!SCM_ARRAYP (vra0
))
290 vra1
= scm_make_ra (1);
291 SCM_ARRAY_BASE (vra1
) = 0;
292 SCM_ARRAY_DIMS (vra1
)->lbnd
= 0;
293 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_LENGTH (vra0
) - 1;
294 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
295 SCM_ARRAY_V (vra1
) = vra0
;
300 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
303 vra1
= scm_make_ra (1);
304 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
305 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
306 if (!SCM_ARRAYP (ra1
))
308 SCM_ARRAY_BASE (vra1
) = 0;
309 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
310 SCM_ARRAY_V (vra1
) = ra1
;
312 else if (!SCM_ARRAY_CONTP (ra1
))
316 SCM_ARRAY_BASE (vra1
) = SCM_ARRAY_BASE (ra1
);
317 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
318 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
320 *plvra
= scm_cons (vra1
, SCM_EOL
);
321 plvra
= SCM_CDRLOC (*plvra
);
323 return (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
));
325 gencase
: /* Have to loop over all dimensions. */
326 vra0
= scm_make_ra (1);
330 kmax
= SCM_ARRAY_NDIM (ra0
) - 1;
333 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
334 SCM_ARRAY_DIMS (vra0
)->ubnd
= 0;
335 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
339 SCM_ARRAY_DIMS (vra0
)->lbnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].lbnd
;
340 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].ubnd
;
341 SCM_ARRAY_DIMS (vra0
)->inc
= SCM_ARRAY_DIMS (ra0
)[kmax
].inc
;
343 SCM_ARRAY_BASE (vra0
) = SCM_ARRAY_BASE (ra0
);
344 SCM_ARRAY_V (vra0
) = SCM_ARRAY_V (ra0
);
349 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
350 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_LENGTH (ra0
) - 1;
351 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
352 SCM_ARRAY_BASE (vra0
) = 0;
353 SCM_ARRAY_V (vra0
) = ra0
;
358 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
361 vra1
= scm_make_ra (1);
362 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
363 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
368 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
369 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
373 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
374 SCM_ARRAY_V (vra1
) = ra1
;
376 *plvra
= scm_cons (vra1
, SCM_EOL
);
377 plvra
= SCM_CDRLOC (*plvra
);
379 inds
= scm_make_uve (SCM_ARRAY_NDIM (ra0
), SCM_MAKINUM (-1L));
380 vinds
= (long *) SCM_VELTS (inds
);
381 for (k
= 0; k
<= kmax
; k
++)
382 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
;
389 SCM_ARRAY_BASE (vra0
) = cind (ra0
, inds
);
390 for (z
= lvra
; SCM_NIMP (z
); z
= SCM_CDR (z
), y
= SCM_CDR (y
))
391 SCM_ARRAY_BASE (SCM_CAR (z
)) = cind (SCM_CAR (y
), inds
);
392 if (0 == (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
)))
397 if (vinds
[k
] < SCM_ARRAY_DIMS (ra0
)[k
].ubnd
)
403 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
- 1;
412 SCM_PROC(s_array_fill_x
, "array-fill!", 2, 0, 0, scm_array_fill_x
);
415 scm_array_fill_x (ra
, fill
)
419 scm_ramapc (scm_array_fill_int
, fill
, ra
, SCM_EOL
, s_array_fill_x
);
420 return SCM_UNSPECIFIED
;
425 scm_array_fill_int (ra
, fill
, ignore
)
430 scm_sizet i
, n
= SCM_ARRAY_DIMS (ra
)->ubnd
- SCM_ARRAY_DIMS (ra
)->lbnd
+ 1;
431 long inc
= SCM_ARRAY_DIMS (ra
)->inc
;
432 scm_sizet base
= SCM_ARRAY_BASE (ra
);
433 ra
= SCM_ARRAY_V (ra
);
438 for (i
= base
; n
--; i
+= inc
)
439 scm_array_set_x (ra
, fill
, SCM_MAKINUM (i
));
443 for (i
= base
; n
--; i
+= inc
)
444 SCM_VELTS (ra
)[i
] = fill
;
447 SCM_ASRTGO (SCM_ICHRP (fill
), badarg2
);
448 for (i
= base
; n
--; i
+= inc
)
449 SCM_CHARS (ra
)[i
] = SCM_ICHR (fill
);
452 if (SCM_ICHRP (fill
))
453 fill
= SCM_MAKINUM ((char) SCM_ICHR (fill
));
454 SCM_ASRTGO (SCM_INUMP (fill
)
455 && -128 <= SCM_INUM (fill
) && SCM_INUM (fill
) < 128,
457 for (i
= base
; n
--; i
+= inc
)
458 SCM_CHARS (ra
)[i
] = SCM_INUM (fill
);
462 long *ve
= (long *) SCM_VELTS (ra
);
463 if (1 == inc
&& (n
>= SCM_LONG_BIT
|| n
== SCM_LENGTH (ra
)))
465 i
= base
/ SCM_LONG_BIT
;
466 if (SCM_BOOL_F
== fill
)
468 if (base
% SCM_LONG_BIT
) /* leading partial word */
469 ve
[i
++] &= ~(~0L << (base
% SCM_LONG_BIT
));
470 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
472 if ((base
+ n
) % SCM_LONG_BIT
) /* trailing partial word */
473 ve
[i
] &= (~0L << ((base
+ n
) % SCM_LONG_BIT
));
475 else if (SCM_BOOL_T
== fill
)
477 if (base
% SCM_LONG_BIT
)
478 ve
[i
++] |= ~0L << (base
% SCM_LONG_BIT
);
479 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
481 if ((base
+ n
) % SCM_LONG_BIT
)
482 ve
[i
] |= ~(~0L << ((base
+ n
) % SCM_LONG_BIT
));
485 badarg2
:scm_wta (fill
, (char *) SCM_ARG2
, s_array_fill_x
);
489 if (SCM_BOOL_F
== fill
)
490 for (i
= base
; n
--; i
+= inc
)
491 ve
[i
/ SCM_LONG_BIT
] &= ~(1L << (i
% SCM_LONG_BIT
));
492 else if (SCM_BOOL_T
== fill
)
493 for (i
= base
; n
--; i
+= inc
)
494 ve
[i
/ SCM_LONG_BIT
] |= (1L << (i
% SCM_LONG_BIT
));
501 SCM_ASRTGO (0 <= SCM_INUM (fill
), badarg2
);
503 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
505 long f
= SCM_INUM (fill
), *ve
= (long *) SCM_VELTS (ra
);
506 for (i
= base
; n
--; i
+= inc
)
511 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
513 short f
= SCM_INUM (fill
), *ve
= (short *) SCM_VELTS (ra
);
514 for (i
= base
; n
--; i
+= inc
)
520 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
522 long long f
= SCM_INUM (fill
), *ve
= (long long *) SCM_VELTS (ra
);
523 for (i
= base
; n
--; i
+= inc
)
532 float f
, *ve
= (float *) SCM_VELTS (ra
);
533 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
534 f
= SCM_REALPART (fill
);
535 for (i
= base
; n
--; i
+= inc
)
539 #endif /* SCM_SINGLES */
542 double f
, *ve
= (double *) SCM_VELTS (ra
);
543 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
544 f
= SCM_REALPART (fill
);
545 for (i
= base
; n
--; i
+= inc
)
552 double (*ve
)[2] = (double (*)[2]) SCM_VELTS (ra
);
553 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_INEXP (fill
), badarg2
);
554 fr
= SCM_REALPART (fill
);
555 fi
= (SCM_CPLXP (fill
) ? SCM_IMAG (fill
) : 0.0);
556 for (i
= base
; n
--; i
+= inc
)
563 #endif /* SCM_FLOATS */
571 static int racp
SCM_P ((SCM dst
, SCM src
));
578 long n
= (SCM_ARRAY_DIMS (src
)->ubnd
- SCM_ARRAY_DIMS (src
)->lbnd
+ 1);
579 long inc_d
, inc_s
= SCM_ARRAY_DIMS (src
)->inc
;
580 scm_sizet i_d
, i_s
= SCM_ARRAY_BASE (src
);
582 inc_d
= SCM_ARRAY_DIMS (dst
)->inc
;
583 i_d
= SCM_ARRAY_BASE (dst
);
584 src
= SCM_ARRAY_V (src
);
585 dst
= SCM_ARRAY_V (dst
);
594 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
595 scm_array_set_x (dst
, scm_cvref (src
, i_s
, SCM_UNDEFINED
), SCM_MAKINUM (i_d
));
599 if (scm_tc7_string
!= SCM_TYP7 (dst
))
601 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
602 SCM_CHARS (dst
)[i_d
] = SCM_CHARS (src
)[i_s
];
605 if (scm_tc7_bvect
!= SCM_TYP7 (dst
))
607 if (1 == inc_d
&& 1 == inc_s
&& i_s
% SCM_LONG_BIT
== i_d
% SCM_LONG_BIT
&& n
>= SCM_LONG_BIT
)
609 long *sv
= (long *) SCM_VELTS (src
);
610 long *dv
= (long *) SCM_VELTS (dst
);
611 sv
+= i_s
/ SCM_LONG_BIT
;
612 dv
+= i_d
/ SCM_LONG_BIT
;
613 if (i_s
% SCM_LONG_BIT
)
614 { /* leading partial word */
615 *dv
= (*dv
& ~(~0L << (i_s
% SCM_LONG_BIT
))) | (*sv
& (~0L << (i_s
% SCM_LONG_BIT
)));
618 n
-= SCM_LONG_BIT
- (i_s
% SCM_LONG_BIT
);
621 for (; n
>= SCM_LONG_BIT
; n
-= SCM_LONG_BIT
, sv
++, dv
++)
623 if (n
) /* trailing partial word */
624 *dv
= (*dv
& (~0L << n
)) | (*sv
& ~(~0L << n
));
628 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
629 if (SCM_VELTS (src
)[i_s
/ SCM_LONG_BIT
] & (1L << (i_s
% SCM_LONG_BIT
)))
630 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] |= (1L << (i_d
% SCM_LONG_BIT
));
632 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] &= ~(1L << (i_d
% SCM_LONG_BIT
));
636 if (scm_tc7_uvect
!= SCM_TYP7 (src
))
640 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
642 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
647 if (scm_tc7_uvect
!= SCM_TYP7 (src
) && scm_tc7_ivect
!= SCM_TYP7 (src
))
651 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
653 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
661 float *d
= (float *) SCM_VELTS (dst
);
662 float *s
= (float *) SCM_VELTS (src
);
671 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
672 d
[i_d
] = ((long *) s
)[i_s
];)
676 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
681 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
682 d
[i_d
] = ((double *) s
)[i_s
];)
687 #endif /* SCM_SINGLES */
690 double *d
= (double *) SCM_VELTS (dst
);
691 double *s
= (double *) SCM_VELTS (src
);
700 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
701 d
[i_d
] = ((long *) s
)[i_s
];)
705 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
706 d
[i_d
] = ((float *) s
)[i_s
];)
710 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
718 double (*d
)[2] = (double (*)[2]) SCM_VELTS (dst
);
719 double (*s
)[2] = (double (*)[2]) SCM_VELTS (src
);
728 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
730 d
[i_d
][0] = ((long *) s
)[i_s
];
737 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
739 d
[i_d
][0] = ((float *) s
)[i_s
];
746 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
748 d
[i_d
][0] = ((double *) s
)[i_s
];
755 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
757 d
[i_d
][0] = s
[i_s
][0];
758 d
[i_d
][1] = s
[i_s
][1];
765 #endif /* SCM_FLOATS */
770 SCM_PROC(s_serial_array_copy_x
, "serial-array-copy!", 2, 0, 0, scm_array_copy_x
);
771 SCM_PROC(s_array_copy_x
, "array-copy!", 2, 0, 0, scm_array_copy_x
);
774 scm_array_copy_x (src
, dst
)
778 scm_ramapc (racp
, SCM_UNDEFINED
, src
, scm_cons (dst
, SCM_EOL
), s_array_copy_x
);
779 return SCM_UNSPECIFIED
;
782 /* Functions callable by ARRAY-MAP! */
786 scm_ra_eqp (ra0
, ras
)
790 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
791 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
792 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
793 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
794 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
795 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
796 ra0
= SCM_ARRAY_V (ra0
);
797 ra1
= SCM_ARRAY_V (ra1
);
798 ra2
= SCM_ARRAY_V (ra2
);
799 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
803 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
804 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
808 (scm_eq_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)))
814 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
817 if (SCM_VELTS (ra1
)[i1
] != SCM_VELTS (ra2
)[i2
])
823 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
826 if (((float *) SCM_VELTS (ra1
))[i1
] != ((float *) SCM_VELTS (ra2
))[i2
])
829 #endif /*SCM_SINGLES*/
831 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
834 if (((double *) SCM_VELTS (ra1
))[i1
] != ((double *) SCM_VELTS (ra2
))[i2
])
838 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
841 if (((double *) SCM_VELTS (ra1
))[2 * i1
] != ((double *) SCM_VELTS (ra2
))[2 * i2
] ||
842 ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1] != ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1])
845 #endif /*SCM_FLOATS*/
850 /* opt 0 means <, nonzero means >= */
852 static int ra_compare
SCM_P ((SCM ra0
, SCM ra1
, SCM ra2
, int opt
));
855 ra_compare (ra0
, ra1
, ra2
, opt
)
861 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
862 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
863 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
864 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
865 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
866 ra0
= SCM_ARRAY_V (ra0
);
867 ra1
= SCM_ARRAY_V (ra1
);
868 ra2
= SCM_ARRAY_V (ra2
);
869 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
873 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
874 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
878 SCM_NFALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))) :
879 SCM_FALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
885 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
890 SCM_VELTS (ra1
)[i1
] < SCM_VELTS (ra2
)[i2
] :
891 SCM_VELTS (ra1
)[i1
] >= SCM_VELTS (ra2
)[i2
])
898 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
902 ((float *) SCM_VELTS (ra1
))[i1
] < ((float *) SCM_VELTS (ra2
))[i2
] :
903 ((float *) SCM_VELTS (ra1
))[i1
] >= ((float *) SCM_VELTS (ra2
))[i2
])
906 #endif /*SCM_SINGLES*/
908 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
912 ((double *) SCM_VELTS (ra1
))[i1
] < ((double *) SCM_VELTS (ra2
))[i2
] :
913 ((double *) SCM_VELTS (ra1
))[i1
] >= ((double *) SCM_VELTS (ra2
))[i2
])
916 #endif /*SCM_FLOATS*/
924 scm_ra_lessp (ra0
, ras
)
928 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 0);
933 scm_ra_leqp (ra0
, ras
)
937 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 1);
942 scm_ra_grp (ra0
, ras
)
946 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 0);
951 scm_ra_greqp (ra0
, ras
)
955 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 1);
961 scm_ra_sum (ra0
, ras
)
965 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
966 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
967 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
968 ra0
= SCM_ARRAY_V (ra0
);
972 SCM ra1
= SCM_CAR (ras
);
973 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
974 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
975 ra1
= SCM_ARRAY_V (ra1
);
976 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
980 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
981 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
982 scm_array_set_x (ra0
, scm_sum (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
989 long *v0
= SCM_VELTS (ra0
);
990 long *v1
= SCM_VELTS (ra1
);
992 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1000 float *v0
= (float *) SCM_VELTS (ra0
);
1001 float *v1
= (float *) SCM_VELTS (ra1
);
1003 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1007 #endif /* SCM_SINGLES */
1010 double *v0
= (double *) SCM_VELTS (ra0
);
1011 double *v1
= (double *) SCM_VELTS (ra1
);
1013 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1019 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1020 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1022 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1024 v0
[i0
][0] += v1
[i1
][0];
1025 v0
[i0
][1] += v1
[i1
][1];
1030 #endif /* SCM_FLOATS */
1039 scm_ra_difference (ra0
, ras
)
1043 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1044 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1045 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1046 ra0
= SCM_ARRAY_V (ra0
);
1055 SCM e0
= SCM_UNDEFINED
;
1056 for (; n
-- > 0; i0
+= inc0
)
1057 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1064 float *v0
= (float *) SCM_VELTS (ra0
);
1065 for (; n
-- > 0; i0
+= inc0
)
1069 #endif /* SCM_SINGLES */
1072 double *v0
= (double *) SCM_VELTS (ra0
);
1073 for (; n
-- > 0; i0
+= inc0
)
1079 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1080 for (; n
-- > 0; i0
+= inc0
)
1082 v0
[i0
][0] = -v0
[i0
][0];
1083 v0
[i0
][1] = -v0
[i0
][1];
1087 #endif /* SCM_FLOATS */
1092 SCM ra1
= SCM_CAR (ras
);
1093 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1094 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1095 ra1
= SCM_ARRAY_V (ra1
);
1096 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1100 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1101 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1102 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1109 float *v0
= (float *) SCM_VELTS (ra0
);
1110 float *v1
= (float *) SCM_VELTS (ra1
);
1112 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1116 #endif /* SCM_SINGLES */
1119 double *v0
= (double *) SCM_VELTS (ra0
);
1120 double *v1
= (double *) SCM_VELTS (ra1
);
1122 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1128 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1129 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1131 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1133 v0
[i0
][0] -= v1
[i1
][0];
1134 v0
[i0
][1] -= v1
[i1
][1];
1139 #endif /* SCM_FLOATS */
1148 scm_ra_product (ra0
, ras
)
1152 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1153 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1154 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1155 ra0
= SCM_ARRAY_V (ra0
);
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)
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
)),
1176 long *v0
= SCM_VELTS (ra0
);
1177 long *v1
= SCM_VELTS (ra1
);
1179 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1187 float *v0
= (float *) SCM_VELTS (ra0
);
1188 float *v1
= (float *) SCM_VELTS (ra1
);
1190 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1194 #endif /* SCM_SINGLES */
1197 double *v0
= (double *) SCM_VELTS (ra0
);
1198 double *v1
= (double *) SCM_VELTS (ra1
);
1200 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1206 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1208 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1210 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
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];
1219 #endif /* SCM_FLOATS */
1227 scm_ra_divide (ra0
, ras
)
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
);
1243 SCM e0
= SCM_UNDEFINED
;
1244 for (; n
-- > 0; i0
+= inc0
)
1245 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1252 float *v0
= (float *) SCM_VELTS (ra0
);
1253 for (; n
-- > 0; i0
+= inc0
)
1254 v0
[i0
] = 1.0 / v0
[i0
];
1257 #endif /* SCM_SINGLES */
1260 double *v0
= (double *) SCM_VELTS (ra0
);
1261 for (; n
-- > 0; i0
+= inc0
)
1262 v0
[i0
] = 1.0 / v0
[i0
];
1268 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1269 for (; n
-- > 0; i0
+= inc0
)
1271 d
= v0
[i0
][0] * v0
[i0
][0] + v0
[i0
][1] * v0
[i0
][1];
1277 #endif /* SCM_FLOATS */
1282 SCM ra1
= SCM_CAR (ras
);
1283 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1284 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1285 ra1
= SCM_ARRAY_V (ra1
);
1286 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1290 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1291 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1292 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1299 float *v0
= (float *) SCM_VELTS (ra0
);
1300 float *v1
= (float *) SCM_VELTS (ra1
);
1302 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1306 #endif /* SCM_SINGLES */
1309 double *v0
= (double *) SCM_VELTS (ra0
);
1310 double *v1
= (double *) SCM_VELTS (ra1
);
1312 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1318 register double d
, r
;
1319 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1320 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1322 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1324 d
= v1
[i1
][0] * v1
[i1
][0] + v1
[i1
][1] * v1
[i1
][1];
1325 r
= (v0
[i0
][0] * v1
[i1
][0] + v0
[i0
][1] * v1
[i1
][1]) / d
;
1326 v0
[i0
][1] = (v0
[i0
][1] * v1
[i1
][0] - v0
[i0
][0] * v1
[i1
][1]) / d
;
1332 #endif /* SCM_FLOATS */
1340 scm_array_identity (dst
, src
)
1344 return racp (SCM_CAR (src
), scm_cons (dst
, SCM_EOL
));
1349 static int ramap
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1352 ramap (ra0
, proc
, ras
)
1357 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1358 long inc
= SCM_ARRAY_DIMS (ra0
)->inc
;
1359 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1360 long base
= SCM_ARRAY_BASE (ra0
) - i
* inc
;
1361 ra0
= SCM_ARRAY_V (ra0
);
1365 scm_array_set_x (ra0
, scm_apply (proc
, SCM_EOL
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1368 SCM ra1
= SCM_CAR (ras
);
1369 SCM args
, *ve
= &ras
;
1370 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1371 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1372 ra1
= SCM_ARRAY_V (ra1
);
1373 ras
= SCM_CDR (ras
);
1379 ras
= scm_vector (ras
);
1380 ve
= SCM_VELTS (ras
);
1382 for (; i
<= n
; i
++, i1
+= inc1
)
1385 for (k
= SCM_LENGTH (ras
); k
--;)
1386 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1387 args
= scm_cons (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1388 scm_array_set_x (ra0
, scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1395 static int ramap_cxr
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1398 ramap_cxr (ra0
, proc
, ras
)
1403 SCM ra1
= SCM_CAR (ras
);
1404 SCM e1
= SCM_UNDEFINED
;
1405 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1406 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1407 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra1
)->lbnd
+ 1;
1408 ra0
= SCM_ARRAY_V (ra0
);
1409 ra1
= SCM_ARRAY_V (ra1
);
1415 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1416 scm_array_set_x (ra0
, scm_apply (proc
, RVREF (ra1
, i1
, e1
), scm_listofnull
), SCM_MAKINUM (i0
));
1422 float *dst
= (float *) SCM_VELTS (ra0
);
1429 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1430 dst
[i0
] = SCM_DSUBRF (proc
) ((double) ((float *) SCM_VELTS (ra1
))[i1
]);
1434 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1435 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1440 #endif /* SCM_SINGLES */
1443 double *dst
= (double *) SCM_VELTS (ra0
);
1450 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1451 dst
[i0
] = SCM_DSUBRF (proc
) (((double *) SCM_VELTS (ra1
))[i1
]);
1455 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1456 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1461 #endif /* SCM_FLOATS */
1468 static int ramap_rp
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1471 ramap_rp (ra0
, proc
, ras
)
1476 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
1477 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
1478 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1479 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
1480 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1481 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1482 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
1483 ra0
= SCM_ARRAY_V (ra0
);
1484 ra1
= SCM_ARRAY_V (ra1
);
1485 ra2
= SCM_ARRAY_V (ra2
);
1486 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
1489 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1493 (SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)))
1498 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1503 (SCM_SUBRF (proc
) (SCM_MAKINUM (SCM_VELTS (ra1
)[i1
]),
1504 SCM_MAKINUM (SCM_VELTS (ra2
)[i2
])))
1512 SCM a1
= scm_makflo (1.0), a2
= scm_makflo (1.0);
1513 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1517 SCM_FLO (a1
) = ((float *) SCM_VELTS (ra1
))[i1
];
1518 SCM_FLO (a2
) = ((float *) SCM_VELTS (ra2
))[i2
];
1520 (SCM_SUBRF (proc
) (a1
, a2
))
1525 #endif /*SCM_SINGLES*/
1528 SCM a1
= scm_makdbl (1.0 / 3.0, 0.0), a2
= scm_makdbl (1.0 / 3.0, 0.0);
1529 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1533 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[i1
];
1534 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[i2
];
1536 (SCM_SUBRF (proc
) (a1
, a2
))
1543 SCM a1
= scm_makdbl (1.0, 1.0), a2
= scm_makdbl (1.0, 1.0);
1544 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1548 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
];
1549 SCM_IMAG (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1];
1550 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
];
1551 SCM_IMAG (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1];
1553 (SCM_SUBRF (proc
) (a1
, a2
))
1558 #endif /*SCM_FLOATS*/
1565 static int ramap_1
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1568 ramap_1 (ra0
, proc
, ras
)
1573 SCM ra1
= SCM_CAR (ras
);
1574 SCM e1
= SCM_UNDEFINED
;
1575 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1576 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1577 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1578 ra0
= SCM_ARRAY_V (ra0
);
1579 ra1
= SCM_ARRAY_V (ra1
);
1580 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1581 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1582 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
)), SCM_MAKINUM (i0
));
1584 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1585 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1591 static int ramap_2o
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1594 ramap_2o (ra0
, proc
, ras
)
1599 SCM ra1
= SCM_CAR (ras
);
1600 SCM e1
= SCM_UNDEFINED
;
1601 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1602 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1603 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1604 ra0
= SCM_ARRAY_V (ra0
);
1605 ra1
= SCM_ARRAY_V (ra1
);
1606 ras
= SCM_CDR (ras
);
1610 if (scm_tc7_vector
== SCM_TYP7 (ra0
)
1611 || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1613 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1614 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), SCM_UNDEFINED
),
1617 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1618 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), SCM_UNDEFINED
),
1623 SCM ra2
= SCM_CAR (ras
);
1624 SCM e2
= SCM_UNDEFINED
;
1625 scm_sizet i2
= SCM_ARRAY_BASE (ra2
);
1626 long inc2
= SCM_ARRAY_DIMS (ra2
)->inc
;
1627 ra2
= SCM_ARRAY_V (ra2
);
1628 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1629 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1630 scm_array_set_x (ra0
,
1631 SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), scm_cvref (ra2
, i2
, SCM_UNDEFINED
)),
1634 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1635 scm_array_set_x (ra0
,
1636 SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)),
1644 static int ramap_a
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1647 ramap_a (ra0
, proc
, ras
)
1652 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1653 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1654 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1655 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1656 ra0
= SCM_ARRAY_V (ra0
);
1659 for (; n
-- > 0; i0
+= inc0
)
1660 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1663 SCM ra1
= SCM_CAR (ras
);
1664 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1665 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1666 ra1
= SCM_ARRAY_V (ra1
);
1667 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1668 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1674 SCM_PROC(s_serial_array_map_x
, "serial-array-map!", 2, 0, 1, scm_array_map_x
);
1675 SCM_PROC(s_array_map_x
, "array-map!", 2, 0, 1, scm_array_map_x
);
1678 scm_array_map_x (ra0
, proc
, lra
)
1683 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
, s_array_map_x
);
1684 switch (SCM_TYP7 (proc
))
1688 scm_ramapc (ramap
, proc
, ra0
, lra
, s_array_map_x
);
1689 return SCM_UNSPECIFIED
;
1690 case scm_tc7_subr_1
:
1691 scm_ramapc (ramap_1
, proc
, ra0
, lra
, s_array_map_x
);
1692 return SCM_UNSPECIFIED
;
1693 case scm_tc7_subr_2
:
1694 case scm_tc7_subr_2o
:
1695 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map_x
);
1696 return SCM_UNSPECIFIED
;
1698 if (!SCM_SUBRF (proc
))
1700 scm_ramapc (ramap_cxr
, proc
, ra0
, lra
, s_array_map_x
);
1701 return SCM_UNSPECIFIED
;
1702 case scm_tc7_rpsubr
:
1705 if (SCM_FALSEP (scm_array_p (ra0
, SCM_BOOL_T
)))
1707 scm_array_fill_x (ra0
, SCM_BOOL_T
);
1708 for (p
= ra_rpsubrs
; p
->name
; p
++)
1709 if (proc
== p
->sproc
)
1711 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1713 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map_x
);
1714 lra
= SCM_CDR (lra
);
1716 return SCM_UNSPECIFIED
;
1718 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1720 scm_ramapc (ramap_rp
, proc
, ra0
, lra
, s_array_map_x
);
1721 lra
= SCM_CDR (lra
);
1723 return SCM_UNSPECIFIED
;
1729 SCM prot
, fill
= SCM_SUBRF (proc
) (SCM_UNDEFINED
, SCM_UNDEFINED
);
1733 prot
= scm_array_prototype (ra0
);
1734 if (SCM_NIMP (prot
) && SCM_INEXP (prot
))
1735 fill
= scm_makdbl ((double) SCM_INUM (fill
), 0.0);
1738 scm_array_fill_x (ra0
, fill
);
1742 SCM tail
, ra1
= SCM_CAR (lra
);
1743 SCM v0
= (SCM_NIMP (ra0
) && SCM_ARRAYP (ra0
) ? SCM_ARRAY_V (ra0
) : ra0
);
1745 /* Check to see if order might matter.
1746 This might be an argument for a separate
1747 SERIAL-ARRAY-MAP! */
1748 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1749 if (ra0
!= ra1
|| (SCM_ARRAYP(ra0
) && !SCM_ARRAY_CONTP(ra0
)))
1751 for (tail
= SCM_CDR (lra
); SCM_NNULLP (tail
); tail
= SCM_CDR (tail
))
1753 ra1
= SCM_CAR (tail
);
1754 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1757 for (p
= ra_asubrs
; p
->name
; p
++)
1758 if (proc
== p
->sproc
)
1760 if (ra0
!= SCM_CAR (lra
))
1761 scm_ramapc (scm_array_identity
, SCM_UNDEFINED
, ra0
, scm_cons (SCM_CAR (lra
), SCM_EOL
), s_array_map_x
);
1762 lra
= SCM_CDR (lra
);
1765 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map_x
);
1766 if (SCM_IMP (lra
) || SCM_IMP (SCM_CDR (lra
)))
1767 return SCM_UNSPECIFIED
;
1768 lra
= SCM_CDR (lra
);
1771 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map_x
);
1772 lra
= SCM_CDR (lra
);
1775 for (lra
= SCM_CDR (lra
); SCM_NIMP (lra
); lra
= SCM_CDR (lra
))
1776 scm_ramapc (ramap_a
, proc
, ra0
, lra
, s_array_map_x
);
1778 return SCM_UNSPECIFIED
;
1783 static int rafe
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1786 rafe (ra0
, proc
, ras
)
1791 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1792 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1793 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1794 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1795 ra0
= SCM_ARRAY_V (ra0
);
1798 for (; i
<= n
; i
++, i0
+= inc0
)
1799 scm_apply (proc
, scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_listofnull
);
1802 SCM ra1
= SCM_CAR (ras
);
1803 SCM args
, *ve
= &ras
;
1804 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1805 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1806 ra1
= SCM_ARRAY_V (ra1
);
1807 ras
= SCM_CDR (ras
);
1813 ras
= scm_vector (ras
);
1814 ve
= SCM_VELTS (ras
);
1816 for (; i
<= n
; i
++, i0
+= inc0
, i1
+= inc1
)
1819 for (k
= SCM_LENGTH (ras
); k
--;)
1820 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1821 args
= scm_cons2 (scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1822 scm_apply (proc
, args
, SCM_EOL
);
1829 SCM_PROC(s_array_for_each
, "array-for-each", 2, 0, 1, scm_array_for_each
);
1832 scm_array_for_each (proc
, ra0
, lra
)
1837 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG1
, s_array_for_each
);
1838 scm_ramapc (rafe
, proc
, ra0
, lra
, s_array_for_each
);
1839 return SCM_UNSPECIFIED
;
1842 SCM_PROC(s_array_index_map_x
, "array-index-map!", 2, 0, 0, scm_array_index_map_x
);
1845 scm_array_index_map_x (ra
, proc
)
1850 SCM_ASSERT (SCM_NIMP (ra
), ra
, SCM_ARG1
, s_array_index_map_x
);
1851 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
,
1852 s_array_index_map_x
);
1853 switch (SCM_TYP7(ra
))
1856 badarg
:scm_wta (ra
, (char *) SCM_ARG1
, s_array_index_map_x
);
1857 case scm_tc7_vector
:
1860 SCM
*ve
= SCM_VELTS (ra
);
1861 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1862 ve
[i
] = scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
);
1863 return SCM_UNSPECIFIED
;
1865 case scm_tc7_string
:
1866 case scm_tc7_byvect
:
1872 case scm_tc7_llvect
:
1877 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1878 scm_array_set_x (ra
, scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
),
1880 return SCM_UNSPECIFIED
;
1882 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
1885 SCM inds
= scm_make_uve (SCM_ARRAY_NDIM (ra
), SCM_MAKINUM (-1L));
1886 long *vinds
= SCM_VELTS (inds
);
1887 int j
, k
, kmax
= SCM_ARRAY_NDIM (ra
) - 1;
1889 return scm_array_set_x (ra
, scm_apply(proc
, SCM_EOL
, SCM_EOL
),
1891 for (k
= 0; k
<= kmax
; k
++)
1892 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1898 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1899 i
= cind (ra
, inds
);
1900 for (; vinds
[k
] <= SCM_ARRAY_DIMS (ra
)[k
].ubnd
; vinds
[k
]++)
1902 for (j
= kmax
+ 1, args
= SCM_EOL
; j
--;)
1903 args
= scm_cons (SCM_MAKINUM (vinds
[j
]), args
);
1904 scm_array_set_x (SCM_ARRAY_V (ra
),
1905 scm_apply (proc
, args
, SCM_EOL
),
1907 i
+= SCM_ARRAY_DIMS (ra
)[k
].inc
;
1912 if (vinds
[k
] < SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
1918 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
- 1;
1922 return SCM_UNSPECIFIED
;
1928 static int raeql_1
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
1931 raeql_1 (ra0
, as_equal
, ra1
)
1936 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1937 scm_sizet i0
= 0, i1
= 0;
1938 long inc0
= 1, inc1
= 1;
1939 scm_sizet n
= SCM_LENGTH (ra0
);
1940 ra1
= SCM_CAR (ra1
);
1944 n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1945 i0
= SCM_ARRAY_BASE (ra0
);
1946 inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1947 ra0
= SCM_ARRAY_V (ra0
);
1952 i1
= SCM_ARRAY_BASE (ra1
);
1953 inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1954 ra1
= SCM_ARRAY_V (ra1
);
1959 case scm_tc7_vector
:
1962 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1968 (scm_array_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)))
1972 (scm_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)))
1976 case scm_tc7_string
:
1977 case scm_tc7_byvect
:
1979 char *v0
= SCM_CHARS (ra0
) + i0
;
1980 char *v1
= SCM_CHARS (ra1
) + i1
;
1981 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1987 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1988 if (BVE_REF (ra0
, i0
) != BVE_REF (ra1
, i1
))
1994 long *v0
= (long *) SCM_VELTS (ra0
) + i0
;
1995 long *v1
= (long *) SCM_VELTS (ra1
) + i1
;
1996 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2003 short *v0
= (short *) SCM_VELTS (ra0
) + i0
;
2004 short *v1
= (short *) SCM_VELTS (ra1
) + i1
;
2005 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2011 case scm_tc7_llvect
:
2013 long long *v0
= (long long *) SCM_VELTS (ra0
) + i0
;
2014 long long *v1
= (long long *) SCM_VELTS (ra1
) + i1
;
2015 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2025 float *v0
= (float *) SCM_VELTS (ra0
) + i0
;
2026 float *v1
= (float *) SCM_VELTS (ra1
) + i1
;
2027 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2032 #endif /* SCM_SINGLES */
2035 double *v0
= (double *) SCM_VELTS (ra0
) + i0
;
2036 double *v1
= (double *) SCM_VELTS (ra1
) + i1
;
2037 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2044 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
) + i0
;
2045 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
) + i1
;
2046 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2048 if ((*v0
)[0] != (*v1
)[0])
2050 if ((*v0
)[1] != (*v1
)[1])
2055 #endif /* SCM_FLOATS */
2061 static int raeql
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
2064 raeql (ra0
, as_equal
, ra1
)
2069 SCM v0
= ra0
, v1
= ra1
;
2070 scm_array_dim dim0
, dim1
;
2071 scm_array_dim
*s0
= &dim0
, *s1
= &dim1
;
2072 scm_sizet bas0
= 0, bas1
= 0;
2073 int k
, unroll
= 1, vlen
= 1, ndim
= 1;
2077 ndim
= SCM_ARRAY_NDIM (ra0
);
2078 s0
= SCM_ARRAY_DIMS (ra0
);
2079 bas0
= SCM_ARRAY_BASE (ra0
);
2080 v0
= SCM_ARRAY_V (ra0
);
2086 s0
->ubnd
= SCM_LENGTH (v0
) - 1;
2092 if (ndim
!= SCM_ARRAY_NDIM (ra1
))
2094 s1
= SCM_ARRAY_DIMS (ra1
);
2095 bas1
= SCM_ARRAY_BASE (ra1
);
2096 v1
= SCM_ARRAY_V (ra1
);
2104 s1
->ubnd
= SCM_LENGTH (v1
) - 1;
2107 if (SCM_TYP7 (v0
) != SCM_TYP7 (v1
))
2109 for (k
= ndim
; k
--;)
2111 if (s0
[k
].lbnd
!= s1
[k
].lbnd
|| s0
[k
].ubnd
!= s1
[k
].ubnd
)
2115 unroll
= (s0
[k
].inc
== s1
[k
].inc
);
2116 vlen
*= s0
[k
].ubnd
- s1
[k
].lbnd
+ 1;
2119 if (unroll
&& bas0
== bas1
&& v0
== v1
)
2121 return scm_ramapc (raeql_1
, as_equal
, ra0
, scm_cons (ra1
, SCM_EOL
), "");
2126 scm_raequal (ra0
, ra1
)
2130 return (raeql (ra0
, SCM_BOOL_T
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2133 static char s_array_equal_p
[] = "array-equal?";
2137 scm_array_equal_p (ra0
, ra1
)
2141 if (SCM_IMP (ra0
) || SCM_IMP (ra1
))
2142 callequal
:return scm_equal_p (ra0
, ra1
);
2149 case scm_tc7_string
:
2150 case scm_tc7_byvect
:
2156 case scm_tc7_vector
:
2160 if (!SCM_ARRAYP (ra0
))
2169 case scm_tc7_string
:
2170 case scm_tc7_byvect
:
2176 case scm_tc7_vector
:
2180 if (!SCM_ARRAYP (ra1
))
2183 return (raeql (ra0
, SCM_BOOL_F
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2189 init_raprocs (subra
)
2192 for (; subra
->name
; subra
++)
2193 subra
->sproc
= SCM_CDR (scm_intern (subra
->name
, strlen (subra
->name
)));
2200 init_raprocs (ra_rpsubrs
);
2201 init_raprocs (ra_asubrs
);
2202 scm_make_subr (s_array_equal_p
, scm_tc7_rpsubr
, scm_array_equal_p
);
2203 scm_smobs
[0x0ff & (scm_tc16_array
>> 8)].equalp
= scm_raequal
;
2205 scm_add_feature (s_array_for_each
);