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?) */
155 if (SCM_IMP (ra0
)) return 0;
156 switch (SCM_TYP7 (ra0
))
168 #ifdef HAVE_LONG_LONGS
176 s0
->ubnd
= (long) SCM_LENGTH (ra0
) - 1;
179 if (!SCM_ARRAYP (ra0
))
181 ndim
= SCM_ARRAY_NDIM (ra0
);
182 s0
= SCM_ARRAY_DIMS (ra0
);
183 bas0
= SCM_ARRAY_BASE (ra0
);
205 #ifdef HAVE_LONG_LONGS
222 if ((0 == s0
->lbnd
) && (s0
->ubnd
== SCM_LENGTH (ra1
) - 1))
226 if (s0
->lbnd
< 0 || s0
->ubnd
>= SCM_LENGTH (ra1
))
231 if (!SCM_ARRAYP (ra1
) || ndim
!= SCM_ARRAY_NDIM (ra1
))
233 s1
= SCM_ARRAY_DIMS (ra1
);
234 if (bas0
!= SCM_ARRAY_BASE (ra1
))
236 for (i
= 0; i
< ndim
; i
++)
241 if (s0
[i
].inc
!= s1
[i
].inc
)
244 if (s0
[i
].lbnd
== s1
[i
].lbnd
&& s0
[i
].ubnd
== s1
[i
].ubnd
)
248 if (s0
[i
].lbnd
< s1
[i
].lbnd
|| s0
[i
].ubnd
> s1
[i
].ubnd
)
249 return (s0
[i
].lbnd
<= s0
[i
].ubnd
? 0 : 1);
258 /* array mapper: apply cproc to each dimension of the given arrays. */
260 scm_ramapc (cproc
, data
, ra0
, lra
, what
)
261 int (*cproc
) (); /* procedure to call on normalised arrays:
262 cproc (dest, source list) or
263 cproc (dest, data, source list). */
264 SCM data
; /* data to give to cproc or unbound. */
265 SCM ra0
; /* destination array. */
266 SCM lra
; /* list of source arrays. */
267 const char *what
; /* caller, for error reporting. */
274 switch (scm_ra_matchp (ra0
, lra
))
278 scm_wta (ra0
, "array shape 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
);
286 if (SCM_IMP (vra0
)) goto gencase
;
287 if (!SCM_ARRAYP (vra0
))
289 vra1
= scm_make_ra (1);
290 SCM_ARRAY_BASE (vra1
) = 0;
291 SCM_ARRAY_DIMS (vra1
)->lbnd
= 0;
292 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_LENGTH (vra0
) - 1;
293 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
294 SCM_ARRAY_V (vra1
) = vra0
;
299 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
302 vra1
= scm_make_ra (1);
303 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
304 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
305 if (!SCM_ARRAYP (ra1
))
307 SCM_ARRAY_BASE (vra1
) = 0;
308 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
309 SCM_ARRAY_V (vra1
) = ra1
;
311 else if (!SCM_ARRAY_CONTP (ra1
))
315 SCM_ARRAY_BASE (vra1
) = SCM_ARRAY_BASE (ra1
);
316 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
317 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
319 *plvra
= scm_cons (vra1
, SCM_EOL
);
320 plvra
= SCM_CDRLOC (*plvra
);
322 return (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
));
324 gencase
: /* Have to loop over all dimensions. */
325 vra0
= scm_make_ra (1);
326 if (SCM_ARRAYP (ra0
))
328 kmax
= SCM_ARRAY_NDIM (ra0
) - 1;
331 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
332 SCM_ARRAY_DIMS (vra0
)->ubnd
= 0;
333 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
337 SCM_ARRAY_DIMS (vra0
)->lbnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].lbnd
;
338 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].ubnd
;
339 SCM_ARRAY_DIMS (vra0
)->inc
= SCM_ARRAY_DIMS (ra0
)[kmax
].inc
;
341 SCM_ARRAY_BASE (vra0
) = SCM_ARRAY_BASE (ra0
);
342 SCM_ARRAY_V (vra0
) = SCM_ARRAY_V (ra0
);
347 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
348 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_LENGTH (ra0
) - 1;
349 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
350 SCM_ARRAY_BASE (vra0
) = 0;
351 SCM_ARRAY_V (vra0
) = ra0
;
356 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
359 vra1
= scm_make_ra (1);
360 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
361 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
362 if (SCM_ARRAYP (ra1
))
365 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
366 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
370 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
371 SCM_ARRAY_V (vra1
) = ra1
;
373 *plvra
= scm_cons (vra1
, SCM_EOL
);
374 plvra
= SCM_CDRLOC (*plvra
);
376 inds
= scm_make_uve (SCM_ARRAY_NDIM (ra0
), SCM_MAKINUM (-1L));
377 vinds
= (long *) SCM_VELTS (inds
);
378 for (k
= 0; k
<= kmax
; k
++)
379 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
;
386 SCM_ARRAY_BASE (vra0
) = cind (ra0
, inds
);
387 for (z
= lvra
; SCM_NIMP (z
); z
= SCM_CDR (z
), y
= SCM_CDR (y
))
388 SCM_ARRAY_BASE (SCM_CAR (z
)) = cind (SCM_CAR (y
), inds
);
389 if (0 == (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
)))
394 if (vinds
[k
] < SCM_ARRAY_DIMS (ra0
)[k
].ubnd
)
400 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
- 1;
409 SCM_PROC(s_array_fill_x
, "array-fill!", 2, 0, 0, scm_array_fill_x
);
412 scm_array_fill_x (ra
, fill
)
416 scm_ramapc (scm_array_fill_int
, fill
, ra
, SCM_EOL
, s_array_fill_x
);
417 return SCM_UNSPECIFIED
;
420 /* to be used as cproc in scm_ramapc to fill an array dimension with
423 scm_array_fill_int (ra
, fill
, ignore
)
429 scm_sizet n
= SCM_ARRAY_DIMS (ra
)->ubnd
- SCM_ARRAY_DIMS (ra
)->lbnd
+ 1;
430 long inc
= SCM_ARRAY_DIMS (ra
)->inc
;
431 scm_sizet base
= SCM_ARRAY_BASE (ra
);
433 ra
= SCM_ARRAY_V (ra
);
437 for (i
= base
; n
--; i
+= inc
)
438 scm_array_set_x (ra
, fill
, SCM_MAKINUM (i
));
442 for (i
= base
; n
--; i
+= inc
)
443 SCM_VELTS (ra
)[i
] = fill
;
446 SCM_ASRTGO (SCM_ICHRP (fill
), badarg2
);
447 for (i
= base
; n
--; i
+= inc
)
448 SCM_CHARS (ra
)[i
] = SCM_ICHR (fill
);
451 if (SCM_ICHRP (fill
))
452 fill
= SCM_MAKINUM ((char) SCM_ICHR (fill
));
453 SCM_ASRTGO (SCM_INUMP (fill
)
454 && -128 <= SCM_INUM (fill
) && SCM_INUM (fill
) < 128,
456 for (i
= base
; n
--; i
+= inc
)
457 SCM_CHARS (ra
)[i
] = SCM_INUM (fill
);
461 long *ve
= (long *) SCM_VELTS (ra
);
462 if (1 == inc
&& (n
>= SCM_LONG_BIT
|| n
== SCM_LENGTH (ra
)))
464 i
= base
/ SCM_LONG_BIT
;
465 if (SCM_BOOL_F
== fill
)
467 if (base
% SCM_LONG_BIT
) /* leading partial word */
468 ve
[i
++] &= ~(~0L << (base
% SCM_LONG_BIT
));
469 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
471 if ((base
+ n
) % SCM_LONG_BIT
) /* trailing partial word */
472 ve
[i
] &= (~0L << ((base
+ n
) % SCM_LONG_BIT
));
474 else if (SCM_BOOL_T
== fill
)
476 if (base
% SCM_LONG_BIT
)
477 ve
[i
++] |= ~0L << (base
% SCM_LONG_BIT
);
478 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
480 if ((base
+ n
) % SCM_LONG_BIT
)
481 ve
[i
] |= ~(~0L << ((base
+ n
) % SCM_LONG_BIT
));
484 badarg2
:scm_wta (fill
, (char *) SCM_ARG2
, s_array_fill_x
);
488 if (SCM_BOOL_F
== fill
)
489 for (i
= base
; n
--; i
+= inc
)
490 ve
[i
/ SCM_LONG_BIT
] &= ~(1L << (i
% SCM_LONG_BIT
));
491 else if (SCM_BOOL_T
== fill
)
492 for (i
= base
; n
--; i
+= inc
)
493 ve
[i
/ SCM_LONG_BIT
] |= (1L << (i
% SCM_LONG_BIT
));
501 unsigned long f
= scm_num2ulong (fill
, (char *) SCM_ARG2
,
503 unsigned long *ve
= (long *) SCM_VELTS (ra
);
505 for (i
= base
; n
--; i
+= inc
)
511 long f
= scm_num2long (fill
, (char *) SCM_ARG2
, s_array_fill_x
);
512 long *ve
= (long *) SCM_VELTS (ra
);
514 for (i
= base
; n
--; i
+= inc
)
519 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
521 short f
= SCM_INUM (fill
);
522 short *ve
= (short *) SCM_VELTS (ra
);
524 if (f
!= SCM_INUM (fill
))
525 scm_out_of_range (s_array_fill_x
, fill
);
526 for (i
= base
; n
--; i
+= inc
)
530 #ifdef HAVE_LONG_LONGS
533 long long f
= scm_num2long_long (fill
, (char *) SCM_ARG2
,
535 long long *ve
= (long long *) SCM_VELTS (ra
);
537 for (i
= base
; n
--; i
+= inc
)
546 float f
, *ve
= (float *) SCM_VELTS (ra
);
547 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
548 f
= SCM_REALPART (fill
);
549 for (i
= base
; n
--; i
+= inc
)
553 #endif /* SCM_SINGLES */
556 double f
, *ve
= (double *) SCM_VELTS (ra
);
557 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
558 f
= SCM_REALPART (fill
);
559 for (i
= base
; n
--; i
+= inc
)
566 double (*ve
)[2] = (double (*)[2]) SCM_VELTS (ra
);
567 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_INEXP (fill
), badarg2
);
568 fr
= SCM_REALPART (fill
);
569 fi
= (SCM_CPLXP (fill
) ? SCM_IMAG (fill
) : 0.0);
570 for (i
= base
; n
--; i
+= inc
)
577 #endif /* SCM_FLOATS */
585 static int racp
SCM_P ((SCM dst
, SCM src
));
592 long n
= (SCM_ARRAY_DIMS (src
)->ubnd
- SCM_ARRAY_DIMS (src
)->lbnd
+ 1);
593 long inc_d
, inc_s
= SCM_ARRAY_DIMS (src
)->inc
;
594 scm_sizet i_d
, i_s
= SCM_ARRAY_BASE (src
);
596 inc_d
= SCM_ARRAY_DIMS (dst
)->inc
;
597 i_d
= SCM_ARRAY_BASE (dst
);
598 src
= SCM_ARRAY_V (src
);
599 dst
= SCM_ARRAY_V (dst
);
608 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
609 scm_array_set_x (dst
, scm_cvref (src
, i_s
, SCM_UNDEFINED
), SCM_MAKINUM (i_d
));
613 if (scm_tc7_string
!= SCM_TYP7 (dst
))
615 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
616 SCM_CHARS (dst
)[i_d
] = SCM_CHARS (src
)[i_s
];
619 if (scm_tc7_bvect
!= SCM_TYP7 (dst
))
621 if (1 == inc_d
&& 1 == inc_s
&& i_s
% SCM_LONG_BIT
== i_d
% SCM_LONG_BIT
&& n
>= SCM_LONG_BIT
)
623 long *sv
= (long *) SCM_VELTS (src
);
624 long *dv
= (long *) SCM_VELTS (dst
);
625 sv
+= i_s
/ SCM_LONG_BIT
;
626 dv
+= i_d
/ SCM_LONG_BIT
;
627 if (i_s
% SCM_LONG_BIT
)
628 { /* leading partial word */
629 *dv
= (*dv
& ~(~0L << (i_s
% SCM_LONG_BIT
))) | (*sv
& (~0L << (i_s
% SCM_LONG_BIT
)));
632 n
-= SCM_LONG_BIT
- (i_s
% SCM_LONG_BIT
);
635 for (; n
>= SCM_LONG_BIT
; n
-= SCM_LONG_BIT
, sv
++, dv
++)
637 if (n
) /* trailing partial word */
638 *dv
= (*dv
& (~0L << n
)) | (*sv
& ~(~0L << n
));
642 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
643 if (SCM_VELTS (src
)[i_s
/ SCM_LONG_BIT
] & (1L << (i_s
% SCM_LONG_BIT
)))
644 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] |= (1L << (i_d
% SCM_LONG_BIT
));
646 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] &= ~(1L << (i_d
% SCM_LONG_BIT
));
650 if (scm_tc7_uvect
!= SCM_TYP7 (src
))
654 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
656 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
661 if (scm_tc7_uvect
!= SCM_TYP7 (src
) && scm_tc7_ivect
!= SCM_TYP7 (src
))
665 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
667 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
675 float *d
= (float *) SCM_VELTS (dst
);
676 float *s
= (float *) SCM_VELTS (src
);
685 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
686 d
[i_d
] = ((long *) s
)[i_s
];)
690 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
695 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
696 d
[i_d
] = ((double *) s
)[i_s
];)
701 #endif /* SCM_SINGLES */
704 double *d
= (double *) SCM_VELTS (dst
);
705 double *s
= (double *) SCM_VELTS (src
);
714 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
715 d
[i_d
] = ((long *) s
)[i_s
];)
719 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
720 d
[i_d
] = ((float *) s
)[i_s
];)
724 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
732 double (*d
)[2] = (double (*)[2]) SCM_VELTS (dst
);
733 double (*s
)[2] = (double (*)[2]) SCM_VELTS (src
);
742 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
744 d
[i_d
][0] = ((long *) s
)[i_s
];
751 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
753 d
[i_d
][0] = ((float *) s
)[i_s
];
760 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
762 d
[i_d
][0] = ((double *) s
)[i_s
];
769 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
771 d
[i_d
][0] = s
[i_s
][0];
772 d
[i_d
][1] = s
[i_s
][1];
779 #endif /* SCM_FLOATS */
784 /* This name is obsolete. Will go away in release 1.5. */
785 SCM_PROC(s_serial_array_copy_x
, "serial-array-copy!", 2, 0, 0, scm_array_copy_x
);
786 SCM_PROC(s_array_copy_in_order_x
, "array-copy-in-order!", 2, 0, 0, scm_array_copy_x
);
787 SCM_PROC(s_array_copy_x
, "array-copy!", 2, 0, 0, scm_array_copy_x
);
790 scm_array_copy_x (src
, dst
)
794 scm_ramapc (racp
, SCM_UNDEFINED
, src
, scm_cons (dst
, SCM_EOL
), s_array_copy_x
);
795 return SCM_UNSPECIFIED
;
798 /* Functions callable by ARRAY-MAP! */
802 scm_ra_eqp (ra0
, ras
)
806 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
807 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
808 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
809 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
810 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
811 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
812 ra0
= SCM_ARRAY_V (ra0
);
813 ra1
= SCM_ARRAY_V (ra1
);
814 ra2
= SCM_ARRAY_V (ra2
);
815 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
819 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
820 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
821 if (BVE_REF (ra0
, i0
))
822 if (SCM_FALSEP(scm_eq_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
828 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
829 if (BVE_REF (ra0
, i0
))
830 if (SCM_VELTS (ra1
)[i1
] != SCM_VELTS (ra2
)[i2
])
836 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
837 if (BVE_REF (ra0
, i0
))
838 if (((float *) SCM_VELTS (ra1
))[i1
] != ((float *) SCM_VELTS (ra2
))[i2
])
841 #endif /*SCM_SINGLES*/
843 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
844 if (BVE_REF (ra0
, i0
))
845 if (((double *) SCM_VELTS (ra1
))[i1
] != ((double *) SCM_VELTS (ra2
))[i2
])
849 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
850 if (BVE_REF (ra0
, i0
))
851 if (((double *) SCM_VELTS (ra1
))[2 * i1
] != ((double *) SCM_VELTS (ra2
))[2 * i2
] ||
852 ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1] != ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1])
855 #endif /*SCM_FLOATS*/
860 /* opt 0 means <, nonzero means >= */
862 static int ra_compare
SCM_P ((SCM ra0
, SCM ra1
, SCM ra2
, int opt
));
865 ra_compare (ra0
, ra1
, ra2
, opt
)
871 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
872 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
873 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
874 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
875 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
876 ra0
= SCM_ARRAY_V (ra0
);
877 ra1
= SCM_ARRAY_V (ra1
);
878 ra2
= SCM_ARRAY_V (ra2
);
879 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
883 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
884 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
885 if (BVE_REF (ra0
, i0
))
887 SCM_NFALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))) :
888 SCM_FALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
894 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
896 if (BVE_REF (ra0
, i0
))
898 SCM_VELTS (ra1
)[i1
] < SCM_VELTS (ra2
)[i2
] :
899 SCM_VELTS (ra1
)[i1
] >= SCM_VELTS (ra2
)[i2
])
906 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
907 if (BVE_REF(ra0
, i0
))
909 ((float *) SCM_VELTS (ra1
))[i1
] < ((float *) SCM_VELTS (ra2
))[i2
] :
910 ((float *) SCM_VELTS (ra1
))[i1
] >= ((float *) SCM_VELTS (ra2
))[i2
])
913 #endif /*SCM_SINGLES*/
915 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
916 if (BVE_REF (ra0
, i0
))
918 ((double *) SCM_VELTS (ra1
))[i1
] < ((double *) SCM_VELTS (ra2
))[i2
] :
919 ((double *) SCM_VELTS (ra1
))[i1
] >= ((double *) SCM_VELTS (ra2
))[i2
])
922 #endif /*SCM_FLOATS*/
930 scm_ra_lessp (ra0
, ras
)
934 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 0);
939 scm_ra_leqp (ra0
, ras
)
943 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 1);
948 scm_ra_grp (ra0
, ras
)
952 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 0);
957 scm_ra_greqp (ra0
, ras
)
961 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 1);
967 scm_ra_sum (ra0
, ras
)
971 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
972 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
973 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
974 ra0
= SCM_ARRAY_V (ra0
);
977 SCM ra1
= SCM_CAR (ras
);
978 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
979 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
980 ra1
= SCM_ARRAY_V (ra1
);
981 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
985 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
986 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
987 scm_array_set_x (ra0
, scm_sum (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
994 long *v0
= SCM_VELTS (ra0
);
995 long *v1
= SCM_VELTS (ra1
);
997 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1005 float *v0
= (float *) SCM_VELTS (ra0
);
1006 float *v1
= (float *) SCM_VELTS (ra1
);
1008 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1012 #endif /* SCM_SINGLES */
1015 double *v0
= (double *) SCM_VELTS (ra0
);
1016 double *v1
= (double *) SCM_VELTS (ra1
);
1018 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1024 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1025 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1027 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1029 v0
[i0
][0] += v1
[i1
][0];
1030 v0
[i0
][1] += v1
[i1
][1];
1035 #endif /* SCM_FLOATS */
1044 scm_ra_difference (ra0
, ras
)
1048 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1049 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1050 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1051 ra0
= SCM_ARRAY_V (ra0
);
1052 if (SCM_NULLP (ras
))
1054 switch (SCM_TYP7 (ra0
))
1058 SCM e0
= SCM_UNDEFINED
;
1059 for (; n
-- > 0; i0
+= inc0
)
1060 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1067 float *v0
= (float *) SCM_VELTS (ra0
);
1068 for (; n
-- > 0; i0
+= inc0
)
1072 #endif /* SCM_SINGLES */
1075 double *v0
= (double *) SCM_VELTS (ra0
);
1076 for (; n
-- > 0; i0
+= inc0
)
1082 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1083 for (; n
-- > 0; i0
+= inc0
)
1085 v0
[i0
][0] = -v0
[i0
][0];
1086 v0
[i0
][1] = -v0
[i0
][1];
1090 #endif /* SCM_FLOATS */
1095 SCM ra1
= SCM_CAR (ras
);
1096 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1097 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1098 ra1
= SCM_ARRAY_V (ra1
);
1099 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1103 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1104 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1105 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1112 float *v0
= (float *) SCM_VELTS (ra0
);
1113 float *v1
= (float *) SCM_VELTS (ra1
);
1115 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1119 #endif /* SCM_SINGLES */
1122 double *v0
= (double *) SCM_VELTS (ra0
);
1123 double *v1
= (double *) SCM_VELTS (ra1
);
1125 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1131 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1132 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1134 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1136 v0
[i0
][0] -= v1
[i1
][0];
1137 v0
[i0
][1] -= v1
[i1
][1];
1142 #endif /* SCM_FLOATS */
1151 scm_ra_product (ra0
, ras
)
1155 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1156 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1157 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1158 ra0
= SCM_ARRAY_V (ra0
);
1159 if (SCM_NNULLP (ras
))
1161 SCM ra1
= SCM_CAR (ras
);
1162 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1163 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1164 ra1
= SCM_ARRAY_V (ra1
);
1165 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1169 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1170 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1171 scm_array_set_x (ra0
, scm_product (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1178 long *v0
= SCM_VELTS (ra0
);
1179 long *v1
= SCM_VELTS (ra1
);
1181 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1189 float *v0
= (float *) SCM_VELTS (ra0
);
1190 float *v1
= (float *) SCM_VELTS (ra1
);
1192 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1196 #endif /* SCM_SINGLES */
1199 double *v0
= (double *) SCM_VELTS (ra0
);
1200 double *v1
= (double *) SCM_VELTS (ra1
);
1202 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1208 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1210 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1212 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1214 r
= v0
[i0
][0] * v1
[i1
][0] - v0
[i0
][1] * v1
[i1
][1];
1215 v0
[i0
][1] = v0
[i0
][0] * v1
[i1
][1] + v0
[i0
][1] * v1
[i1
][0];
1221 #endif /* SCM_FLOATS */
1229 scm_ra_divide (ra0
, ras
)
1233 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1234 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1235 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1236 ra0
= SCM_ARRAY_V (ra0
);
1237 if (SCM_NULLP (ras
))
1239 switch (SCM_TYP7 (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
);
1362 if (SCM_NULLP (ras
))
1364 scm_array_set_x (ra0
, scm_apply (proc
, SCM_EOL
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1367 SCM ra1
= SCM_CAR (ras
);
1368 SCM args
, *ve
= &ras
;
1369 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1370 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1371 ra1
= SCM_ARRAY_V (ra1
);
1372 ras
= SCM_CDR (ras
);
1377 ras
= scm_vector (ras
);
1378 ve
= SCM_VELTS (ras
);
1380 for (; i
<= n
; i
++, i1
+= inc1
)
1383 for (k
= SCM_LENGTH (ras
); k
--;)
1384 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1385 args
= scm_cons (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1386 scm_array_set_x (ra0
, scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1393 static int ramap_cxr
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1396 ramap_cxr (ra0
, proc
, ras
)
1401 SCM ra1
= SCM_CAR (ras
);
1402 SCM e1
= SCM_UNDEFINED
;
1403 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1404 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1405 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra1
)->lbnd
+ 1;
1406 ra0
= SCM_ARRAY_V (ra0
);
1407 ra1
= SCM_ARRAY_V (ra1
);
1408 switch (SCM_TYP7 (ra0
))
1412 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1413 scm_array_set_x (ra0
, scm_apply (proc
, RVREF (ra1
, i1
, e1
), scm_listofnull
), SCM_MAKINUM (i0
));
1419 float *dst
= (float *) SCM_VELTS (ra0
);
1420 switch (SCM_TYP7 (ra1
))
1425 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1426 dst
[i0
] = SCM_DSUBRF (proc
) ((double) ((float *) SCM_VELTS (ra1
))[i1
]);
1430 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1431 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1436 #endif /* SCM_SINGLES */
1439 double *dst
= (double *) SCM_VELTS (ra0
);
1440 switch (SCM_TYP7 (ra1
))
1445 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1446 dst
[i0
] = SCM_DSUBRF (proc
) (((double *) SCM_VELTS (ra1
))[i1
]);
1450 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1451 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1456 #endif /* SCM_FLOATS */
1463 static int ramap_rp
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1466 ramap_rp (ra0
, proc
, ras
)
1471 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
1472 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
1473 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1474 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
1475 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1476 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1477 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
1478 ra0
= SCM_ARRAY_V (ra0
);
1479 ra1
= SCM_ARRAY_V (ra1
);
1480 ra2
= SCM_ARRAY_V (ra2
);
1481 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
1484 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1485 if (BVE_REF (ra0
, i0
))
1486 if (SCM_FALSEP (SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
1491 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1492 if (BVE_REF (ra0
, i0
))
1494 if (SCM_FALSEP (SCM_SUBRF (proc
) (SCM_MAKINUM (SCM_VELTS (ra1
)[i1
]),
1495 SCM_MAKINUM (SCM_VELTS (ra2
)[i2
]))))
1503 SCM a1
= scm_makflo (1.0), a2
= scm_makflo (1.0);
1504 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1505 if (BVE_REF (ra0
, i0
))
1507 SCM_FLO (a1
) = ((float *) SCM_VELTS (ra1
))[i1
];
1508 SCM_FLO (a2
) = ((float *) SCM_VELTS (ra2
))[i2
];
1509 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1514 #endif /*SCM_SINGLES*/
1517 SCM a1
= scm_makdbl (1.0 / 3.0, 0.0), a2
= scm_makdbl (1.0 / 3.0, 0.0);
1518 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1519 if (BVE_REF (ra0
, i0
))
1521 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[i1
];
1522 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[i2
];
1523 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1530 SCM a1
= scm_makdbl (1.0, 1.0), a2
= scm_makdbl (1.0, 1.0);
1531 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1532 if (BVE_REF (ra0
, i0
))
1534 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
];
1535 SCM_IMAG (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1];
1536 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
];
1537 SCM_IMAG (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1];
1538 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1543 #endif /*SCM_FLOATS*/
1550 static int ramap_1
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1553 ramap_1 (ra0
, proc
, ras
)
1558 SCM ra1
= SCM_CAR (ras
);
1559 SCM e1
= SCM_UNDEFINED
;
1560 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1561 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1562 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1563 ra0
= SCM_ARRAY_V (ra0
);
1564 ra1
= SCM_ARRAY_V (ra1
);
1565 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1566 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1567 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
)), SCM_MAKINUM (i0
));
1569 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1570 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1576 static int ramap_2o
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1579 ramap_2o (ra0
, proc
, ras
)
1584 SCM ra1
= SCM_CAR (ras
);
1585 SCM e1
= SCM_UNDEFINED
;
1586 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1587 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1588 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1589 ra0
= SCM_ARRAY_V (ra0
);
1590 ra1
= SCM_ARRAY_V (ra1
);
1591 ras
= SCM_CDR (ras
);
1592 if (SCM_NULLP (ras
))
1594 if (scm_tc7_vector
== SCM_TYP7 (ra0
)
1595 || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1597 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1598 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), SCM_UNDEFINED
),
1601 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1602 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), SCM_UNDEFINED
),
1607 SCM ra2
= SCM_CAR (ras
);
1608 SCM e2
= SCM_UNDEFINED
;
1609 scm_sizet i2
= SCM_ARRAY_BASE (ra2
);
1610 long inc2
= SCM_ARRAY_DIMS (ra2
)->inc
;
1611 ra2
= SCM_ARRAY_V (ra2
);
1612 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1613 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1614 scm_array_set_x (ra0
,
1615 SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), scm_cvref (ra2
, i2
, SCM_UNDEFINED
)),
1618 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1619 scm_array_set_x (ra0
,
1620 SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)),
1628 static int ramap_a
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1631 ramap_a (ra0
, proc
, ras
)
1636 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1637 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1638 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1639 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1640 ra0
= SCM_ARRAY_V (ra0
);
1641 if (SCM_NULLP (ras
))
1642 for (; n
-- > 0; i0
+= inc0
)
1643 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1646 SCM ra1
= SCM_CAR (ras
);
1647 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1648 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1649 ra1
= SCM_ARRAY_V (ra1
);
1650 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1651 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1657 /* This name is obsolete. Will go away in release 1.5. */
1658 SCM_PROC(s_serial_array_map_x
, "serial-array-map!", 2, 0, 1, scm_array_map_x
);
1659 SCM_PROC(s_array_map_in_order_x
, "array-map-in-order!", 2, 0, 1, scm_array_map_x
);
1660 SCM_PROC(s_array_map_x
, "array-map!", 2, 0, 1, scm_array_map_x
);
1663 scm_array_map_x (ra0
, proc
, lra
)
1668 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
, s_array_map_x
);
1669 switch (SCM_TYP7 (proc
))
1673 scm_ramapc (ramap
, proc
, ra0
, lra
, s_array_map_x
);
1674 return SCM_UNSPECIFIED
;
1675 case scm_tc7_subr_1
:
1676 scm_ramapc (ramap_1
, proc
, ra0
, lra
, s_array_map_x
);
1677 return SCM_UNSPECIFIED
;
1678 case scm_tc7_subr_2
:
1679 case scm_tc7_subr_2o
:
1680 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map_x
);
1681 return SCM_UNSPECIFIED
;
1683 if (!SCM_SUBRF (proc
))
1685 scm_ramapc (ramap_cxr
, proc
, ra0
, lra
, s_array_map_x
);
1686 return SCM_UNSPECIFIED
;
1687 case scm_tc7_rpsubr
:
1690 if (SCM_FALSEP (scm_array_p (ra0
, SCM_BOOL_T
)))
1692 scm_array_fill_x (ra0
, SCM_BOOL_T
);
1693 for (p
= ra_rpsubrs
; p
->name
; p
++)
1694 if (proc
== p
->sproc
)
1696 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1698 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map_x
);
1699 lra
= SCM_CDR (lra
);
1701 return SCM_UNSPECIFIED
;
1703 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1705 scm_ramapc (ramap_rp
, proc
, ra0
, lra
, s_array_map_x
);
1706 lra
= SCM_CDR (lra
);
1708 return SCM_UNSPECIFIED
;
1711 if (SCM_NULLP (lra
))
1713 SCM prot
, fill
= SCM_SUBRF (proc
) (SCM_UNDEFINED
, SCM_UNDEFINED
);
1714 if (SCM_INUMP(fill
))
1716 prot
= scm_array_prototype (ra0
);
1717 if (SCM_NIMP (prot
) && SCM_INEXP (prot
))
1718 fill
= scm_makdbl ((double) SCM_INUM (fill
), 0.0);
1721 scm_array_fill_x (ra0
, fill
);
1725 SCM tail
, ra1
= SCM_CAR (lra
);
1726 SCM v0
= (SCM_NIMP (ra0
) && SCM_ARRAYP (ra0
) ? SCM_ARRAY_V (ra0
) : ra0
);
1728 /* Check to see if order might matter.
1729 This might be an argument for a separate
1730 SERIAL-ARRAY-MAP! */
1731 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1732 if (ra0
!= ra1
|| (SCM_ARRAYP(ra0
) && !SCM_ARRAY_CONTP(ra0
)))
1734 for (tail
= SCM_CDR (lra
); SCM_NNULLP (tail
); tail
= SCM_CDR (tail
))
1736 ra1
= SCM_CAR (tail
);
1737 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1740 for (p
= ra_asubrs
; p
->name
; p
++)
1741 if (proc
== p
->sproc
)
1743 if (ra0
!= SCM_CAR (lra
))
1744 scm_ramapc (scm_array_identity
, SCM_UNDEFINED
, ra0
, scm_cons (SCM_CAR (lra
), SCM_EOL
), s_array_map_x
);
1745 lra
= SCM_CDR (lra
);
1748 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, s_array_map_x
);
1749 if (SCM_IMP (lra
) || SCM_IMP (SCM_CDR (lra
)))
1750 return SCM_UNSPECIFIED
;
1751 lra
= SCM_CDR (lra
);
1754 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, s_array_map_x
);
1755 lra
= SCM_CDR (lra
);
1757 for (lra
= SCM_CDR (lra
); SCM_NIMP (lra
); lra
= SCM_CDR (lra
))
1758 scm_ramapc (ramap_a
, proc
, ra0
, lra
, s_array_map_x
);
1760 return SCM_UNSPECIFIED
;
1765 static int rafe
SCM_P ((SCM ra0
, SCM proc
, SCM ras
));
1768 rafe (ra0
, proc
, ras
)
1773 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1774 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1775 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1776 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1777 ra0
= SCM_ARRAY_V (ra0
);
1778 if (SCM_NULLP (ras
))
1779 for (; i
<= n
; i
++, i0
+= inc0
)
1780 scm_apply (proc
, scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_listofnull
);
1783 SCM ra1
= SCM_CAR (ras
);
1784 SCM args
, *ve
= &ras
;
1785 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1786 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1787 ra1
= SCM_ARRAY_V (ra1
);
1788 ras
= SCM_CDR (ras
);
1793 ras
= scm_vector (ras
);
1794 ve
= SCM_VELTS (ras
);
1796 for (; i
<= n
; i
++, i0
+= inc0
, i1
+= inc1
)
1799 for (k
= SCM_LENGTH (ras
); k
--;)
1800 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1801 args
= scm_cons2 (scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1802 scm_apply (proc
, args
, SCM_EOL
);
1809 SCM_PROC(s_array_for_each
, "array-for-each", 2, 0, 1, scm_array_for_each
);
1812 scm_array_for_each (proc
, ra0
, lra
)
1817 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG1
, s_array_for_each
);
1818 scm_ramapc (rafe
, proc
, ra0
, lra
, s_array_for_each
);
1819 return SCM_UNSPECIFIED
;
1822 SCM_PROC(s_array_index_map_x
, "array-index-map!", 2, 0, 0, scm_array_index_map_x
);
1825 scm_array_index_map_x (ra
, proc
)
1830 SCM_ASSERT (SCM_NIMP (ra
), ra
, SCM_ARG1
, s_array_index_map_x
);
1831 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (proc
), proc
, SCM_ARG2
,
1832 s_array_index_map_x
);
1833 switch (SCM_TYP7(ra
))
1836 badarg
:scm_wta (ra
, (char *) SCM_ARG1
, s_array_index_map_x
);
1837 case scm_tc7_vector
:
1840 SCM
*ve
= SCM_VELTS (ra
);
1841 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1842 ve
[i
] = scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
);
1843 return SCM_UNSPECIFIED
;
1845 case scm_tc7_string
:
1846 case scm_tc7_byvect
:
1851 #ifdef HAVE_LONG_LONGS
1852 case scm_tc7_llvect
:
1857 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1858 scm_array_set_x (ra
, scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
),
1860 return SCM_UNSPECIFIED
;
1862 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
1865 SCM inds
= scm_make_uve (SCM_ARRAY_NDIM (ra
), SCM_MAKINUM (-1L));
1866 long *vinds
= SCM_VELTS (inds
);
1867 int j
, k
, kmax
= SCM_ARRAY_NDIM (ra
) - 1;
1869 return scm_array_set_x (ra
, scm_apply(proc
, SCM_EOL
, SCM_EOL
),
1871 for (k
= 0; k
<= kmax
; k
++)
1872 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1878 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1879 i
= cind (ra
, inds
);
1880 for (; vinds
[k
] <= SCM_ARRAY_DIMS (ra
)[k
].ubnd
; vinds
[k
]++)
1882 for (j
= kmax
+ 1, args
= SCM_EOL
; j
--;)
1883 args
= scm_cons (SCM_MAKINUM (vinds
[j
]), args
);
1884 scm_array_set_x (SCM_ARRAY_V (ra
),
1885 scm_apply (proc
, args
, SCM_EOL
),
1887 i
+= SCM_ARRAY_DIMS (ra
)[k
].inc
;
1892 if (vinds
[k
] < SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
1898 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
- 1;
1902 return SCM_UNSPECIFIED
;
1908 static int raeql_1
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
1911 raeql_1 (ra0
, as_equal
, ra1
)
1916 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1917 scm_sizet i0
= 0, i1
= 0;
1918 long inc0
= 1, inc1
= 1;
1919 scm_sizet n
= SCM_LENGTH (ra0
);
1920 ra1
= SCM_CAR (ra1
);
1921 if (SCM_ARRAYP(ra0
))
1923 n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1924 i0
= SCM_ARRAY_BASE (ra0
);
1925 inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1926 ra0
= SCM_ARRAY_V (ra0
);
1928 if (SCM_ARRAYP (ra1
))
1930 i1
= SCM_ARRAY_BASE (ra1
);
1931 inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1932 ra1
= SCM_ARRAY_V (ra1
);
1934 switch (SCM_TYP7 (ra0
))
1936 case scm_tc7_vector
:
1939 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1941 if (SCM_FALSEP (as_equal
))
1943 if (SCM_FALSEP (scm_array_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
))))
1946 else if (SCM_FALSEP (scm_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
))))
1950 case scm_tc7_string
:
1951 case scm_tc7_byvect
:
1953 char *v0
= SCM_CHARS (ra0
) + i0
;
1954 char *v1
= SCM_CHARS (ra1
) + i1
;
1955 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1961 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1962 if (BVE_REF (ra0
, i0
) != BVE_REF (ra1
, i1
))
1968 long *v0
= (long *) SCM_VELTS (ra0
) + i0
;
1969 long *v1
= (long *) SCM_VELTS (ra1
) + i1
;
1970 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1977 short *v0
= (short *) SCM_VELTS (ra0
) + i0
;
1978 short *v1
= (short *) SCM_VELTS (ra1
) + i1
;
1979 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1984 #ifdef HAVE_LONG_LONGS
1985 case scm_tc7_llvect
:
1987 long long *v0
= (long long *) SCM_VELTS (ra0
) + i0
;
1988 long long *v1
= (long long *) SCM_VELTS (ra1
) + i1
;
1989 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1999 float *v0
= (float *) SCM_VELTS (ra0
) + i0
;
2000 float *v1
= (float *) SCM_VELTS (ra1
) + i1
;
2001 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2006 #endif /* SCM_SINGLES */
2009 double *v0
= (double *) SCM_VELTS (ra0
) + i0
;
2010 double *v1
= (double *) SCM_VELTS (ra1
) + i1
;
2011 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2018 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
) + i0
;
2019 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
) + i1
;
2020 for (; n
--; v0
+= inc0
, v1
+= inc1
)
2022 if ((*v0
)[0] != (*v1
)[0])
2024 if ((*v0
)[1] != (*v1
)[1])
2029 #endif /* SCM_FLOATS */
2035 static int raeql
SCM_P ((SCM ra0
, SCM as_equal
, SCM ra1
));
2038 raeql (ra0
, as_equal
, ra1
)
2043 SCM v0
= ra0
, v1
= ra1
;
2044 scm_array_dim dim0
, dim1
;
2045 scm_array_dim
*s0
= &dim0
, *s1
= &dim1
;
2046 scm_sizet bas0
= 0, bas1
= 0;
2047 int k
, unroll
= 1, vlen
= 1, ndim
= 1;
2048 if (SCM_ARRAYP (ra0
))
2050 ndim
= SCM_ARRAY_NDIM (ra0
);
2051 s0
= SCM_ARRAY_DIMS (ra0
);
2052 bas0
= SCM_ARRAY_BASE (ra0
);
2053 v0
= SCM_ARRAY_V (ra0
);
2059 s0
->ubnd
= SCM_LENGTH (v0
) - 1;
2062 if (SCM_ARRAYP (ra1
))
2064 if (ndim
!= SCM_ARRAY_NDIM (ra1
))
2066 s1
= SCM_ARRAY_DIMS (ra1
);
2067 bas1
= SCM_ARRAY_BASE (ra1
);
2068 v1
= SCM_ARRAY_V (ra1
);
2076 s1
->ubnd
= SCM_LENGTH (v1
) - 1;
2079 if (SCM_TYP7 (v0
) != SCM_TYP7 (v1
))
2081 for (k
= ndim
; k
--;)
2083 if (s0
[k
].lbnd
!= s1
[k
].lbnd
|| s0
[k
].ubnd
!= s1
[k
].ubnd
)
2087 unroll
= (s0
[k
].inc
== s1
[k
].inc
);
2088 vlen
*= s0
[k
].ubnd
- s1
[k
].lbnd
+ 1;
2091 if (unroll
&& bas0
== bas1
&& v0
== v1
)
2093 return scm_ramapc (raeql_1
, as_equal
, ra0
, scm_cons (ra1
, SCM_EOL
), "");
2098 scm_raequal (ra0
, ra1
)
2102 return (raeql (ra0
, SCM_BOOL_T
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2105 static char s_array_equal_p
[] = "array-equal?";
2109 scm_array_equal_p (ra0
, ra1
)
2113 if (SCM_IMP (ra0
) || SCM_IMP (ra1
))
2114 callequal
:return scm_equal_p (ra0
, ra1
);
2115 switch (SCM_TYP7(ra0
))
2120 case scm_tc7_string
:
2121 case scm_tc7_byvect
:
2127 case scm_tc7_vector
:
2131 if (!SCM_ARRAYP (ra0
))
2134 switch (SCM_TYP7 (ra1
))
2139 case scm_tc7_string
:
2140 case scm_tc7_byvect
:
2146 case scm_tc7_vector
:
2150 if (!SCM_ARRAYP (ra1
))
2153 return (raeql (ra0
, SCM_BOOL_F
, ra1
) ? SCM_BOOL_T
: SCM_BOOL_F
);
2159 init_raprocs (subra
)
2162 for (; subra
->name
; subra
++)
2163 subra
->sproc
= SCM_CDR (scm_intern (subra
->name
, strlen (subra
->name
)));
2170 init_raprocs (ra_rpsubrs
);
2171 init_raprocs (ra_asubrs
);
2172 scm_make_subr (s_array_equal_p
, scm_tc7_rpsubr
, scm_array_equal_p
);
2173 scm_smobs
[0x0ff & (scm_tc16_array
>> 8)].equalp
= scm_raequal
;
2175 scm_add_feature (s_array_for_each
);