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, 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
))
172 s0
->ubnd
= (long) SCM_LENGTH (ra0
) - 1;
175 if (!SCM_ARRAYP (ra0
))
177 ndim
= SCM_ARRAY_NDIM (ra0
);
178 s0
= SCM_ARRAY_DIMS (ra0
);
179 bas0
= SCM_ARRAY_BASE (ra0
);
213 if ((0 == s0
->lbnd
) && (s0
->ubnd
== SCM_LENGTH (ra1
) - 1))
217 if (s0
->lbnd
< 0 || s0
->ubnd
>= SCM_LENGTH (ra1
))
222 if (!SCM_ARRAYP (ra1
) || ndim
!= SCM_ARRAY_NDIM (ra1
))
224 s1
= SCM_ARRAY_DIMS (ra1
);
225 if (bas0
!= SCM_ARRAY_BASE (ra1
))
227 for (i
= 0; i
< ndim
; i
++)
232 if (s0
[i
].inc
!= s1
[i
].inc
)
235 if (s0
[i
].lbnd
== s1
[i
].lbnd
&& s0
[i
].ubnd
== s1
[i
].ubnd
)
239 if (s0
[i
].lbnd
< s1
[i
].lbnd
|| s0
[i
].ubnd
> s1
[i
].ubnd
)
240 return (s0
[i
].lbnd
<= s0
[i
].ubnd
? 0 : 1);
249 static char s_ra_mismatch
[] = "array shape mismatch";
252 scm_ramapc (cproc
, data
, ra0
, lra
, what
)
264 switch (scm_ra_matchp (ra0
, lra
))
268 scm_wta (ra0
, s_ra_mismatch
, what
);
271 case 4: /* Try unrolling arrays */
272 kmax
= (SCM_ARRAYP (ra0
) ? SCM_ARRAY_NDIM (ra0
) - 1 : 0);
275 vra0
= scm_array_contents (ra0
, SCM_UNDEFINED
);
278 if (!SCM_ARRAYP (vra0
))
280 vra1
= scm_make_ra (1);
281 SCM_ARRAY_BASE (vra1
) = 0;
282 SCM_ARRAY_DIMS (vra1
)->lbnd
= 0;
283 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_LENGTH (vra0
) - 1;
284 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
285 SCM_ARRAY_V (vra1
) = vra0
;
290 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
293 vra1
= scm_make_ra (1);
294 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
295 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
296 if (!SCM_ARRAYP (ra1
))
298 SCM_ARRAY_BASE (vra1
) = 0;
299 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
300 SCM_ARRAY_V (vra1
) = ra1
;
302 else if (!SCM_ARRAY_CONTP (ra1
))
306 SCM_ARRAY_BASE (vra1
) = SCM_ARRAY_BASE (ra1
);
307 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
308 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
310 *plvra
= scm_cons (vra1
, SCM_EOL
);
311 plvra
= SCM_CDRLOC (*plvra
);
313 return (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
));
315 gencase
: /* Have to loop over all dimensions. */
316 vra0
= scm_make_ra (1);
320 kmax
= SCM_ARRAY_NDIM (ra0
) - 1;
323 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
324 SCM_ARRAY_DIMS (vra0
)->ubnd
= 0;
325 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
329 SCM_ARRAY_DIMS (vra0
)->lbnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].lbnd
;
330 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].ubnd
;
331 SCM_ARRAY_DIMS (vra0
)->inc
= SCM_ARRAY_DIMS (ra0
)[kmax
].inc
;
333 SCM_ARRAY_BASE (vra0
) = SCM_ARRAY_BASE (ra0
);
334 SCM_ARRAY_V (vra0
) = SCM_ARRAY_V (ra0
);
339 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
340 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_LENGTH (ra0
) - 1;
341 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
342 SCM_ARRAY_BASE (vra0
) = 0;
343 SCM_ARRAY_V (vra0
) = ra0
;
348 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
351 vra1
= scm_make_ra (1);
352 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
353 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
358 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
359 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
363 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
364 SCM_ARRAY_V (vra1
) = ra1
;
366 *plvra
= scm_cons (vra1
, SCM_EOL
);
367 plvra
= SCM_CDRLOC (*plvra
);
369 inds
= scm_make_uve (SCM_ARRAY_NDIM (ra0
), SCM_MAKINUM (-1L));
370 vinds
= (long *) SCM_VELTS (inds
);
371 for (k
= 0; k
<= kmax
; k
++)
372 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
;
379 SCM_ARRAY_BASE (vra0
) = cind (ra0
, inds
);
380 for (z
= lvra
; SCM_NIMP (z
); z
= SCM_CDR (z
), y
= SCM_CDR (y
))
381 SCM_ARRAY_BASE (SCM_CAR (z
)) = cind (SCM_CAR (y
), inds
);
382 if (0 == (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
)))
387 if (vinds
[k
] < SCM_ARRAY_DIMS (ra0
)[k
].ubnd
)
393 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
- 1;
402 SCM_PROC(s_array_fill_x
, "array-fill!", 2, 0, 0, scm_array_fill_x
);
405 scm_array_fill_x (ra
, fill
)
409 scm_ramapc (scm_array_fill_int
, fill
, ra
, SCM_EOL
, s_array_fill_x
);
410 return SCM_UNSPECIFIED
;
415 scm_array_fill_int (ra
, fill
, ignore
)
420 scm_sizet i
, n
= SCM_ARRAY_DIMS (ra
)->ubnd
- SCM_ARRAY_DIMS (ra
)->lbnd
+ 1;
421 long inc
= SCM_ARRAY_DIMS (ra
)->inc
;
422 scm_sizet base
= SCM_ARRAY_BASE (ra
);
423 ra
= SCM_ARRAY_V (ra
);
428 for (i
= base
; n
--; i
+= inc
)
429 scm_array_set_x (ra
, fill
, SCM_MAKINUM (i
));
432 for (i
= base
; n
--; i
+= inc
)
433 SCM_VELTS (ra
)[i
] = fill
;
436 SCM_ASRTGO (SCM_ICHRP (fill
), badarg2
);
437 for (i
= base
; n
--; i
+= inc
)
438 SCM_CHARS (ra
)[i
] = SCM_ICHR (fill
);
441 if (SCM_ICHRP (fill
))
442 fill
= SCM_MAKINUM ((char) SCM_ICHR (fill
));
443 SCM_ASRTGO (SCM_INUMP (fill
)
444 && -128 <= SCM_INUM (fill
) && SCM_INUM (fill
) < 128,
446 for (i
= base
; n
--; i
+= inc
)
447 SCM_CHARS (ra
)[i
] = SCM_INUM (fill
);
451 long *ve
= (long *) SCM_VELTS (ra
);
452 if (1 == inc
&& (n
>= SCM_LONG_BIT
|| n
== SCM_LENGTH (ra
)))
454 i
= base
/ SCM_LONG_BIT
;
455 if (SCM_BOOL_F
== fill
)
457 if (base
% SCM_LONG_BIT
) /* leading partial word */
458 ve
[i
++] &= ~(~0L << (base
% SCM_LONG_BIT
));
459 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
461 if ((base
+ n
) % SCM_LONG_BIT
) /* trailing partial word */
462 ve
[i
] &= (~0L << ((base
+ n
) % SCM_LONG_BIT
));
464 else if (SCM_BOOL_T
== fill
)
466 if (base
% SCM_LONG_BIT
)
467 ve
[i
++] |= ~0L << (base
% SCM_LONG_BIT
);
468 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
470 if ((base
+ n
) % SCM_LONG_BIT
)
471 ve
[i
] |= ~(~0L << ((base
+ n
) % SCM_LONG_BIT
));
474 badarg2
:scm_wta (fill
, (char *) SCM_ARG2
, s_array_fill_x
);
478 if (SCM_BOOL_F
== fill
)
479 for (i
= base
; n
--; i
+= inc
)
480 ve
[i
/ SCM_LONG_BIT
] &= ~(1L << (i
% SCM_LONG_BIT
));
481 else if (SCM_BOOL_T
== fill
)
482 for (i
= base
; n
--; i
+= inc
)
483 ve
[i
/ SCM_LONG_BIT
] |= (1L << (i
% SCM_LONG_BIT
));
490 SCM_ASRTGO (0 <= SCM_INUM (fill
), badarg2
);
492 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
494 long f
= SCM_INUM (fill
), *ve
= (long *) SCM_VELTS (ra
);
495 for (i
= base
; n
--; i
+= inc
)
503 float f
, *ve
= (float *) SCM_VELTS (ra
);
504 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
505 f
= SCM_REALPART (fill
);
506 for (i
= base
; n
--; i
+= inc
)
510 #endif /* SCM_SINGLES */
513 double f
, *ve
= (double *) SCM_VELTS (ra
);
514 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
515 f
= SCM_REALPART (fill
);
516 for (i
= base
; n
--; i
+= inc
)
523 double (*ve
)[2] = (double (*)[2]) SCM_VELTS (ra
);
524 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_INEXP (fill
), badarg2
);
525 fr
= SCM_REALPART (fill
);
526 fi
= (SCM_CPLXP (fill
) ? SCM_IMAG (fill
) : 0.0);
527 for (i
= base
; n
--; i
+= inc
)
534 #endif /* SCM_FLOATS */
542 static int racp
SCM_P ((SCM dst
, SCM src
));
549 long n
= (SCM_ARRAY_DIMS (src
)->ubnd
- SCM_ARRAY_DIMS (src
)->lbnd
+ 1);
550 long inc_d
, inc_s
= SCM_ARRAY_DIMS (src
)->inc
;
551 scm_sizet i_d
, i_s
= SCM_ARRAY_BASE (src
);
553 inc_d
= SCM_ARRAY_DIMS (dst
)->inc
;
554 i_d
= SCM_ARRAY_BASE (dst
);
555 src
= SCM_ARRAY_V (src
);
556 dst
= SCM_ARRAY_V (dst
);
561 gencase
: case scm_tc7_vector
:
562 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
563 scm_array_set_x (dst
, scm_cvref (src
, i_s
, SCM_UNDEFINED
), SCM_MAKINUM (i_d
));
567 if (scm_tc7_string
!= SCM_TYP7 (dst
))
569 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
570 SCM_CHARS (dst
)[i_d
] = SCM_CHARS (src
)[i_s
];
573 if (scm_tc7_bvect
!= SCM_TYP7 (dst
))
575 if (1 == inc_d
&& 1 == inc_s
&& i_s
% SCM_LONG_BIT
== i_d
% SCM_LONG_BIT
&& n
>= SCM_LONG_BIT
)
577 long *sv
= (long *) SCM_VELTS (src
);
578 long *dv
= (long *) SCM_VELTS (dst
);
579 sv
+= i_s
/ SCM_LONG_BIT
;
580 dv
+= i_d
/ SCM_LONG_BIT
;
581 if (i_s
% SCM_LONG_BIT
)
582 { /* leading partial word */
583 *dv
= (*dv
& ~(~0L << (i_s
% SCM_LONG_BIT
))) | (*sv
& (~0L << (i_s
% SCM_LONG_BIT
)));
586 n
-= SCM_LONG_BIT
- (i_s
% SCM_LONG_BIT
);
589 for (; n
>= SCM_LONG_BIT
; n
-= SCM_LONG_BIT
, sv
++, dv
++)
591 if (n
) /* trailing partial word */
592 *dv
= (*dv
& (~0L << n
)) | (*sv
& ~(~0L << n
));
596 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
597 if (SCM_VELTS (src
)[i_s
/ SCM_LONG_BIT
] & (1L << (i_s
% SCM_LONG_BIT
)))
598 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] |= (1L << (i_d
% SCM_LONG_BIT
));
600 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] &= ~(1L << (i_d
% SCM_LONG_BIT
));
604 if (scm_tc7_uvect
!= SCM_TYP7 (src
))
608 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
610 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
615 if (scm_tc7_uvect
!= SCM_TYP7 (src
) && scm_tc7_ivect
!= SCM_TYP7 (src
))
619 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
621 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
629 float *d
= (float *) SCM_VELTS (dst
);
630 float *s
= (float *) SCM_VELTS (src
);
639 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
640 d
[i_d
] = ((long *) s
)[i_s
];)
644 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
649 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
650 d
[i_d
] = ((double *) s
)[i_s
];)
655 #endif /* SCM_SINGLES */
658 double *d
= (double *) SCM_VELTS (dst
);
659 double *s
= (double *) SCM_VELTS (src
);
668 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
669 d
[i_d
] = ((long *) s
)[i_s
];)
673 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
674 d
[i_d
] = ((float *) s
)[i_s
];)
678 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
686 double (*d
)[2] = (double (*)[2]) SCM_VELTS (dst
);
687 double (*s
)[2] = (double (*)[2]) SCM_VELTS (src
);
696 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
698 d
[i_d
][0] = ((long *) s
)[i_s
];
705 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
707 d
[i_d
][0] = ((float *) s
)[i_s
];
714 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
716 d
[i_d
][0] = ((double *) s
)[i_s
];
723 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
725 d
[i_d
][0] = s
[i_s
][0];
726 d
[i_d
][1] = s
[i_s
][1];
733 #endif /* SCM_FLOATS */
738 SCM_PROC(s_serial_array_copy_x
, "serial-array-copy!", 2, 0, 0, scm_array_copy_x
);
739 SCM_PROC(s_array_copy_x
, "array-copy!", 2, 0, 0, scm_array_copy_x
);
742 scm_array_copy_x (src
, dst
)
746 scm_ramapc (racp
, SCM_UNDEFINED
, src
, scm_cons (dst
, SCM_EOL
), s_array_copy_x
);
747 return SCM_UNSPECIFIED
;
750 /* Functions callable by ARRAY-MAP! */
754 scm_ra_eqp (ra0
, ras
)
758 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
759 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
760 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
761 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
762 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
763 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
764 ra0
= SCM_ARRAY_V (ra0
);
765 ra1
= SCM_ARRAY_V (ra1
);
766 ra2
= SCM_ARRAY_V (ra2
);
767 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
771 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
772 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
776 (scm_eq_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)))
782 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
785 if (SCM_VELTS (ra1
)[i1
] != SCM_VELTS (ra2
)[i2
])
791 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
794 if (((float *) SCM_VELTS (ra1
))[i1
] != ((float *) SCM_VELTS (ra2
))[i2
])
797 #endif /*SCM_SINGLES*/
799 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
802 if (((double *) SCM_VELTS (ra1
))[i1
] != ((double *) SCM_VELTS (ra2
))[i2
])
806 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
809 if (((double *) SCM_VELTS (ra1
))[2 * i1
] != ((double *) SCM_VELTS (ra2
))[2 * i2
] ||
810 ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1] != ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1])
813 #endif /*SCM_FLOATS*/
818 /* opt 0 means <, nonzero means >= */
820 static int ra_compare
SCM_P ((SCM ra0
, SCM ra1
, SCM ra2
, int opt
));
823 ra_compare (ra0
, ra1
, ra2
, opt
)
829 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
830 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
831 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
832 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
833 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
834 ra0
= SCM_ARRAY_V (ra0
);
835 ra1
= SCM_ARRAY_V (ra1
);
836 ra2
= SCM_ARRAY_V (ra2
);
837 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
841 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
842 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
846 SCM_NFALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))) :
847 SCM_FALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
853 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
858 SCM_VELTS (ra1
)[i1
] < SCM_VELTS (ra2
)[i2
] :
859 SCM_VELTS (ra1
)[i1
] >= SCM_VELTS (ra2
)[i2
])
866 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
870 ((float *) SCM_VELTS (ra1
))[i1
] < ((float *) SCM_VELTS (ra2
))[i2
] :
871 ((float *) SCM_VELTS (ra1
))[i1
] >= ((float *) SCM_VELTS (ra2
))[i2
])
874 #endif /*SCM_SINGLES*/
876 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
880 ((double *) SCM_VELTS (ra1
))[i1
] < ((double *) SCM_VELTS (ra2
))[i2
] :
881 ((double *) SCM_VELTS (ra1
))[i1
] >= ((double *) SCM_VELTS (ra2
))[i2
])
884 #endif /*SCM_FLOATS*/
892 scm_ra_lessp (ra0
, ras
)
896 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 0);
901 scm_ra_leqp (ra0
, ras
)
905 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 1);
910 scm_ra_grp (ra0
, ras
)
914 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 0);
919 scm_ra_greqp (ra0
, ras
)
923 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 1);
929 scm_ra_sum (ra0
, ras
)
933 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
934 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
935 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
936 ra0
= SCM_ARRAY_V (ra0
);
940 SCM ra1
= SCM_CAR (ras
);
941 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
942 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
943 ra1
= SCM_ARRAY_V (ra1
);
944 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
948 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
949 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
950 scm_array_set_x (ra0
, scm_sum (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
957 long *v0
= SCM_VELTS (ra0
);
958 long *v1
= SCM_VELTS (ra1
);
960 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
968 float *v0
= (float *) SCM_VELTS (ra0
);
969 float *v1
= (float *) SCM_VELTS (ra1
);
971 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
975 #endif /* SCM_SINGLES */
978 double *v0
= (double *) SCM_VELTS (ra0
);
979 double *v1
= (double *) SCM_VELTS (ra1
);
981 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
987 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
988 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
990 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
992 v0
[i0
][0] += v1
[i1
][0];
993 v0
[i0
][1] += v1
[i1
][1];
998 #endif /* SCM_FLOATS */
1007 scm_ra_difference (ra0
, ras
)
1011 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1012 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1013 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1014 ra0
= SCM_ARRAY_V (ra0
);
1023 SCM e0
= SCM_UNDEFINED
;
1024 for (; n
-- > 0; i0
+= inc0
)
1025 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1032 float *v0
= (float *) SCM_VELTS (ra0
);
1033 for (; n
-- > 0; i0
+= inc0
)
1037 #endif /* SCM_SINGLES */
1040 double *v0
= (double *) SCM_VELTS (ra0
);
1041 for (; n
-- > 0; i0
+= inc0
)
1047 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1048 for (; n
-- > 0; i0
+= inc0
)
1050 v0
[i0
][0] = -v0
[i0
][0];
1051 v0
[i0
][1] = -v0
[i0
][1];
1055 #endif /* SCM_FLOATS */
1060 SCM ra1
= SCM_CAR (ras
);
1061 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1062 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1063 ra1
= SCM_ARRAY_V (ra1
);
1064 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1068 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1069 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1070 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1077 float *v0
= (float *) SCM_VELTS (ra0
);
1078 float *v1
= (float *) SCM_VELTS (ra1
);
1080 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1084 #endif /* SCM_SINGLES */
1087 double *v0
= (double *) SCM_VELTS (ra0
);
1088 double *v1
= (double *) SCM_VELTS (ra1
);
1090 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1096 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1097 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1099 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1101 v0
[i0
][0] -= v1
[i1
][0];
1102 v0
[i0
][1] -= v1
[i1
][1];
1107 #endif /* SCM_FLOATS */
1116 scm_ra_product (ra0
, ras
)
1120 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1121 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1122 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1123 ra0
= SCM_ARRAY_V (ra0
);
1127 SCM ra1
= SCM_CAR (ras
);
1128 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1129 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1130 ra1
= SCM_ARRAY_V (ra1
);
1131 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1135 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1136 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1137 scm_array_set_x (ra0
, scm_product (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1144 long *v0
= SCM_VELTS (ra0
);
1145 long *v1
= SCM_VELTS (ra1
);
1147 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1155 float *v0
= (float *) SCM_VELTS (ra0
);
1156 float *v1
= (float *) SCM_VELTS (ra1
);
1158 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1162 #endif /* SCM_SINGLES */
1165 double *v0
= (double *) SCM_VELTS (ra0
);
1166 double *v1
= (double *) SCM_VELTS (ra1
);
1168 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1174 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1176 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1178 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1180 r
= v0
[i0
][0] * v1
[i1
][0] - v0
[i0
][1] * v1
[i1
][1];
1181 v0
[i0
][1] = v0
[i0
][0] * v1
[i1
][1] + v0
[i0
][1] * v1
[i1
][0];
1187 #endif /* SCM_FLOATS */
1195 scm_ra_divide (ra0
, ras
)
1199 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1200 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1201 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1202 ra0
= SCM_ARRAY_V (ra0
);
1211 SCM e0
= SCM_UNDEFINED
;
1212 for (; n
-- > 0; i0
+= inc0
)
1213 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1220 float *v0
= (float *) SCM_VELTS (ra0
);
1221 for (; n
-- > 0; i0
+= inc0
)
1222 v0
[i0
] = 1.0 / v0
[i0
];
1225 #endif /* SCM_SINGLES */
1228 double *v0
= (double *) SCM_VELTS (ra0
);
1229 for (; n
-- > 0; i0
+= inc0
)
1230 v0
[i0
] = 1.0 / v0
[i0
];
1236 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1237 for (; n
-- > 0; i0
+= inc0
)
1239 d
= v0
[i0
][0] * v0
[i0
][0] + v0
[i0
][1] * v0
[i0
][1];
1245 #endif /* SCM_FLOATS */
1250 SCM ra1
= SCM_CAR (ras
);
1251 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1252 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1253 ra1
= SCM_ARRAY_V (ra1
);
1254 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1258 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1259 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1260 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1267 float *v0
= (float *) SCM_VELTS (ra0
);
1268 float *v1
= (float *) SCM_VELTS (ra1
);
1270 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1274 #endif /* SCM_SINGLES */
1277 double *v0
= (double *) SCM_VELTS (ra0
);
1278 double *v1
= (double *) SCM_VELTS (ra1
);
1280 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1286 register double d
, r
;
1287 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1288 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1290 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1292 d
= v1
[i1
][0] * v1
[i1
][0] + v1
[i1
][1] * v1
[i1
][1];
1293 r
= (v0
[i0
][0] * v1
[i1
][0] + v0
[i0
][1] * v1
[i1
][1]) / d
;
1294 v0
[i0
][1] = (v0
[i0
][1] * v1
[i1
][0] - v0
[i0
][0] * v1
[i1
][1]) / d
;
1300 #endif /* SCM_FLOATS */
1308 scm_array_identity (dst
, src
)
1312 return racp (SCM_CAR (src
), scm_cons (dst
, SCM_EOL
));
1317 static int ramap
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1320 ramap (ra0
, proc
, ras
)
1325 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1326 long inc
= SCM_ARRAY_DIMS (ra0
)->inc
;
1327 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1328 long base
= SCM_ARRAY_BASE (ra0
) - i
* inc
;
1329 ra0
= SCM_ARRAY_V (ra0
);
1333 scm_array_set_x (ra0
, scm_apply (proc
, SCM_EOL
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1336 SCM ra1
= SCM_CAR (ras
);
1337 SCM args
, *ve
= &ras
;
1338 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1339 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1340 ra1
= SCM_ARRAY_V (ra1
);
1341 ras
= SCM_CDR (ras
);
1347 ras
= scm_vector (ras
);
1348 ve
= SCM_VELTS (ras
);
1350 for (; i
<= n
; i
++, i1
+= inc1
)
1353 for (k
= SCM_LENGTH (ras
); k
--;)
1354 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1355 args
= scm_cons (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1356 scm_array_set_x (ra0
, scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1363 static int ramap_cxr
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1366 ramap_cxr (ra0
, proc
, ras
)
1371 SCM ra1
= SCM_CAR (ras
);
1372 SCM e1
= SCM_UNDEFINED
;
1373 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1374 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1375 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra1
)->lbnd
+ 1;
1376 ra0
= SCM_ARRAY_V (ra0
);
1377 ra1
= SCM_ARRAY_V (ra1
);
1383 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1384 scm_array_set_x (ra0
, scm_apply (proc
, RVREF (ra1
, i1
, e1
), scm_listofnull
), SCM_MAKINUM (i0
));
1390 float *dst
= (float *) SCM_VELTS (ra0
);
1397 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1398 dst
[i0
] = SCM_DSUBRF (proc
) ((double) ((float *) SCM_VELTS (ra1
))[i1
]);
1402 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1403 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1408 #endif /* SCM_SINGLES */
1411 double *dst
= (double *) SCM_VELTS (ra0
);
1418 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1419 dst
[i0
] = SCM_DSUBRF (proc
) (((double *) SCM_VELTS (ra1
))[i1
]);
1423 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1424 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1429 #endif /* SCM_FLOATS */
1436 static int ramap_rp
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1439 ramap_rp (ra0
, proc
, ras
)
1444 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
1445 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
1446 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1447 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
1448 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1449 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1450 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
1451 ra0
= SCM_ARRAY_V (ra0
);
1452 ra1
= SCM_ARRAY_V (ra1
);
1453 ra2
= SCM_ARRAY_V (ra2
);
1454 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
1457 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1461 (SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)))
1466 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1471 (SCM_SUBRF (proc
) (SCM_MAKINUM (SCM_VELTS (ra1
)[i1
]),
1472 SCM_MAKINUM (SCM_VELTS (ra2
)[i2
])))
1480 SCM a1
= scm_makflo (1.0), a2
= scm_makflo (1.0);
1481 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1485 SCM_FLO (a1
) = ((float *) SCM_VELTS (ra1
))[i1
];
1486 SCM_FLO (a2
) = ((float *) SCM_VELTS (ra2
))[i2
];
1488 (SCM_SUBRF (proc
) (a1
, a2
))
1493 #endif /*SCM_SINGLES*/
1496 SCM a1
= scm_makdbl (1.0 / 3.0, 0.0), a2
= scm_makdbl (1.0 / 3.0, 0.0);
1497 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1501 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[i1
];
1502 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[i2
];
1504 (SCM_SUBRF (proc
) (a1
, a2
))
1511 SCM a1
= scm_makdbl (1.0, 1.0), a2
= scm_makdbl (1.0, 1.0);
1512 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1516 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
];
1517 SCM_IMAG (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1];
1518 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
];
1519 SCM_IMAG (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1];
1521 (SCM_SUBRF (proc
) (a1
, a2
))
1526 #endif /*SCM_FLOATS*/
1533 static int ramap_1
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1536 ramap_1 (ra0
, proc
, ras
)
1541 SCM ra1
= SCM_CAR (ras
);
1542 SCM e1
= SCM_UNDEFINED
;
1543 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1544 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1545 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1546 ra0
= SCM_ARRAY_V (ra0
);
1547 ra1
= SCM_ARRAY_V (ra1
);
1548 if (scm_tc7_vector
== SCM_TYP7 (ra0
))
1549 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1550 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
)), SCM_MAKINUM (i0
));
1552 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1553 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1559 static int ramap_2o
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1562 ramap_2o (ra0
, proc
, ras
)
1567 SCM ra1
= SCM_CAR (ras
);
1568 SCM e1
= SCM_UNDEFINED
;
1569 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1570 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1571 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1572 ra0
= SCM_ARRAY_V (ra0
);
1573 ra1
= SCM_ARRAY_V (ra1
);
1574 ras
= SCM_CDR (ras
);
1578 if (scm_tc7_vector
== SCM_TYP7 (ra0
))
1579 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1580 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), SCM_UNDEFINED
),
1583 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1584 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), SCM_UNDEFINED
),
1589 SCM ra2
= SCM_CAR (ras
);
1590 SCM e2
= SCM_UNDEFINED
;
1591 scm_sizet i2
= SCM_ARRAY_BASE (ra2
);
1592 long inc2
= SCM_ARRAY_DIMS (ra2
)->inc
;
1593 ra2
= SCM_ARRAY_V (ra2
);
1594 if (scm_tc7_vector
== SCM_TYP7 (ra0
))
1595 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1596 scm_array_set_x (ra0
,
1597 SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), scm_cvref (ra2
, i2
, SCM_UNDEFINED
)),
1600 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1601 scm_array_set_x (ra0
,
1602 SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)),
1610 static int ramap_a
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1613 ramap_a (ra0
, proc
, ras
)
1618 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1619 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1620 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1621 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1622 ra0
= SCM_ARRAY_V (ra0
);
1625 for (; n
-- > 0; i0
+= inc0
)
1626 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1629 SCM ra1
= SCM_CAR (ras
);
1630 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1631 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1632 ra1
= SCM_ARRAY_V (ra1
);
1633 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1634 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1640 SCM_PROC(s_serial_array_map
, "serial-array-map", 2, 0, 1, scm_array_map
);
1641 SCM_PROC(s_array_map
, "array-map", 2, 0, 1, scm_array_map
);
1644 scm_array_map (ra0
, proc
, lra
)
1649 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
, s_array_map
);
1650 switch (SCM_TYP7 (proc
))
1654 scm_ramapc (ramap
, proc
, ra0
, lra
, s_array_map
);
1655 return SCM_UNSPECIFIED
;
1656 case scm_tc7_subr_1
:
1657 scm_ramapc (ramap_1
, proc
, ra0
, lra
, s_array_map
);
1658 return SCM_UNSPECIFIED
;
1659 case scm_tc7_subr_2
:
1660 case scm_tc7_subr_2o
:
1661 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map
);
1662 return SCM_UNSPECIFIED
;
1664 if (!SCM_SUBRF (proc
))
1666 scm_ramapc (ramap_cxr
, proc
, ra0
, lra
, s_array_map
);
1667 return SCM_UNSPECIFIED
;
1668 case scm_tc7_rpsubr
:
1671 if (SCM_FALSEP (scm_array_p (ra0
, SCM_BOOL_T
)))
1673 scm_array_fill_x (ra0
, SCM_BOOL_T
);
1674 for (p
= ra_rpsubrs
; p
->name
; p
++)
1675 if (proc
== p
->sproc
)
1677 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1679 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map
);
1680 lra
= SCM_CDR (lra
);
1682 return SCM_UNSPECIFIED
;
1684 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1686 scm_ramapc (ramap_rp
, proc
, ra0
, lra
, s_array_map
);
1687 lra
= SCM_CDR (lra
);
1689 return SCM_UNSPECIFIED
;
1695 SCM prot
, fill
= SCM_SUBRF (proc
) (SCM_UNDEFINED
, SCM_UNDEFINED
);
1699 prot
= scm_array_prototype (ra0
);
1700 if (SCM_NIMP (prot
) && SCM_INEXP (prot
))
1701 fill
= scm_makdbl ((double) SCM_INUM (fill
), 0.0);
1704 scm_array_fill_x (ra0
, fill
);
1708 SCM tail
, ra1
= SCM_CAR (lra
);
1709 SCM v0
= (SCM_NIMP (ra0
) && SCM_ARRAYP (ra0
) ? SCM_ARRAY_V (ra0
) : ra0
);
1711 /* Check to see if order might matter.
1712 This might be an argument for a separate
1713 SERIAL-ARRAY-MAP! */
1714 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1715 if (ra0
!= ra1
|| (SCM_ARRAYP(ra0
) && !SCM_ARRAY_CONTP(ra0
)))
1717 for (tail
= SCM_CDR (lra
); SCM_NNULLP (tail
); tail
= SCM_CDR (tail
))
1719 ra1
= SCM_CAR (tail
);
1720 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1723 for (p
= ra_asubrs
; p
->name
; p
++)
1724 if (proc
== p
->sproc
)
1726 if (ra0
!= SCM_CAR (lra
))
1727 scm_ramapc (scm_array_identity
, SCM_UNDEFINED
, ra0
, scm_cons (SCM_CAR (lra
), SCM_EOL
), s_array_map
);
1728 lra
= SCM_CDR (lra
);
1731 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map
);
1732 if (SCM_IMP (lra
) || SCM_IMP (SCM_CDR (lra
)))
1733 return SCM_UNSPECIFIED
;
1734 lra
= SCM_CDR (lra
);
1737 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map
);
1738 lra
= SCM_CDR (lra
);
1741 for (lra
= SCM_CDR (lra
); SCM_NIMP (lra
); lra
= SCM_CDR (lra
))
1742 scm_ramapc (ramap_a
, proc
, ra0
, lra
, s_array_map
);
1744 return SCM_UNSPECIFIED
;
1749 static int rafe
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1752 rafe (ra0
, proc
, ras
)
1757 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1758 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1759 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1760 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1761 ra0
= SCM_ARRAY_V (ra0
);
1764 for (; i
<= n
; i
++, i0
+= inc0
)
1765 scm_apply (proc
, scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_listofnull
);
1768 SCM ra1
= SCM_CAR (ras
);
1769 SCM args
, *ve
= &ras
;
1770 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1771 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1772 ra1
= SCM_ARRAY_V (ra1
);
1773 ras
= SCM_CDR (ras
);
1779 ras
= scm_vector (ras
);
1780 ve
= SCM_VELTS (ras
);
1782 for (; i
<= n
; i
++, i0
+= inc0
, i1
+= inc1
)
1785 for (k
= SCM_LENGTH (ras
); k
--;)
1786 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1787 args
= scm_cons2 (scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1788 scm_apply (proc
, args
, SCM_EOL
);
1795 SCM_PROC(s_array_for_each
, "array-for-each", 2, 0, 1, scm_array_for_each
);
1798 scm_array_for_each (proc
, ra0
, lra
)
1803 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG1
, s_array_for_each
);
1804 scm_ramapc (rafe
, proc
, ra0
, lra
, s_array_for_each
);
1805 return SCM_UNSPECIFIED
;
1808 SCM_PROC(s_array_index_map_x
, "array-index-map!", 2, 0, 0, scm_array_index_map_x
);
1811 scm_array_index_map_x (ra
, proc
)
1816 SCM_ASSERT (SCM_NIMP (ra
), ra
, SCM_ARG1
, s_array_index_map_x
);
1817 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
, s_array_index_map_x
);
1822 badarg
:scm_wta (ra
, (char *) SCM_ARG1
, s_array_index_map_x
);
1823 case scm_tc7_vector
:
1825 SCM
*ve
= SCM_VELTS (ra
);
1826 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1827 ve
[i
] = scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
);
1828 return SCM_UNSPECIFIED
;
1830 case scm_tc7_string
:
1831 case scm_tc7_byvect
:
1838 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1839 scm_array_set_x (ra
, scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
), SCM_MAKINUM (i
));
1840 return SCM_UNSPECIFIED
;
1842 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
1845 SCM inds
= scm_make_uve (SCM_ARRAY_NDIM (ra
), SCM_MAKINUM (-1L));
1846 long *vinds
= SCM_VELTS (inds
);
1847 int j
, k
, kmax
= SCM_ARRAY_NDIM (ra
) - 1;
1848 for (k
= 0; k
<= kmax
; k
++)
1849 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1855 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1856 i
= cind (ra
, inds
);
1857 for (; vinds
[k
] <= SCM_ARRAY_DIMS (ra
)[k
].ubnd
; vinds
[k
]++)
1859 for (j
= kmax
+ 1, args
= SCM_EOL
; j
--;)
1860 args
= scm_cons (SCM_MAKINUM (vinds
[j
]), args
);
1861 scm_array_set_x (SCM_ARRAY_V (ra
), scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
));
1862 i
+= SCM_ARRAY_DIMS (ra
)[k
].inc
;
1867 if (vinds
[k
] < SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
1873 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
- 1;
1877 return SCM_UNSPECIFIED
;
1883 static int raeql_1
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
1886 raeql_1 (ra0
, as_equal
, ra1
)
1891 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1892 scm_sizet i0
= 0, i1
= 0;
1893 long inc0
= 1, inc1
= 1;
1894 scm_sizet n
= SCM_LENGTH (ra0
);
1895 ra1
= SCM_CAR (ra1
);
1899 n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1900 i0
= SCM_ARRAY_BASE (ra0
);
1901 inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1902 ra0
= SCM_ARRAY_V (ra0
);
1907 i1
= SCM_ARRAY_BASE (ra1
);
1908 inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1909 ra1
= SCM_ARRAY_V (ra1
);
1914 case scm_tc7_vector
:
1916 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1922 (scm_array_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)))
1926 (scm_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)))
1930 case scm_tc7_string
:
1931 case scm_tc7_byvect
:
1933 char *v0
= SCM_CHARS (ra0
) + i0
;
1934 char *v1
= SCM_CHARS (ra1
) + i1
;
1935 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1941 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1942 if (BVE_REF (ra0
, i0
) != BVE_REF (ra1
, i1
))
1948 long *v0
= (long *) SCM_VELTS (ra0
) + i0
;
1949 long *v1
= (long *) SCM_VELTS (ra1
) + i1
;
1950 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1959 float *v0
= (float *) SCM_VELTS (ra0
) + i0
;
1960 float *v1
= (float *) SCM_VELTS (ra1
) + i1
;
1961 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1966 #endif /* SCM_SINGLES */
1969 double *v0
= (double *) SCM_VELTS (ra0
) + i0
;
1970 double *v1
= (double *) SCM_VELTS (ra1
) + i1
;
1971 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1978 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
) + i0
;
1979 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
) + i1
;
1980 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1982 if ((*v0
)[0] != (*v1
)[0])
1984 if ((*v0
)[1] != (*v1
)[1])
1989 #endif /* SCM_FLOATS */
1995 static int raeql
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
1998 raeql (ra0
, as_equal
, ra1
)
2003 SCM v0
= ra0
, v1
= ra1
;
2004 scm_array_dim dim0
, dim1
;
2005 scm_array_dim
*s0
= &dim0
, *s1
= &dim1
;
2006 scm_sizet bas0
= 0, bas1
= 0;
2007 int k
, unroll
= 1, vlen
= 1, ndim
= 1;
2011 ndim
= SCM_ARRAY_NDIM (ra0
);
2012 s0
= SCM_ARRAY_DIMS (ra0
);
2013 bas0
= SCM_ARRAY_BASE (ra0
);
2014 v0
= SCM_ARRAY_V (ra0
);
2020 s0
->ubnd
= SCM_LENGTH (v0
) - 1;
2026 if (ndim
!= SCM_ARRAY_NDIM (ra1
))
2028 s1
= SCM_ARRAY_DIMS (ra1
);
2029 bas1
= SCM_ARRAY_BASE (ra1
);
2030 v1
= SCM_ARRAY_V (ra1
);
2038 s1
->ubnd
= SCM_LENGTH (v1
) - 1;
2041 if (SCM_TYP7 (v0
) != SCM_TYP7 (v1
))
2043 for (k
= ndim
; k
--;)
2045 if (s0
[k
].lbnd
!= s1
[k
].lbnd
|| s0
[k
].ubnd
!= s1
[k
].ubnd
)
2049 unroll
= (s0
[k
].inc
== s1
[k
].inc
);
2050 vlen
*= s0
[k
].ubnd
- s1
[k
].lbnd
+ 1;
2053 if (unroll
&& bas0
== bas1
&& v0
== v1
)
2055 return scm_ramapc (raeql_1
, as_equal
, ra0
, scm_cons (ra1
, SCM_EOL
), "");
2060 scm_raequal (ra0
, ra1
)
2064 return (raeql (ra0
, SCM_BOOL_T
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2067 static char s_array_equal_p
[] = "array-equal?";
2071 scm_array_equal_p (ra0
, ra1
)
2075 if (SCM_IMP (ra0
) || SCM_IMP (ra1
))
2076 callequal
:return scm_equal_p (ra0
, ra1
);
2083 case scm_tc7_string
:
2084 case scm_tc7_byvect
:
2090 case scm_tc7_vector
:
2093 if (!SCM_ARRAYP (ra0
))
2102 case scm_tc7_string
:
2103 case scm_tc7_byvect
:
2109 case scm_tc7_vector
:
2112 if (!SCM_ARRAYP (ra1
))
2115 return (raeql (ra0
, SCM_BOOL_F
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2121 init_raprocs (subra
)
2124 for (; subra
->name
; subra
++)
2125 subra
->sproc
= SCM_CDR (scm_intern (subra
->name
, strlen (subra
->name
)));
2132 init_raprocs (ra_rpsubrs
);
2133 init_raprocs (ra_asubrs
);
2134 scm_make_subr (s_array_equal_p
, scm_tc7_rpsubr
, scm_array_equal_p
);
2135 scm_smobs
[0x0ff & (scm_tc16_array
>> 8)].equalp
= scm_raequal
;
2137 scm_add_feature (s_array_for_each
);