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. */
42 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
43 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
59 #include "scm_validate.h"
63 #define SCM_RAMAPC(ramap,proc,ra0,lra) do { scm_ramapc (ramap, proc, ra0, lra, FUNC_NAME); } while (0)
73 /* These tables are a kluge that will not scale well when more
74 * vectorized subrs are added. It is tempting to steal some bits from
75 * the SCM_CAR of all subrs (like those selected by SCM_SMOBNUM) to hold an
76 * offset into a table of vectorized subrs.
79 static ra_iproc ra_rpsubrs
[] =
81 {"=", SCM_UNDEFINED
, scm_ra_eqp
},
82 {"<", SCM_UNDEFINED
, scm_ra_lessp
},
83 {"<=", SCM_UNDEFINED
, scm_ra_leqp
},
84 {">", SCM_UNDEFINED
, scm_ra_grp
},
85 {">=", SCM_UNDEFINED
, scm_ra_greqp
},
89 static ra_iproc ra_asubrs
[] =
91 {"+", SCM_UNDEFINED
, scm_ra_sum
},
92 {"-", SCM_UNDEFINED
, scm_ra_difference
},
93 {"*", SCM_UNDEFINED
, scm_ra_product
},
94 {"/", SCM_UNDEFINED
, scm_ra_divide
},
99 #define BVE_REF(a, i) ((SCM_VELTS(a)[(i)/SCM_LONG_BIT] & (1L<<((i)%SCM_LONG_BIT))) ? 1 : 0)
100 #define BVE_SET(a, i) (SCM_VELTS(a)[(i)/SCM_LONG_BIT] |= (1L<<((i)%SCM_LONG_BIT)))
101 #define BVE_CLR(a, i) (SCM_VELTS(a)[(i)/SCM_LONG_BIT] &= ~(1L<<((i)%SCM_LONG_BIT)))
103 /* Fast, recycling scm_vector ref */
104 #define RVREF(ra, i, e) (e = scm_cvref(ra, i, e))
106 /* #define RVREF(ra, i, e) (scm_cvref(ra, i, SCM_UNDEFINED)) to turn off */
108 /* IVDEP means "ignore scm_vector dependencies", meaning we guarantee that
109 elements of scm_vector operands are not aliased */
111 #define IVDEP(test, line) if (test) {_Pragma("ivdep"); line} else {line}
113 #define IVDEP(test, line) line
118 /* inds must be a uvect or ivect, no check. */
122 cind (SCM ra
, SCM inds
)
126 long *ve
= SCM_VELTS (inds
);
127 if (!SCM_ARRAYP (ra
))
129 i
= SCM_ARRAY_BASE (ra
);
130 for (k
= 0; k
< SCM_ARRAY_NDIM (ra
); k
++)
131 i
+= (ve
[k
] - SCM_ARRAY_DIMS (ra
)[k
].lbnd
) * SCM_ARRAY_DIMS (ra
)[k
].inc
;
136 /* Checker for scm_array mapping functions:
137 return values: 4 --> shapes, increments, and bases are the same;
138 3 --> shapes and increments are the same;
139 2 --> shapes are the same;
140 1 --> ras are at least as big as ra0;
145 scm_ra_matchp (SCM ra0
, SCM ras
)
149 scm_array_dim
*s0
= &dims
;
153 int exact
= 2 /* 4 */ ; /* Don't care about values >2 (yet?) */
154 if (SCM_IMP (ra0
)) return 0;
155 switch (SCM_TYP7 (ra0
))
167 #ifdef HAVE_LONG_LONGS
175 s0
->ubnd
= (long) SCM_LENGTH (ra0
) - 1;
178 if (!SCM_ARRAYP (ra0
))
180 ndim
= SCM_ARRAY_NDIM (ra0
);
181 s0
= SCM_ARRAY_DIMS (ra0
);
182 bas0
= SCM_ARRAY_BASE (ra0
);
204 #ifdef HAVE_LONG_LONGS
221 if ((0 == s0
->lbnd
) && (s0
->ubnd
== SCM_LENGTH (ra1
) - 1))
225 if (s0
->lbnd
< 0 || s0
->ubnd
>= SCM_LENGTH (ra1
))
230 if (!SCM_ARRAYP (ra1
) || ndim
!= SCM_ARRAY_NDIM (ra1
))
232 s1
= SCM_ARRAY_DIMS (ra1
);
233 if (bas0
!= SCM_ARRAY_BASE (ra1
))
235 for (i
= 0; i
< ndim
; i
++)
240 if (s0
[i
].inc
!= s1
[i
].inc
)
243 if (s0
[i
].lbnd
== s1
[i
].lbnd
&& s0
[i
].ubnd
== s1
[i
].ubnd
)
247 if (s0
[i
].lbnd
< s1
[i
].lbnd
|| s0
[i
].ubnd
> s1
[i
].ubnd
)
248 return (s0
[i
].lbnd
<= s0
[i
].ubnd
? 0 : 1);
257 /* array mapper: apply cproc to each dimension of the given arrays?.
258 int (*cproc) (); procedure to call on unrolled arrays?
259 cproc (dest, source list) or
260 cproc (dest, data, source list).
261 SCM data; data to give to cproc or unbound.
262 SCM ra0; destination array.
263 SCM lra; list of source arrays.
264 const char *what; caller, for error reporting. */
266 scm_ramapc (int (*cproc
)(), SCM data
, SCM ra0
, SCM lra
, const char *what
)
273 switch (scm_ra_matchp (ra0
, lra
))
277 scm_wta (ra0
, "array shape mismatch", what
);
280 case 4: /* Try unrolling arrays */
281 kmax
= (SCM_ARRAYP (ra0
) ? SCM_ARRAY_NDIM (ra0
) - 1 : 0);
284 vra0
= scm_array_contents (ra0
, SCM_UNDEFINED
);
285 if (SCM_IMP (vra0
)) goto gencase
;
286 if (!SCM_ARRAYP (vra0
))
288 vra1
= scm_make_ra (1);
289 SCM_ARRAY_BASE (vra1
) = 0;
290 SCM_ARRAY_DIMS (vra1
)->lbnd
= 0;
291 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_LENGTH (vra0
) - 1;
292 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
293 SCM_ARRAY_V (vra1
) = vra0
;
298 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
301 vra1
= scm_make_ra (1);
302 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
303 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
304 if (!SCM_ARRAYP (ra1
))
306 SCM_ARRAY_BASE (vra1
) = 0;
307 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
308 SCM_ARRAY_V (vra1
) = ra1
;
310 else if (!SCM_ARRAY_CONTP (ra1
))
314 SCM_ARRAY_BASE (vra1
) = SCM_ARRAY_BASE (ra1
);
315 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
316 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
318 *plvra
= scm_cons (vra1
, SCM_EOL
);
319 plvra
= SCM_CDRLOC (*plvra
);
321 return (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
));
323 gencase
: /* Have to loop over all dimensions. */
324 vra0
= scm_make_ra (1);
325 if (SCM_ARRAYP (ra0
))
327 kmax
= SCM_ARRAY_NDIM (ra0
) - 1;
330 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
331 SCM_ARRAY_DIMS (vra0
)->ubnd
= 0;
332 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
336 SCM_ARRAY_DIMS (vra0
)->lbnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].lbnd
;
337 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].ubnd
;
338 SCM_ARRAY_DIMS (vra0
)->inc
= SCM_ARRAY_DIMS (ra0
)[kmax
].inc
;
340 SCM_ARRAY_BASE (vra0
) = SCM_ARRAY_BASE (ra0
);
341 SCM_ARRAY_V (vra0
) = SCM_ARRAY_V (ra0
);
346 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
347 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_LENGTH (ra0
) - 1;
348 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
349 SCM_ARRAY_BASE (vra0
) = 0;
350 SCM_ARRAY_V (vra0
) = ra0
;
355 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
358 vra1
= scm_make_ra (1);
359 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
360 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
361 if (SCM_ARRAYP (ra1
))
364 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
365 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
369 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
370 SCM_ARRAY_V (vra1
) = ra1
;
372 *plvra
= scm_cons (vra1
, SCM_EOL
);
373 plvra
= SCM_CDRLOC (*plvra
);
375 inds
= scm_make_uve (SCM_ARRAY_NDIM (ra0
), SCM_MAKINUM (-1L));
376 vinds
= (long *) SCM_VELTS (inds
);
377 for (k
= 0; k
<= kmax
; k
++)
378 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
;
385 SCM_ARRAY_BASE (vra0
) = cind (ra0
, inds
);
386 for (z
= lvra
; SCM_NIMP (z
); z
= SCM_CDR (z
), y
= SCM_CDR (y
))
387 SCM_ARRAY_BASE (SCM_CAR (z
)) = cind (SCM_CAR (y
), inds
);
388 if (0 == (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
)))
393 if (vinds
[k
] < SCM_ARRAY_DIMS (ra0
)[k
].ubnd
)
399 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
- 1;
408 GUILE_PROC(scm_array_fill_x
, "array-fill!", 2, 0, 0,
411 #define FUNC_NAME s_scm_array_fill_x
413 SCM_RAMAPC (scm_array_fill_int
, fill
, ra
, SCM_EOL
);
414 return SCM_UNSPECIFIED
;
418 /* to be used as cproc in scm_ramapc to fill an array dimension with
421 scm_array_fill_int (SCM ra
, SCM fill
, SCM ignore
)
422 #define FUNC_NAME s_scm_array_fill_x
425 scm_sizet n
= SCM_ARRAY_DIMS (ra
)->ubnd
- SCM_ARRAY_DIMS (ra
)->lbnd
+ 1;
426 long inc
= SCM_ARRAY_DIMS (ra
)->inc
;
427 scm_sizet base
= SCM_ARRAY_BASE (ra
);
429 ra
= SCM_ARRAY_V (ra
);
433 for (i
= base
; n
--; i
+= inc
)
434 scm_array_set_x (ra
, fill
, SCM_MAKINUM (i
));
438 for (i
= base
; n
--; i
+= inc
)
439 SCM_VELTS (ra
)[i
] = fill
;
442 SCM_ASRTGO (SCM_ICHRP (fill
), badarg2
);
443 for (i
= base
; n
--; i
+= inc
)
444 SCM_CHARS (ra
)[i
] = SCM_ICHR (fill
);
447 if (SCM_ICHRP (fill
))
448 fill
= SCM_MAKINUM ((char) SCM_ICHR (fill
));
449 SCM_ASRTGO (SCM_INUMP (fill
)
450 && -128 <= SCM_INUM (fill
) && SCM_INUM (fill
) < 128,
452 for (i
= base
; n
--; i
+= inc
)
453 SCM_CHARS (ra
)[i
] = SCM_INUM (fill
);
457 long *ve
= (long *) SCM_VELTS (ra
);
458 if (1 == inc
&& (n
>= SCM_LONG_BIT
|| n
== SCM_LENGTH (ra
)))
460 i
= base
/ SCM_LONG_BIT
;
461 if (SCM_BOOL_F
== fill
)
463 if (base
% SCM_LONG_BIT
) /* leading partial word */
464 ve
[i
++] &= ~(~0L << (base
% SCM_LONG_BIT
));
465 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
467 if ((base
+ n
) % SCM_LONG_BIT
) /* trailing partial word */
468 ve
[i
] &= (~0L << ((base
+ n
) % SCM_LONG_BIT
));
470 else if (SCM_BOOL_T
== fill
)
472 if (base
% SCM_LONG_BIT
)
473 ve
[i
++] |= ~0L << (base
% SCM_LONG_BIT
);
474 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
476 if ((base
+ n
) % SCM_LONG_BIT
)
477 ve
[i
] |= ~(~0L << ((base
+ n
) % SCM_LONG_BIT
));
480 badarg2
:SCM_WTA (2,fill
);
484 if (SCM_BOOL_F
== fill
)
485 for (i
= base
; n
--; i
+= inc
)
486 ve
[i
/ SCM_LONG_BIT
] &= ~(1L << (i
% SCM_LONG_BIT
));
487 else if (SCM_BOOL_T
== fill
)
488 for (i
= base
; n
--; i
+= inc
)
489 ve
[i
/ SCM_LONG_BIT
] |= (1L << (i
% SCM_LONG_BIT
));
497 unsigned long f
= SCM_NUM2ULONG (2,fill
);
498 unsigned long *ve
= (long *) SCM_VELTS (ra
);
500 for (i
= base
; n
--; i
+= inc
)
506 long f
= SCM_NUM2LONG (2,fill
);
507 long *ve
= (long *) SCM_VELTS (ra
);
509 for (i
= base
; n
--; i
+= inc
)
514 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
516 short f
= SCM_INUM (fill
);
517 short *ve
= (short *) SCM_VELTS (ra
);
519 if (f
!= SCM_INUM (fill
))
520 SCM_OUT_OF_RANGE (2, fill
);
521 for (i
= base
; n
--; i
+= inc
)
525 #ifdef HAVE_LONG_LONGS
528 long long f
= SCM_NUM2LONG_LONG (2,fill
);
529 long long *ve
= (long long *) SCM_VELTS (ra
);
531 for (i
= base
; n
--; i
+= inc
)
540 float f
, *ve
= (float *) SCM_VELTS (ra
);
541 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
542 f
= SCM_REALPART (fill
);
543 for (i
= base
; n
--; i
+= inc
)
547 #endif /* SCM_SINGLES */
550 double f
, *ve
= (double *) SCM_VELTS (ra
);
551 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_REALP (fill
), badarg2
);
552 f
= SCM_REALPART (fill
);
553 for (i
= base
; n
--; i
+= inc
)
560 double (*ve
)[2] = (double (*)[2]) SCM_VELTS (ra
);
561 SCM_ASRTGO (SCM_NIMP (fill
) && SCM_INEXP (fill
), badarg2
);
562 fr
= SCM_REALPART (fill
);
563 fi
= (SCM_CPLXP (fill
) ? SCM_IMAG (fill
) : 0.0);
564 for (i
= base
; n
--; i
+= inc
)
571 #endif /* SCM_FLOATS */
579 racp (SCM src
, SCM dst
)
581 long n
= (SCM_ARRAY_DIMS (src
)->ubnd
- SCM_ARRAY_DIMS (src
)->lbnd
+ 1);
582 long inc_d
, inc_s
= SCM_ARRAY_DIMS (src
)->inc
;
583 scm_sizet i_d
, i_s
= SCM_ARRAY_BASE (src
);
585 inc_d
= SCM_ARRAY_DIMS (dst
)->inc
;
586 i_d
= SCM_ARRAY_BASE (dst
);
587 src
= SCM_ARRAY_V (src
);
588 dst
= SCM_ARRAY_V (dst
);
597 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
598 scm_array_set_x (dst
, scm_cvref (src
, i_s
, SCM_UNDEFINED
), SCM_MAKINUM (i_d
));
602 if (scm_tc7_string
!= SCM_TYP7 (dst
))
604 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
605 SCM_CHARS (dst
)[i_d
] = SCM_CHARS (src
)[i_s
];
608 if (scm_tc7_bvect
!= SCM_TYP7 (dst
))
610 if (1 == inc_d
&& 1 == inc_s
&& i_s
% SCM_LONG_BIT
== i_d
% SCM_LONG_BIT
&& n
>= SCM_LONG_BIT
)
612 long *sv
= (long *) SCM_VELTS (src
);
613 long *dv
= (long *) SCM_VELTS (dst
);
614 sv
+= i_s
/ SCM_LONG_BIT
;
615 dv
+= i_d
/ SCM_LONG_BIT
;
616 if (i_s
% SCM_LONG_BIT
)
617 { /* leading partial word */
618 *dv
= (*dv
& ~(~0L << (i_s
% SCM_LONG_BIT
))) | (*sv
& (~0L << (i_s
% SCM_LONG_BIT
)));
621 n
-= SCM_LONG_BIT
- (i_s
% SCM_LONG_BIT
);
624 for (; n
>= SCM_LONG_BIT
; n
-= SCM_LONG_BIT
, sv
++, dv
++)
626 if (n
) /* trailing partial word */
627 *dv
= (*dv
& (~0L << n
)) | (*sv
& ~(~0L << n
));
631 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
632 if (SCM_VELTS (src
)[i_s
/ SCM_LONG_BIT
] & (1L << (i_s
% SCM_LONG_BIT
)))
633 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] |= (1L << (i_d
% SCM_LONG_BIT
));
635 SCM_VELTS (dst
)[i_d
/ SCM_LONG_BIT
] &= ~(1L << (i_d
% SCM_LONG_BIT
));
639 if (scm_tc7_uvect
!= SCM_TYP7 (src
))
643 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
645 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
650 if (scm_tc7_uvect
!= SCM_TYP7 (src
) && scm_tc7_ivect
!= 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
)
664 float *d
= (float *) SCM_VELTS (dst
);
665 float *s
= (float *) SCM_VELTS (src
);
674 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
675 d
[i_d
] = ((long *) s
)[i_s
];)
679 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
684 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
685 d
[i_d
] = ((double *) s
)[i_s
];)
690 #endif /* SCM_SINGLES */
693 double *d
= (double *) SCM_VELTS (dst
);
694 double *s
= (double *) SCM_VELTS (src
);
703 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
704 d
[i_d
] = ((long *) s
)[i_s
];)
708 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
709 d
[i_d
] = ((float *) s
)[i_s
];)
713 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
721 double (*d
)[2] = (double (*)[2]) SCM_VELTS (dst
);
722 double (*s
)[2] = (double (*)[2]) SCM_VELTS (src
);
731 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
733 d
[i_d
][0] = ((long *) s
)[i_s
];
740 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
742 d
[i_d
][0] = ((float *) s
)[i_s
];
749 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
751 d
[i_d
][0] = ((double *) s
)[i_s
];
758 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
760 d
[i_d
][0] = s
[i_s
][0];
761 d
[i_d
][1] = s
[i_s
][1];
768 #endif /* SCM_FLOATS */
774 /* This name is obsolete. Will go away in release 1.5. */
775 SCM_REGISTER_PROC(s_serial_array_copy_x
, "serial-array-copy!", 2, 0, 0, scm_array_copy_x
);
776 SCM_REGISTER_PROC(s_array_copy_in_order_x
, "array-copy-in-order!", 2, 0, 0, scm_array_copy_x
);
779 GUILE_PROC(scm_array_copy_x
, "array-copy!", 2, 0, 0,
782 #define FUNC_NAME s_scm_array_copy_x
784 SCM_RAMAPC (racp
, SCM_UNDEFINED
, src
, scm_cons (dst
, SCM_EOL
));
785 return SCM_UNSPECIFIED
;
789 /* Functions callable by ARRAY-MAP! */
793 scm_ra_eqp (SCM ra0
, SCM ras
)
795 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
796 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
797 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
798 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
799 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
800 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
801 ra0
= SCM_ARRAY_V (ra0
);
802 ra1
= SCM_ARRAY_V (ra1
);
803 ra2
= SCM_ARRAY_V (ra2
);
804 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
808 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
809 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
810 if (BVE_REF (ra0
, i0
))
811 if (SCM_FALSEP(scm_eq_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
817 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
818 if (BVE_REF (ra0
, i0
))
819 if (SCM_VELTS (ra1
)[i1
] != SCM_VELTS (ra2
)[i2
])
825 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
826 if (BVE_REF (ra0
, i0
))
827 if (((float *) SCM_VELTS (ra1
))[i1
] != ((float *) SCM_VELTS (ra2
))[i2
])
830 #endif /*SCM_SINGLES*/
832 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
833 if (BVE_REF (ra0
, i0
))
834 if (((double *) SCM_VELTS (ra1
))[i1
] != ((double *) SCM_VELTS (ra2
))[i2
])
838 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
839 if (BVE_REF (ra0
, i0
))
840 if (((double *) SCM_VELTS (ra1
))[2 * i1
] != ((double *) SCM_VELTS (ra2
))[2 * i2
] ||
841 ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1] != ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1])
844 #endif /*SCM_FLOATS*/
849 /* opt 0 means <, nonzero means >= */
852 ra_compare (SCM ra0
,SCM ra1
,SCM ra2
,int opt
)
854 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
855 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
856 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
857 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
858 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
859 ra0
= SCM_ARRAY_V (ra0
);
860 ra1
= SCM_ARRAY_V (ra1
);
861 ra2
= SCM_ARRAY_V (ra2
);
862 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
866 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
867 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
868 if (BVE_REF (ra0
, i0
))
870 SCM_NFALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))) :
871 SCM_FALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
877 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
879 if (BVE_REF (ra0
, i0
))
881 SCM_VELTS (ra1
)[i1
] < SCM_VELTS (ra2
)[i2
] :
882 SCM_VELTS (ra1
)[i1
] >= SCM_VELTS (ra2
)[i2
])
889 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
890 if (BVE_REF(ra0
, i0
))
892 ((float *) SCM_VELTS (ra1
))[i1
] < ((float *) SCM_VELTS (ra2
))[i2
] :
893 ((float *) SCM_VELTS (ra1
))[i1
] >= ((float *) SCM_VELTS (ra2
))[i2
])
896 #endif /*SCM_SINGLES*/
898 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
899 if (BVE_REF (ra0
, i0
))
901 ((double *) SCM_VELTS (ra1
))[i1
] < ((double *) SCM_VELTS (ra2
))[i2
] :
902 ((double *) SCM_VELTS (ra1
))[i1
] >= ((double *) SCM_VELTS (ra2
))[i2
])
905 #endif /*SCM_FLOATS*/
913 scm_ra_lessp (SCM ra0
, SCM ras
)
915 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 0);
920 scm_ra_leqp (SCM ra0
, SCM ras
)
922 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 1);
927 scm_ra_grp (SCM ra0
, SCM ras
)
929 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 0);
934 scm_ra_greqp (SCM ra0
, SCM ras
)
936 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 1);
941 scm_ra_sum (SCM ra0
, SCM ras
)
943 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
944 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
945 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
946 ra0
= SCM_ARRAY_V (ra0
);
949 SCM ra1
= SCM_CAR (ras
);
950 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
951 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
952 ra1
= SCM_ARRAY_V (ra1
);
953 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
957 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
958 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
959 scm_array_set_x (ra0
, scm_sum (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
966 long *v0
= SCM_VELTS (ra0
);
967 long *v1
= SCM_VELTS (ra1
);
969 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
977 float *v0
= (float *) SCM_VELTS (ra0
);
978 float *v1
= (float *) SCM_VELTS (ra1
);
980 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
984 #endif /* SCM_SINGLES */
987 double *v0
= (double *) SCM_VELTS (ra0
);
988 double *v1
= (double *) SCM_VELTS (ra1
);
990 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
996 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
997 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
999 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1001 v0
[i0
][0] += v1
[i1
][0];
1002 v0
[i0
][1] += v1
[i1
][1];
1007 #endif /* SCM_FLOATS */
1016 scm_ra_difference (SCM ra0
, SCM ras
)
1018 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1019 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1020 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1021 ra0
= SCM_ARRAY_V (ra0
);
1022 if (SCM_NULLP (ras
))
1024 switch (SCM_TYP7 (ra0
))
1028 SCM e0
= SCM_UNDEFINED
;
1029 for (; n
-- > 0; i0
+= inc0
)
1030 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1037 float *v0
= (float *) SCM_VELTS (ra0
);
1038 for (; n
-- > 0; i0
+= inc0
)
1042 #endif /* SCM_SINGLES */
1045 double *v0
= (double *) SCM_VELTS (ra0
);
1046 for (; n
-- > 0; i0
+= inc0
)
1052 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1053 for (; n
-- > 0; i0
+= inc0
)
1055 v0
[i0
][0] = -v0
[i0
][0];
1056 v0
[i0
][1] = -v0
[i0
][1];
1060 #endif /* SCM_FLOATS */
1065 SCM ra1
= SCM_CAR (ras
);
1066 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1067 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1068 ra1
= SCM_ARRAY_V (ra1
);
1069 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1073 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1074 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1075 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1082 float *v0
= (float *) SCM_VELTS (ra0
);
1083 float *v1
= (float *) SCM_VELTS (ra1
);
1085 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1089 #endif /* SCM_SINGLES */
1092 double *v0
= (double *) SCM_VELTS (ra0
);
1093 double *v1
= (double *) SCM_VELTS (ra1
);
1095 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1101 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1102 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1104 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1106 v0
[i0
][0] -= v1
[i1
][0];
1107 v0
[i0
][1] -= v1
[i1
][1];
1112 #endif /* SCM_FLOATS */
1121 scm_ra_product (SCM ra0
, SCM ras
)
1123 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1124 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1125 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1126 ra0
= SCM_ARRAY_V (ra0
);
1127 if (SCM_NNULLP (ras
))
1129 SCM ra1
= SCM_CAR (ras
);
1130 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1131 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1132 ra1
= SCM_ARRAY_V (ra1
);
1133 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1137 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1138 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1139 scm_array_set_x (ra0
, scm_product (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1146 long *v0
= SCM_VELTS (ra0
);
1147 long *v1
= SCM_VELTS (ra1
);
1149 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1157 float *v0
= (float *) SCM_VELTS (ra0
);
1158 float *v1
= (float *) SCM_VELTS (ra1
);
1160 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1164 #endif /* SCM_SINGLES */
1167 double *v0
= (double *) SCM_VELTS (ra0
);
1168 double *v1
= (double *) SCM_VELTS (ra1
);
1170 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1176 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1178 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1180 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1182 r
= v0
[i0
][0] * v1
[i1
][0] - v0
[i0
][1] * v1
[i1
][1];
1183 v0
[i0
][1] = v0
[i0
][0] * v1
[i1
][1] + v0
[i0
][1] * v1
[i1
][0];
1189 #endif /* SCM_FLOATS */
1197 scm_ra_divide (SCM ra0
, SCM 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
);
1203 if (SCM_NULLP (ras
))
1205 switch (SCM_TYP7 (ra0
))
1209 SCM e0
= SCM_UNDEFINED
;
1210 for (; n
-- > 0; i0
+= inc0
)
1211 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1218 float *v0
= (float *) SCM_VELTS (ra0
);
1219 for (; n
-- > 0; i0
+= inc0
)
1220 v0
[i0
] = 1.0 / v0
[i0
];
1223 #endif /* SCM_SINGLES */
1226 double *v0
= (double *) SCM_VELTS (ra0
);
1227 for (; n
-- > 0; i0
+= inc0
)
1228 v0
[i0
] = 1.0 / v0
[i0
];
1234 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1235 for (; n
-- > 0; i0
+= inc0
)
1237 d
= v0
[i0
][0] * v0
[i0
][0] + v0
[i0
][1] * v0
[i0
][1];
1243 #endif /* SCM_FLOATS */
1248 SCM ra1
= SCM_CAR (ras
);
1249 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1250 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1251 ra1
= SCM_ARRAY_V (ra1
);
1252 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1256 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1257 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1258 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1265 float *v0
= (float *) SCM_VELTS (ra0
);
1266 float *v1
= (float *) SCM_VELTS (ra1
);
1268 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1272 #endif /* SCM_SINGLES */
1275 double *v0
= (double *) SCM_VELTS (ra0
);
1276 double *v1
= (double *) SCM_VELTS (ra1
);
1278 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1284 register double d
, r
;
1285 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1286 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1288 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1290 d
= v1
[i1
][0] * v1
[i1
][0] + v1
[i1
][1] * v1
[i1
][1];
1291 r
= (v0
[i0
][0] * v1
[i1
][0] + v0
[i0
][1] * v1
[i1
][1]) / d
;
1292 v0
[i0
][1] = (v0
[i0
][1] * v1
[i1
][0] - v0
[i0
][0] * v1
[i1
][1]) / d
;
1298 #endif /* SCM_FLOATS */
1306 scm_array_identity (SCM dst
, SCM src
)
1308 return racp (SCM_CAR (src
), scm_cons (dst
, SCM_EOL
));
1314 ramap (SCM ra0
,SCM proc
,SCM ras
)
1316 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1317 long inc
= SCM_ARRAY_DIMS (ra0
)->inc
;
1318 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1319 long base
= SCM_ARRAY_BASE (ra0
) - i
* inc
;
1320 ra0
= SCM_ARRAY_V (ra0
);
1321 if (SCM_NULLP (ras
))
1323 scm_array_set_x (ra0
, scm_apply (proc
, SCM_EOL
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1326 SCM ra1
= SCM_CAR (ras
);
1327 SCM args
, *ve
= &ras
;
1328 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1329 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1330 ra1
= SCM_ARRAY_V (ra1
);
1331 ras
= SCM_CDR (ras
);
1336 ras
= scm_vector (ras
);
1337 ve
= SCM_VELTS (ras
);
1339 for (; i
<= n
; i
++, i1
+= inc1
)
1342 for (k
= SCM_LENGTH (ras
); k
--;)
1343 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1344 args
= scm_cons (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1345 scm_array_set_x (ra0
, scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1353 ramap_cxr (SCM ra0
,SCM proc
,SCM ras
)
1355 SCM ra1
= SCM_CAR (ras
);
1356 SCM e1
= SCM_UNDEFINED
;
1357 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1358 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1359 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra1
)->lbnd
+ 1;
1360 ra0
= SCM_ARRAY_V (ra0
);
1361 ra1
= SCM_ARRAY_V (ra1
);
1362 switch (SCM_TYP7 (ra0
))
1366 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1367 scm_array_set_x (ra0
, scm_apply (proc
, RVREF (ra1
, i1
, e1
), scm_listofnull
), SCM_MAKINUM (i0
));
1373 float *dst
= (float *) SCM_VELTS (ra0
);
1374 switch (SCM_TYP7 (ra1
))
1379 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1380 dst
[i0
] = SCM_DSUBRF (proc
) ((double) ((float *) SCM_VELTS (ra1
))[i1
]);
1384 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1385 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1390 #endif /* SCM_SINGLES */
1393 double *dst
= (double *) SCM_VELTS (ra0
);
1394 switch (SCM_TYP7 (ra1
))
1399 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1400 dst
[i0
] = SCM_DSUBRF (proc
) (((double *) SCM_VELTS (ra1
))[i1
]);
1404 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1405 dst
[i0
] = SCM_DSUBRF (proc
) ((double) SCM_VELTS (ra1
)[i1
]);
1410 #endif /* SCM_FLOATS */
1418 ramap_rp (SCM ra0
,SCM proc
,SCM ras
)
1420 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
1421 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
1422 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1423 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
1424 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1425 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1426 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
1427 ra0
= SCM_ARRAY_V (ra0
);
1428 ra1
= SCM_ARRAY_V (ra1
);
1429 ra2
= SCM_ARRAY_V (ra2
);
1430 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
1433 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1434 if (BVE_REF (ra0
, i0
))
1435 if (SCM_FALSEP (SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
1440 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1441 if (BVE_REF (ra0
, i0
))
1443 if (SCM_FALSEP (SCM_SUBRF (proc
) (SCM_MAKINUM (SCM_VELTS (ra1
)[i1
]),
1444 SCM_MAKINUM (SCM_VELTS (ra2
)[i2
]))))
1452 SCM a1
= scm_makflo (1.0), a2
= scm_makflo (1.0);
1453 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1454 if (BVE_REF (ra0
, i0
))
1456 SCM_FLO (a1
) = ((float *) SCM_VELTS (ra1
))[i1
];
1457 SCM_FLO (a2
) = ((float *) SCM_VELTS (ra2
))[i2
];
1458 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1463 #endif /*SCM_SINGLES*/
1466 SCM a1
= scm_makdbl (1.0 / 3.0, 0.0), a2
= scm_makdbl (1.0 / 3.0, 0.0);
1467 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1468 if (BVE_REF (ra0
, i0
))
1470 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[i1
];
1471 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[i2
];
1472 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1479 SCM a1
= scm_makdbl (1.0, 1.0), a2
= scm_makdbl (1.0, 1.0);
1480 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1481 if (BVE_REF (ra0
, i0
))
1483 SCM_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
];
1484 SCM_IMAG (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1];
1485 SCM_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
];
1486 SCM_IMAG (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1];
1487 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1492 #endif /*SCM_FLOATS*/
1500 ramap_1 (SCM ra0
,SCM proc
,SCM ras
)
1502 SCM ra1
= SCM_CAR (ras
);
1503 SCM e1
= SCM_UNDEFINED
;
1504 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1505 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1506 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1507 ra0
= SCM_ARRAY_V (ra0
);
1508 ra1
= SCM_ARRAY_V (ra1
);
1509 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1510 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1511 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
)), SCM_MAKINUM (i0
));
1513 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1514 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1521 ramap_2o (SCM ra0
,SCM proc
,SCM ras
)
1523 SCM ra1
= SCM_CAR (ras
);
1524 SCM e1
= SCM_UNDEFINED
;
1525 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1526 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1527 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1528 ra0
= SCM_ARRAY_V (ra0
);
1529 ra1
= SCM_ARRAY_V (ra1
);
1530 ras
= SCM_CDR (ras
);
1531 if (SCM_NULLP (ras
))
1533 if (scm_tc7_vector
== SCM_TYP7 (ra0
)
1534 || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1536 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1537 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), SCM_UNDEFINED
),
1540 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1541 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), SCM_UNDEFINED
),
1546 SCM ra2
= SCM_CAR (ras
);
1547 SCM e2
= SCM_UNDEFINED
;
1548 scm_sizet i2
= SCM_ARRAY_BASE (ra2
);
1549 long inc2
= SCM_ARRAY_DIMS (ra2
)->inc
;
1550 ra2
= SCM_ARRAY_V (ra2
);
1551 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1552 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1553 scm_array_set_x (ra0
,
1554 SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), scm_cvref (ra2
, i2
, SCM_UNDEFINED
)),
1557 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1558 scm_array_set_x (ra0
,
1559 SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)),
1568 ramap_a (SCM ra0
,SCM proc
,SCM ras
)
1570 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1571 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1572 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1573 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1574 ra0
= SCM_ARRAY_V (ra0
);
1575 if (SCM_NULLP (ras
))
1576 for (; n
-- > 0; i0
+= inc0
)
1577 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1580 SCM ra1
= SCM_CAR (ras
);
1581 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1582 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1583 ra1
= SCM_ARRAY_V (ra1
);
1584 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1585 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1591 /* This name is obsolete. Will go away in release 1.5. */
1592 SCM_REGISTER_PROC(s_serial_array_map_x
, "serial-array-map!", 2, 0, 1, scm_array_map_x
);
1593 SCM_REGISTER_PROC(s_array_map_in_order_x
, "array-map-in-order!", 2, 0, 1, scm_array_map_x
);
1596 GUILE_PROC(scm_array_map_x
, "array-map!", 2, 0, 1,
1597 (SCM ra0
, SCM proc
, SCM lra
),
1599 #define FUNC_NAME s_scm_array_map_x
1601 SCM_VALIDATE_PROC(2,proc
);
1602 switch (SCM_TYP7 (proc
))
1606 SCM_RAMAPC (ramap
, proc
, ra0
, lra
);
1607 return SCM_UNSPECIFIED
;
1608 case scm_tc7_subr_1
:
1609 SCM_RAMAPC (ramap_1
, proc
, ra0
, lra
);
1610 return SCM_UNSPECIFIED
;
1611 case scm_tc7_subr_2
:
1612 case scm_tc7_subr_2o
:
1613 SCM_RAMAPC (ramap_2o
, proc
, ra0
, lra
);
1614 return SCM_UNSPECIFIED
;
1616 if (!SCM_SUBRF (proc
))
1618 SCM_RAMAPC (ramap_cxr
, proc
, ra0
, lra
);
1619 return SCM_UNSPECIFIED
;
1620 case scm_tc7_rpsubr
:
1623 if (SCM_FALSEP (scm_array_p (ra0
, SCM_BOOL_T
)))
1625 scm_array_fill_x (ra0
, SCM_BOOL_T
);
1626 for (p
= ra_rpsubrs
; p
->name
; p
++)
1627 if (proc
== p
->sproc
)
1629 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1631 SCM_RAMAPC (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
);
1632 lra
= SCM_CDR (lra
);
1634 return SCM_UNSPECIFIED
;
1636 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1638 SCM_RAMAPC (ramap_rp
, proc
, ra0
, lra
);
1639 lra
= SCM_CDR (lra
);
1641 return SCM_UNSPECIFIED
;
1644 if (SCM_NULLP (lra
))
1646 SCM prot
, fill
= SCM_SUBRF (proc
) (SCM_UNDEFINED
, SCM_UNDEFINED
);
1647 if (SCM_INUMP(fill
))
1649 prot
= scm_array_prototype (ra0
);
1650 if (SCM_NIMP (prot
) && SCM_INEXP (prot
))
1651 fill
= scm_makdbl ((double) SCM_INUM (fill
), 0.0);
1654 scm_array_fill_x (ra0
, fill
);
1658 SCM tail
, ra1
= SCM_CAR (lra
);
1659 SCM v0
= (SCM_NIMP (ra0
) && SCM_ARRAYP (ra0
) ? SCM_ARRAY_V (ra0
) : ra0
);
1661 /* Check to see if order might matter.
1662 This might be an argument for a separate
1663 SERIAL-ARRAY-MAP! */
1664 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1665 if (ra0
!= ra1
|| (SCM_ARRAYP(ra0
) && !SCM_ARRAY_CONTP(ra0
)))
1667 for (tail
= SCM_CDR (lra
); SCM_NNULLP (tail
); tail
= SCM_CDR (tail
))
1669 ra1
= SCM_CAR (tail
);
1670 if (v0
== ra1
|| (SCM_NIMP (ra1
) && SCM_ARRAYP (ra1
) && v0
== SCM_ARRAY_V (ra1
)))
1673 for (p
= ra_asubrs
; p
->name
; p
++)
1674 if (proc
== p
->sproc
)
1676 if (ra0
!= SCM_CAR (lra
))
1677 SCM_RAMAPC (scm_array_identity
, SCM_UNDEFINED
, ra0
, scm_cons (SCM_CAR (lra
), SCM_EOL
));
1678 lra
= SCM_CDR (lra
);
1681 SCM_RAMAPC (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
);
1682 if (SCM_IMP (lra
) || SCM_IMP (SCM_CDR (lra
)))
1683 return SCM_UNSPECIFIED
;
1684 lra
= SCM_CDR (lra
);
1687 SCM_RAMAPC (ramap_2o
, proc
, ra0
, lra
);
1688 lra
= SCM_CDR (lra
);
1690 for (lra
= SCM_CDR (lra
); SCM_NIMP (lra
); lra
= SCM_CDR (lra
))
1691 SCM_RAMAPC (ramap_a
, proc
, ra0
, lra
);
1693 return SCM_UNSPECIFIED
;
1700 rafe (SCM ra0
,SCM proc
,SCM ras
)
1702 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1703 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1704 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1705 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1706 ra0
= SCM_ARRAY_V (ra0
);
1707 if (SCM_NULLP (ras
))
1708 for (; i
<= n
; i
++, i0
+= inc0
)
1709 scm_apply (proc
, scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_listofnull
);
1712 SCM ra1
= SCM_CAR (ras
);
1713 SCM args
, *ve
= &ras
;
1714 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1715 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1716 ra1
= SCM_ARRAY_V (ra1
);
1717 ras
= SCM_CDR (ras
);
1722 ras
= scm_vector (ras
);
1723 ve
= SCM_VELTS (ras
);
1725 for (; i
<= n
; i
++, i0
+= inc0
, i1
+= inc1
)
1728 for (k
= SCM_LENGTH (ras
); k
--;)
1729 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1730 args
= scm_cons2 (scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1731 scm_apply (proc
, args
, SCM_EOL
);
1738 GUILE_PROC(scm_array_for_each
, "array-for-each", 2, 0, 1,
1739 (SCM proc
, SCM ra0
, SCM lra
),
1741 #define FUNC_NAME s_scm_array_for_each
1743 SCM_VALIDATE_PROC(1,proc
);
1744 SCM_RAMAPC (rafe
, proc
, ra0
, lra
);
1745 return SCM_UNSPECIFIED
;
1749 GUILE_PROC(scm_array_index_map_x
, "array-index-map!", 2, 0, 0,
1752 #define FUNC_NAME s_scm_array_index_map_x
1755 SCM_VALIDATE_NIM (1,ra
);
1756 SCM_VALIDATE_PROC(2,proc
);
1757 switch (SCM_TYP7(ra
))
1760 badarg
:SCM_WTA (1,ra
);
1761 case scm_tc7_vector
:
1764 SCM
*ve
= SCM_VELTS (ra
);
1765 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1766 ve
[i
] = scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
);
1767 return SCM_UNSPECIFIED
;
1769 case scm_tc7_string
:
1770 case scm_tc7_byvect
:
1775 #ifdef HAVE_LONG_LONGS
1776 case scm_tc7_llvect
:
1781 for (i
= 0; i
< SCM_LENGTH (ra
); i
++)
1782 scm_array_set_x (ra
, scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
),
1784 return SCM_UNSPECIFIED
;
1786 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
1789 SCM inds
= scm_make_uve (SCM_ARRAY_NDIM (ra
), SCM_MAKINUM (-1L));
1790 long *vinds
= SCM_VELTS (inds
);
1791 int j
, k
, kmax
= SCM_ARRAY_NDIM (ra
) - 1;
1793 return scm_array_set_x (ra
, scm_apply(proc
, SCM_EOL
, SCM_EOL
),
1795 for (k
= 0; k
<= kmax
; k
++)
1796 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1802 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1803 i
= cind (ra
, inds
);
1804 for (; vinds
[k
] <= SCM_ARRAY_DIMS (ra
)[k
].ubnd
; vinds
[k
]++)
1806 for (j
= kmax
+ 1, args
= SCM_EOL
; j
--;)
1807 args
= scm_cons (SCM_MAKINUM (vinds
[j
]), args
);
1808 scm_array_set_x (SCM_ARRAY_V (ra
),
1809 scm_apply (proc
, args
, SCM_EOL
),
1811 i
+= SCM_ARRAY_DIMS (ra
)[k
].inc
;
1816 if (vinds
[k
] < SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
1822 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
- 1;
1826 return SCM_UNSPECIFIED
;
1834 raeql_1 (SCM ra0
,SCM as_equal
,SCM ra1
)
1836 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1837 scm_sizet i0
= 0, i1
= 0;
1838 long inc0
= 1, inc1
= 1;
1839 scm_sizet n
= SCM_LENGTH (ra0
);
1840 ra1
= SCM_CAR (ra1
);
1841 if (SCM_ARRAYP(ra0
))
1843 n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1844 i0
= SCM_ARRAY_BASE (ra0
);
1845 inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1846 ra0
= SCM_ARRAY_V (ra0
);
1848 if (SCM_ARRAYP (ra1
))
1850 i1
= SCM_ARRAY_BASE (ra1
);
1851 inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1852 ra1
= SCM_ARRAY_V (ra1
);
1854 switch (SCM_TYP7 (ra0
))
1856 case scm_tc7_vector
:
1859 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1861 if (SCM_FALSEP (as_equal
))
1863 if (SCM_FALSEP (scm_array_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
))))
1866 else if (SCM_FALSEP (scm_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
))))
1870 case scm_tc7_string
:
1871 case scm_tc7_byvect
:
1873 char *v0
= SCM_CHARS (ra0
) + i0
;
1874 char *v1
= SCM_CHARS (ra1
) + i1
;
1875 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1881 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1882 if (BVE_REF (ra0
, i0
) != BVE_REF (ra1
, i1
))
1888 long *v0
= (long *) SCM_VELTS (ra0
) + i0
;
1889 long *v1
= (long *) SCM_VELTS (ra1
) + i1
;
1890 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1897 short *v0
= (short *) SCM_VELTS (ra0
) + i0
;
1898 short *v1
= (short *) SCM_VELTS (ra1
) + i1
;
1899 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1904 #ifdef HAVE_LONG_LONGS
1905 case scm_tc7_llvect
:
1907 long long *v0
= (long long *) SCM_VELTS (ra0
) + i0
;
1908 long long *v1
= (long long *) SCM_VELTS (ra1
) + i1
;
1909 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1919 float *v0
= (float *) SCM_VELTS (ra0
) + i0
;
1920 float *v1
= (float *) SCM_VELTS (ra1
) + i1
;
1921 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1926 #endif /* SCM_SINGLES */
1929 double *v0
= (double *) SCM_VELTS (ra0
) + i0
;
1930 double *v1
= (double *) SCM_VELTS (ra1
) + i1
;
1931 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1938 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
) + i0
;
1939 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
) + i1
;
1940 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1942 if ((*v0
)[0] != (*v1
)[0])
1944 if ((*v0
)[1] != (*v1
)[1])
1949 #endif /* SCM_FLOATS */
1956 raeql (SCM ra0
,SCM as_equal
,SCM ra1
)
1958 SCM v0
= ra0
, v1
= ra1
;
1959 scm_array_dim dim0
, dim1
;
1960 scm_array_dim
*s0
= &dim0
, *s1
= &dim1
;
1961 scm_sizet bas0
= 0, bas1
= 0;
1962 int k
, unroll
= 1, vlen
= 1, ndim
= 1;
1963 if (SCM_ARRAYP (ra0
))
1965 ndim
= SCM_ARRAY_NDIM (ra0
);
1966 s0
= SCM_ARRAY_DIMS (ra0
);
1967 bas0
= SCM_ARRAY_BASE (ra0
);
1968 v0
= SCM_ARRAY_V (ra0
);
1974 s0
->ubnd
= SCM_LENGTH (v0
) - 1;
1977 if (SCM_ARRAYP (ra1
))
1979 if (ndim
!= SCM_ARRAY_NDIM (ra1
))
1981 s1
= SCM_ARRAY_DIMS (ra1
);
1982 bas1
= SCM_ARRAY_BASE (ra1
);
1983 v1
= SCM_ARRAY_V (ra1
);
1991 s1
->ubnd
= SCM_LENGTH (v1
) - 1;
1994 if (SCM_TYP7 (v0
) != SCM_TYP7 (v1
))
1996 for (k
= ndim
; k
--;)
1998 if (s0
[k
].lbnd
!= s1
[k
].lbnd
|| s0
[k
].ubnd
!= s1
[k
].ubnd
)
2002 unroll
= (s0
[k
].inc
== s1
[k
].inc
);
2003 vlen
*= s0
[k
].ubnd
- s1
[k
].lbnd
+ 1;
2006 if (unroll
&& bas0
== bas1
&& v0
== v1
)
2008 return scm_ramapc (raeql_1
, as_equal
, ra0
, scm_cons (ra1
, SCM_EOL
), "");
2013 scm_raequal (SCM ra0
, SCM ra1
)
2015 return SCM_BOOL(raeql (ra0
, SCM_BOOL_T
, ra1
));
2018 static char s_array_equal_p
[] = "array-equal?";
2022 scm_array_equal_p (SCM ra0
, SCM ra1
)
2024 if (SCM_IMP (ra0
) || SCM_IMP (ra1
))
2025 callequal
:return scm_equal_p (ra0
, ra1
);
2026 switch (SCM_TYP7(ra0
))
2031 case scm_tc7_string
:
2032 case scm_tc7_byvect
:
2038 case scm_tc7_vector
:
2042 if (!SCM_ARRAYP (ra0
))
2045 switch (SCM_TYP7 (ra1
))
2050 case scm_tc7_string
:
2051 case scm_tc7_byvect
:
2057 case scm_tc7_vector
:
2061 if (!SCM_ARRAYP (ra1
))
2064 return SCM_BOOL(raeql (ra0
, SCM_BOOL_F
, ra1
));
2070 init_raprocs (ra_iproc
*subra
)
2072 for (; subra
->name
; subra
++)
2073 subra
->sproc
= SCM_CDR (scm_intern (subra
->name
, strlen (subra
->name
)));
2080 init_raprocs (ra_rpsubrs
);
2081 init_raprocs (ra_asubrs
);
2082 scm_make_subr (s_array_equal_p
, scm_tc7_rpsubr
, scm_array_equal_p
);
2083 scm_smobs
[0x0ff & (scm_tc16_array
>> 8)].equalp
= scm_raequal
;
2085 scm_add_feature (s_scm_array_for_each
);