1 /* Copyright (C) 1996,1998,2000,2001 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 */
47 Someone should rename this to arraymap.c; that would reflect the
54 #include "libguile/_scm.h"
55 #include "libguile/strings.h"
56 #include "libguile/unif.h"
57 #include "libguile/smob.h"
58 #include "libguile/chars.h"
59 #include "libguile/eq.h"
60 #include "libguile/eval.h"
61 #include "libguile/feature.h"
62 #include "libguile/root.h"
63 #include "libguile/vectors.h"
65 #include "libguile/validate.h"
66 #include "libguile/ramap.h"
77 /* These tables are a kluge that will not scale well when more
78 * vectorized subrs are added. It is tempting to steal some bits from
79 * the SCM_CAR of all subrs (like those selected by SCM_SMOBNUM) to hold an
80 * offset into a table of vectorized subrs.
83 static ra_iproc ra_rpsubrs
[] =
85 {"=", SCM_UNDEFINED
, scm_ra_eqp
},
86 {"<", SCM_UNDEFINED
, scm_ra_lessp
},
87 {"<=", SCM_UNDEFINED
, scm_ra_leqp
},
88 {">", SCM_UNDEFINED
, scm_ra_grp
},
89 {">=", SCM_UNDEFINED
, scm_ra_greqp
},
93 static ra_iproc ra_asubrs
[] =
95 {"+", SCM_UNDEFINED
, scm_ra_sum
},
96 {"-", SCM_UNDEFINED
, scm_ra_difference
},
97 {"*", SCM_UNDEFINED
, scm_ra_product
},
98 {"/", SCM_UNDEFINED
, scm_ra_divide
},
104 /* Fast, recycling scm_vector ref */
105 #define RVREF(ra, i, e) (e = scm_cvref(ra, i, e))
107 /* #define RVREF(ra, i, e) (scm_cvref(ra, i, SCM_UNDEFINED)) to turn off */
109 /* IVDEP means "ignore scm_vector dependencies", meaning we guarantee that
110 elements of scm_vector operands are not aliased */
112 #define IVDEP(test, line) if (test) {_Pragma("ivdep"); line} else {line}
114 #define IVDEP(test, line) line
119 /* inds must be a uvect or ivect, no check. */
124 Yes, this is really ugly, but it prevents multiple code
126 #define BINARY_ELTS_CODE(OPERATOR, type) \
127 do { type *v0 = (type*)SCM_VELTS (ra0);\
128 type *v1 = (type*)SCM_VELTS (ra1);\
130 for (; n-- > 0; i0 += inc0, i1 += inc1) \
131 v0[i0] OPERATOR v1[i1];) \
135 /* This macro is used for all but binary division and
136 multiplication of complex numbers -- see the expanded
137 version in the functions later in this file */
138 #define BINARY_PAIR_ELTS_CODE(OPERATOR, type) \
139 do { type (*v0)[2] = (type (*)[2]) SCM_VELTS (ra0);\
140 type (*v1)[2] = (type (*)[2]) SCM_VELTS (ra1);\
142 for (; n-- > 0; i0 += inc0, i1 += inc1) {\
143 v0[i0][0] OPERATOR v1[i1][0]; \
144 v0[i0][1] OPERATOR v1[i1][1]; \
149 #define UNARY_ELTS_CODE(OPERATOR, type) \
150 do { type *v0 = (type *) SCM_VELTS (ra0);\
151 for (; n-- > 0; i0 += inc0) \
152 v0[i0] OPERATOR v0[i0];\
157 /* This macro is used for all but unary divison
158 of complex numbers -- see the expanded version in the
159 function later in this file. */
160 #define UNARY_PAIR_ELTS_CODE(OPERATOR, type) \
161 do { type (*v0)[2] = (type (*)[2]) SCM_VELTS (ra0);\
162 for (; n-- > 0; i0 += inc0) {\
163 v0[i0][0] OPERATOR v0[i0][0];\
164 v0[i0][1] OPERATOR v0[i0][1];\
170 cind (SCM ra
, SCM inds
)
174 long *ve
= (long*) SCM_VELTS (inds
);
175 if (!SCM_ARRAYP (ra
))
177 i
= SCM_ARRAY_BASE (ra
);
178 for (k
= 0; k
< SCM_ARRAY_NDIM (ra
); k
++)
179 i
+= (ve
[k
] - SCM_ARRAY_DIMS (ra
)[k
].lbnd
) * SCM_ARRAY_DIMS (ra
)[k
].inc
;
184 /* Checker for scm_array mapping functions:
185 return values: 4 --> shapes, increments, and bases are the same;
186 3 --> shapes and increments are the same;
187 2 --> shapes are the same;
188 1 --> ras are at least as big as ra0;
193 scm_ra_matchp (SCM ra0
, SCM ras
)
197 scm_array_dim
*s0
= &dims
;
201 int exact
= 2 /* 4 */ ; /* Don't care about values >2 (yet?) */
202 if (SCM_IMP (ra0
)) return 0;
203 switch (SCM_TYP7 (ra0
))
215 #ifdef HAVE_LONG_LONGS
223 s0
->ubnd
= SCM_INUM (scm_uniform_vector_length (ra0
)) - 1;
226 if (!SCM_ARRAYP (ra0
))
228 ndim
= SCM_ARRAY_NDIM (ra0
);
229 s0
= SCM_ARRAY_DIMS (ra0
);
230 bas0
= SCM_ARRAY_BASE (ra0
);
233 while (SCM_NIMP (ras
))
251 #ifdef HAVE_LONG_LONGS
258 unsigned long int length
;
263 length
= SCM_INUM (scm_uniform_vector_length (ra1
));
274 if ((0 == s0
->lbnd
) && (s0
->ubnd
== length
- 1))
278 if (s0
->lbnd
< 0 || s0
->ubnd
>= length
)
284 if (!SCM_ARRAYP (ra1
) || ndim
!= SCM_ARRAY_NDIM (ra1
))
286 s1
= SCM_ARRAY_DIMS (ra1
);
287 if (bas0
!= SCM_ARRAY_BASE (ra1
))
289 for (i
= 0; i
< ndim
; i
++)
294 if (s0
[i
].inc
!= s1
[i
].inc
)
297 if (s0
[i
].lbnd
== s1
[i
].lbnd
&& s0
[i
].ubnd
== s1
[i
].ubnd
)
301 if (s0
[i
].lbnd
< s1
[i
].lbnd
|| s0
[i
].ubnd
> s1
[i
].ubnd
)
302 return (s0
[i
].lbnd
<= s0
[i
].ubnd
? 0 : 1);
311 /* array mapper: apply cproc to each dimension of the given arrays?.
312 int (*cproc) (); procedure to call on unrolled arrays?
313 cproc (dest, source list) or
314 cproc (dest, data, source list).
315 SCM data; data to give to cproc or unbound.
316 SCM ra0; destination array.
317 SCM lra; list of source arrays.
318 const char *what; caller, for error reporting. */
320 scm_ramapc (int (*cproc
)(), SCM data
, SCM ra0
, SCM lra
, const char *what
)
327 switch (scm_ra_matchp (ra0
, lra
))
331 scm_misc_error (what
, "array shape mismatch: ~S", ra0
);
334 case 4: /* Try unrolling arrays */
335 kmax
= (SCM_ARRAYP (ra0
) ? SCM_ARRAY_NDIM (ra0
) - 1 : 0);
338 vra0
= scm_array_contents (ra0
, SCM_UNDEFINED
);
339 if (SCM_IMP (vra0
)) goto gencase
;
340 if (!SCM_ARRAYP (vra0
))
342 unsigned long int length
= SCM_INUM (scm_uniform_vector_length (vra0
));
343 vra1
= scm_make_ra (1);
344 SCM_ARRAY_BASE (vra1
) = 0;
345 SCM_ARRAY_DIMS (vra1
)->lbnd
= 0;
346 SCM_ARRAY_DIMS (vra1
)->ubnd
= length
- 1;
347 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
348 SCM_ARRAY_V (vra1
) = vra0
;
353 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
356 vra1
= scm_make_ra (1);
357 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
358 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
359 if (!SCM_ARRAYP (ra1
))
361 SCM_ARRAY_BASE (vra1
) = 0;
362 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
363 SCM_ARRAY_V (vra1
) = ra1
;
365 else if (!SCM_ARRAY_CONTP (ra1
))
369 SCM_ARRAY_BASE (vra1
) = SCM_ARRAY_BASE (ra1
);
370 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
371 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
373 *plvra
= scm_cons (vra1
, SCM_EOL
);
374 plvra
= SCM_CDRLOC (*plvra
);
376 return (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
));
378 gencase
: /* Have to loop over all dimensions. */
379 vra0
= scm_make_ra (1);
380 if (SCM_ARRAYP (ra0
))
382 kmax
= SCM_ARRAY_NDIM (ra0
) - 1;
385 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
386 SCM_ARRAY_DIMS (vra0
)->ubnd
= 0;
387 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
391 SCM_ARRAY_DIMS (vra0
)->lbnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].lbnd
;
392 SCM_ARRAY_DIMS (vra0
)->ubnd
= SCM_ARRAY_DIMS (ra0
)[kmax
].ubnd
;
393 SCM_ARRAY_DIMS (vra0
)->inc
= SCM_ARRAY_DIMS (ra0
)[kmax
].inc
;
395 SCM_ARRAY_BASE (vra0
) = SCM_ARRAY_BASE (ra0
);
396 SCM_ARRAY_V (vra0
) = SCM_ARRAY_V (ra0
);
400 unsigned long int length
= SCM_INUM (scm_uniform_vector_length (ra0
));
402 SCM_ARRAY_DIMS (vra0
)->lbnd
= 0;
403 SCM_ARRAY_DIMS (vra0
)->ubnd
= length
- 1;
404 SCM_ARRAY_DIMS (vra0
)->inc
= 1;
405 SCM_ARRAY_BASE (vra0
) = 0;
406 SCM_ARRAY_V (vra0
) = ra0
;
411 for (z
= lra
; SCM_NIMP (z
); z
= SCM_CDR (z
))
414 vra1
= scm_make_ra (1);
415 SCM_ARRAY_DIMS (vra1
)->lbnd
= SCM_ARRAY_DIMS (vra0
)->lbnd
;
416 SCM_ARRAY_DIMS (vra1
)->ubnd
= SCM_ARRAY_DIMS (vra0
)->ubnd
;
417 if (SCM_ARRAYP (ra1
))
420 SCM_ARRAY_DIMS (vra1
)->inc
= SCM_ARRAY_DIMS (ra1
)[kmax
].inc
;
421 SCM_ARRAY_V (vra1
) = SCM_ARRAY_V (ra1
);
425 SCM_ARRAY_DIMS (vra1
)->inc
= 1;
426 SCM_ARRAY_V (vra1
) = ra1
;
428 *plvra
= scm_cons (vra1
, SCM_EOL
);
429 plvra
= SCM_CDRLOC (*plvra
);
431 inds
= scm_make_uve (SCM_ARRAY_NDIM (ra0
), SCM_MAKINUM (-1L));
432 vinds
= (long *) SCM_VELTS (inds
);
433 for (k
= 0; k
<= kmax
; k
++)
434 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
;
441 SCM_ARRAY_BASE (vra0
) = cind (ra0
, inds
);
442 for (z
= lvra
; SCM_NIMP (z
); z
= SCM_CDR (z
), y
= SCM_CDR (y
))
443 SCM_ARRAY_BASE (SCM_CAR (z
)) = cind (SCM_CAR (y
), inds
);
444 if (0 == (SCM_UNBNDP (data
) ? cproc(vra0
, lvra
) : cproc(vra0
, data
, lvra
)))
449 if (vinds
[k
] < SCM_ARRAY_DIMS (ra0
)[k
].ubnd
)
455 vinds
[k
] = SCM_ARRAY_DIMS (ra0
)[k
].lbnd
- 1;
464 SCM_DEFINE (scm_array_fill_x
, "array-fill!", 2, 0, 0,
466 "Stores @var{fill} in every element of @var{array}. The value returned\n"
468 #define FUNC_NAME s_scm_array_fill_x
470 scm_ramapc (scm_array_fill_int
, fill
, ra
, SCM_EOL
, FUNC_NAME
);
471 return SCM_UNSPECIFIED
;
475 /* to be used as cproc in scm_ramapc to fill an array dimension with
478 scm_array_fill_int (SCM ra
, SCM fill
, SCM ignore
)
479 #define FUNC_NAME s_scm_array_fill_x
482 scm_sizet n
= SCM_ARRAY_DIMS (ra
)->ubnd
- SCM_ARRAY_DIMS (ra
)->lbnd
+ 1;
483 long inc
= SCM_ARRAY_DIMS (ra
)->inc
;
484 scm_sizet base
= SCM_ARRAY_BASE (ra
);
486 ra
= SCM_ARRAY_V (ra
);
490 for (i
= base
; n
--; i
+= inc
)
491 scm_array_set_x (ra
, fill
, SCM_MAKINUM (i
));
495 for (i
= base
; n
--; i
+= inc
)
496 SCM_VELTS (ra
)[i
] = fill
;
499 SCM_ASRTGO (SCM_CHARP (fill
), badarg2
);
500 for (i
= base
; n
--; i
+= inc
)
501 SCM_STRING_CHARS (ra
)[i
] = SCM_CHAR (fill
);
504 if (SCM_CHARP (fill
))
505 fill
= SCM_MAKINUM ((char) SCM_CHAR (fill
));
506 SCM_ASRTGO (SCM_INUMP (fill
)
507 && -128 <= SCM_INUM (fill
) && SCM_INUM (fill
) < 128,
509 for (i
= base
; n
--; i
+= inc
)
510 ((char *) SCM_UVECTOR_BASE (ra
))[i
] = SCM_INUM (fill
);
514 long *ve
= (long *) SCM_VELTS (ra
);
515 if (1 == inc
&& (n
>= SCM_LONG_BIT
|| n
== SCM_BITVECTOR_LENGTH (ra
)))
517 i
= base
/ SCM_LONG_BIT
;
518 if (SCM_FALSEP (fill
))
520 if (base
% SCM_LONG_BIT
) /* leading partial word */
521 ve
[i
++] &= ~(~0L << (base
% SCM_LONG_BIT
));
522 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
524 if ((base
+ n
) % SCM_LONG_BIT
) /* trailing partial word */
525 ve
[i
] &= (~0L << ((base
+ n
) % SCM_LONG_BIT
));
527 else if (SCM_EQ_P (fill
, SCM_BOOL_T
))
529 if (base
% SCM_LONG_BIT
)
530 ve
[i
++] |= ~0L << (base
% SCM_LONG_BIT
);
531 for (; i
< (base
+ n
) / SCM_LONG_BIT
; i
++)
533 if ((base
+ n
) % SCM_LONG_BIT
)
534 ve
[i
] |= ~(~0L << ((base
+ n
) % SCM_LONG_BIT
));
537 badarg2
:SCM_WRONG_TYPE_ARG (2, fill
);
541 if (SCM_FALSEP (fill
))
542 for (i
= base
; n
--; i
+= inc
)
543 ve
[i
/ SCM_LONG_BIT
] &= ~(1L << (i
% SCM_LONG_BIT
));
544 else if (SCM_EQ_P (fill
, SCM_BOOL_T
))
545 for (i
= base
; n
--; i
+= inc
)
546 ve
[i
/ SCM_LONG_BIT
] |= (1L << (i
% SCM_LONG_BIT
));
554 unsigned long f
= SCM_NUM2ULONG (2, fill
);
555 unsigned long *ve
= (unsigned long *) SCM_VELTS (ra
);
557 for (i
= base
; n
--; i
+= inc
)
563 long f
= SCM_NUM2LONG (2, fill
);
564 long *ve
= (long *) SCM_VELTS (ra
);
566 for (i
= base
; n
--; i
+= inc
)
571 SCM_ASRTGO (SCM_INUMP (fill
), badarg2
);
573 short f
= SCM_INUM (fill
);
574 short *ve
= (short *) SCM_VELTS (ra
);
576 if (f
!= SCM_INUM (fill
))
577 SCM_OUT_OF_RANGE (2, fill
);
578 for (i
= base
; n
--; i
+= inc
)
582 #ifdef HAVE_LONG_LONGS
585 long long f
= SCM_NUM2LONG_LONG (2, fill
);
586 long long *ve
= (long long *) SCM_VELTS (ra
);
588 for (i
= base
; n
--; i
+= inc
)
595 float f
, *ve
= (float *) SCM_VELTS (ra
);
596 SCM_ASRTGO (SCM_REALP (fill
), badarg2
);
597 f
= SCM_REAL_VALUE (fill
);
598 for (i
= base
; n
--; i
+= inc
)
604 double f
, *ve
= (double *) SCM_VELTS (ra
);
605 SCM_ASRTGO (SCM_REALP (fill
), badarg2
);
606 f
= SCM_REAL_VALUE (fill
);
607 for (i
= base
; n
--; i
+= inc
)
614 double (*ve
)[2] = (double (*)[2]) SCM_VELTS (ra
);
615 SCM_ASRTGO (SCM_INEXACTP (fill
), badarg2
);
616 if (SCM_REALP (fill
)) {
617 fr
= SCM_REAL_VALUE (fill
);
620 fr
= SCM_COMPLEX_REAL (fill
);
621 fi
= SCM_COMPLEX_IMAG (fill
);
623 for (i
= base
; n
--; i
+= inc
)
638 racp (SCM src
, SCM dst
)
640 long n
= (SCM_ARRAY_DIMS (src
)->ubnd
- SCM_ARRAY_DIMS (src
)->lbnd
+ 1);
641 long inc_d
, inc_s
= SCM_ARRAY_DIMS (src
)->inc
;
642 scm_sizet i_d
, i_s
= SCM_ARRAY_BASE (src
);
644 inc_d
= SCM_ARRAY_DIMS (dst
)->inc
;
645 i_d
= SCM_ARRAY_BASE (dst
);
646 src
= SCM_ARRAY_V (src
);
647 dst
= SCM_ARRAY_V (dst
);
649 switch SCM_TYP7 (dst
)
656 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
657 scm_array_set_x (dst
,
658 scm_cvref (src
, i_s
, SCM_UNDEFINED
),
662 if (SCM_TYP7 (src
) != scm_tc7_string
)
664 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
665 SCM_STRING_CHARS (dst
)[i_d
] = SCM_STRING_CHARS (src
)[i_s
];
668 if (SCM_TYP7 (src
) != scm_tc7_byvect
)
670 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
671 ((char *) SCM_UVECTOR_BASE (dst
))[i_d
]
672 = ((char *) SCM_UVECTOR_BASE (src
))[i_s
];
675 if (SCM_TYP7 (src
) != scm_tc7_bvect
)
677 if (1 == inc_d
&& 1 == inc_s
&& i_s
% SCM_LONG_BIT
== i_d
% SCM_LONG_BIT
&& n
>= SCM_LONG_BIT
)
679 long *sv
= (long *) SCM_VELTS (src
);
680 long *dv
= (long *) SCM_VELTS (dst
);
681 sv
+= i_s
/ SCM_LONG_BIT
;
682 dv
+= i_d
/ SCM_LONG_BIT
;
683 if (i_s
% SCM_LONG_BIT
)
684 { /* leading partial word */
685 *dv
= (*dv
& ~(~0L << (i_s
% SCM_LONG_BIT
))) | (*sv
& (~0L << (i_s
% SCM_LONG_BIT
)));
688 n
-= SCM_LONG_BIT
- (i_s
% SCM_LONG_BIT
);
691 for (; n
>= SCM_LONG_BIT
; n
-= SCM_LONG_BIT
, sv
++, dv
++)
693 if (n
) /* trailing partial word */
694 *dv
= (*dv
& (~0L << n
)) | (*sv
& ~(~0L << n
));
698 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
699 if (SCM_BITVEC_REF(src
, i_s
))
700 SCM_BITVEC_SET(dst
, i_d
);
702 SCM_BITVEC_CLR(dst
, i_d
);
706 if (scm_tc7_uvect
!= SCM_TYP7 (src
))
710 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
712 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
717 if (scm_tc7_uvect
!= SCM_TYP7 (src
) && scm_tc7_ivect
!= SCM_TYP7 (src
))
721 long *d
= (long *) SCM_VELTS (dst
), *s
= (long *) SCM_VELTS (src
);
723 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
729 float *d
= (float *) SCM_VELTS (dst
);
730 float *s
= (float *) SCM_VELTS (src
);
739 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
740 d
[i_d
] = ((long *) s
)[i_s
];)
744 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
749 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
750 d
[i_d
] = ((double *) s
)[i_s
];)
757 double *d
= (double *) SCM_VELTS (dst
);
758 double *s
= (double *) SCM_VELTS (src
);
767 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
768 d
[i_d
] = ((long *) s
)[i_s
];)
772 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
773 d
[i_d
] = ((float *) s
)[i_s
];)
777 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
785 double (*d
)[2] = (double (*)[2]) SCM_VELTS (dst
);
786 double (*s
)[2] = (double (*)[2]) SCM_VELTS (src
);
795 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
797 d
[i_d
][0] = ((long *) s
)[i_s
];
803 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
805 d
[i_d
][0] = ((float *) s
)[i_s
];
811 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
813 d
[i_d
][0] = ((double *) s
)[i_s
];
819 for (; n
-- > 0; i_s
+= inc_s
, i_d
+= inc_d
)
821 d
[i_d
][0] = s
[i_s
][0];
822 d
[i_d
][1] = s
[i_s
][1];
832 SCM_REGISTER_PROC(s_array_copy_in_order_x
, "array-copy-in-order!", 2, 0, 0, scm_array_copy_x
);
835 SCM_DEFINE (scm_array_copy_x
, "array-copy!", 2, 0, 0,
837 "@deffnx primitive array-copy-in-order! src dst\n"
838 "Copies every element from vector or array @var{source} to the\n"
839 "corresponding element of @var{destination}. @var{destination} must have\n"
840 "the same rank as @var{source}, and be at least as large in each\n"
841 "dimension. The order is unspecified.")
842 #define FUNC_NAME s_scm_array_copy_x
844 scm_ramapc (racp
, SCM_UNDEFINED
, src
, scm_cons (dst
, SCM_EOL
), FUNC_NAME
);
845 return SCM_UNSPECIFIED
;
849 /* Functions callable by ARRAY-MAP! */
853 scm_ra_eqp (SCM ra0
, SCM ras
)
855 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
856 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
857 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
858 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
859 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
860 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
861 ra0
= SCM_ARRAY_V (ra0
);
862 ra1
= SCM_ARRAY_V (ra1
);
863 ra2
= SCM_ARRAY_V (ra2
);
864 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
868 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
869 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
870 if (SCM_BITVEC_REF (ra0
, i0
))
871 if (SCM_FALSEP(scm_eq_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
872 SCM_BITVEC_CLR (ra0
, i0
);
876 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
877 if (SCM_BITVEC_REF (ra0
, i0
))
878 if (((unsigned long *) SCM_VELTS (ra1
))[i1
] != ((unsigned long *) SCM_VELTS (ra2
))[i2
])
879 SCM_BITVEC_CLR (ra0
, i0
);
882 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
883 if (SCM_BITVEC_REF (ra0
, i0
))
884 if (((signed long *) SCM_VELTS (ra1
))[i1
] != ((signed long *) SCM_VELTS (ra2
))[i2
])
885 SCM_BITVEC_CLR (ra0
, i0
);
888 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
889 if (SCM_BITVEC_REF (ra0
, i0
))
890 if (((float *) SCM_VELTS (ra1
))[i1
] != ((float *) SCM_VELTS (ra2
))[i2
])
891 SCM_BITVEC_CLR (ra0
, i0
);
894 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
895 if (SCM_BITVEC_REF (ra0
, i0
))
896 if (((double *) SCM_VELTS (ra1
))[i1
] != ((double *) SCM_VELTS (ra2
))[i2
])
897 SCM_BITVEC_CLR (ra0
, i0
);
900 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
901 if (SCM_BITVEC_REF (ra0
, i0
))
902 if (((double *) SCM_VELTS (ra1
))[2 * i1
] != ((double *) SCM_VELTS (ra2
))[2 * i2
] ||
903 ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1] != ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1])
904 SCM_BITVEC_CLR (ra0
, i0
);
910 /* opt 0 means <, nonzero means >= */
913 ra_compare (SCM ra0
,SCM ra1
,SCM ra2
,int opt
)
915 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
916 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
917 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
918 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
919 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
920 ra0
= SCM_ARRAY_V (ra0
);
921 ra1
= SCM_ARRAY_V (ra1
);
922 ra2
= SCM_ARRAY_V (ra2
);
923 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
927 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
928 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
929 if (SCM_BITVEC_REF (ra0
, i0
))
931 SCM_NFALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))) :
932 SCM_FALSEP (scm_less_p (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
933 SCM_BITVEC_CLR (ra0
, i0
);
937 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
939 if (SCM_BITVEC_REF (ra0
, i0
))
941 ((unsigned long *) SCM_VELTS (ra1
))[i1
] < ((unsigned long *) SCM_VELTS (ra2
))[i2
] :
942 ((unsigned long *) SCM_VELTS (ra1
))[i1
] >= ((unsigned long *) SCM_VELTS (ra2
))[i2
])
943 SCM_BITVEC_CLR (ra0
, i0
);
947 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
949 if (SCM_BITVEC_REF (ra0
, i0
))
951 ((signed long *) SCM_VELTS (ra1
))[i1
] < ((signed long *) SCM_VELTS (ra2
))[i2
] :
952 ((signed long *) SCM_VELTS (ra1
))[i1
] >= ((signed long *) SCM_VELTS (ra2
))[i2
])
953 SCM_BITVEC_CLR (ra0
, i0
);
957 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
958 if (SCM_BITVEC_REF(ra0
, i0
))
960 ((float *) SCM_VELTS (ra1
))[i1
] < ((float *) SCM_VELTS (ra2
))[i2
] :
961 ((float *) SCM_VELTS (ra1
))[i1
] >= ((float *) SCM_VELTS (ra2
))[i2
])
962 SCM_BITVEC_CLR (ra0
, i0
);
965 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
966 if (SCM_BITVEC_REF (ra0
, i0
))
968 ((double *) SCM_VELTS (ra1
))[i1
] < ((double *) SCM_VELTS (ra2
))[i2
] :
969 ((double *) SCM_VELTS (ra1
))[i1
] >= ((double *) SCM_VELTS (ra2
))[i2
])
970 SCM_BITVEC_CLR (ra0
, i0
);
979 scm_ra_lessp (SCM ra0
, SCM ras
)
981 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 0);
986 scm_ra_leqp (SCM ra0
, SCM ras
)
988 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 1);
993 scm_ra_grp (SCM ra0
, SCM ras
)
995 return ra_compare (ra0
, SCM_CAR (SCM_CDR (ras
)), SCM_CAR (ras
), 0);
1000 scm_ra_greqp (SCM ra0
, SCM ras
)
1002 return ra_compare (ra0
, SCM_CAR (ras
), SCM_CAR (SCM_CDR (ras
)), 1);
1007 scm_ra_sum (SCM ra0
, SCM ras
)
1009 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1010 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1011 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1012 ra0
= SCM_ARRAY_V (ra0
);
1013 if (SCM_NNULLP(ras
))
1015 SCM ra1
= SCM_CAR (ras
);
1016 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1017 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1018 ra1
= SCM_ARRAY_V (ra1
);
1019 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1023 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1024 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1025 scm_array_set_x (ra0
, scm_sum (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1031 BINARY_ELTS_CODE( +=, long);
1033 BINARY_ELTS_CODE( +=, float);
1035 BINARY_ELTS_CODE( +=, double);
1037 BINARY_PAIR_ELTS_CODE( +=, double);
1046 scm_ra_difference (SCM ra0
, SCM 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
,
1061 scm_difference (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
),
1066 UNARY_ELTS_CODE( = -, float);
1068 UNARY_ELTS_CODE( = -, double);
1070 UNARY_PAIR_ELTS_CODE( = -, double);
1075 SCM ra1
= SCM_CAR (ras
);
1076 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1077 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1078 ra1
= SCM_ARRAY_V (ra1
);
1079 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1083 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1084 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1085 scm_array_set_x (ra0
, scm_difference (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1089 BINARY_ELTS_CODE( -=, float);
1091 BINARY_ELTS_CODE( -=, double);
1093 BINARY_PAIR_ELTS_CODE( -=, double);
1102 scm_ra_product (SCM ra0
, SCM ras
)
1104 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1105 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1106 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1107 ra0
= SCM_ARRAY_V (ra0
);
1108 if (SCM_NNULLP (ras
))
1110 SCM ra1
= SCM_CAR (ras
);
1111 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1112 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1113 ra1
= SCM_ARRAY_V (ra1
);
1114 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1118 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1119 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1120 scm_array_set_x (ra0
, scm_product (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1126 BINARY_ELTS_CODE( *=, long);
1128 BINARY_ELTS_CODE( *=, float);
1130 BINARY_ELTS_CODE( *=, double);
1133 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1135 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1137 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1139 r
= v0
[i0
][0] * v1
[i1
][0] - v0
[i0
][1] * v1
[i1
][1];
1140 v0
[i0
][1] = v0
[i0
][0] * v1
[i1
][1] + v0
[i0
][1] * v1
[i1
][0];
1153 scm_ra_divide (SCM ra0
, SCM 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_NULLP (ras
))
1161 switch (SCM_TYP7 (ra0
))
1165 SCM e0
= SCM_UNDEFINED
;
1166 for (; n
-- > 0; i0
+= inc0
)
1167 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1171 UNARY_ELTS_CODE( = 1.0 / , float);
1173 UNARY_ELTS_CODE( = 1.0 / , double);
1177 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1178 for (; n
-- > 0; i0
+= inc0
)
1180 d
= v0
[i0
][0] * v0
[i0
][0] + v0
[i0
][1] * v0
[i0
][1];
1190 SCM ra1
= SCM_CAR (ras
);
1191 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1192 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1193 ra1
= SCM_ARRAY_V (ra1
);
1194 switch (SCM_TYP7 (ra0
) == SCM_TYP7 (ra1
) ? SCM_TYP7 (ra0
) : 0)
1198 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1199 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1200 scm_array_set_x (ra0
, scm_divide (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1204 BINARY_ELTS_CODE( /=, float);
1206 BINARY_ELTS_CODE( /=, double);
1209 register double d
, r
;
1210 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
);
1211 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
);
1213 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1215 d
= v1
[i1
][0] * v1
[i1
][0] + v1
[i1
][1] * v1
[i1
][1];
1216 r
= (v0
[i0
][0] * v1
[i1
][0] + v0
[i0
][1] * v1
[i1
][1]) / d
;
1217 v0
[i0
][1] = (v0
[i0
][1] * v1
[i1
][0] - v0
[i0
][0] * v1
[i1
][1]) / d
;
1230 scm_array_identity (SCM dst
, SCM src
)
1232 return racp (SCM_CAR (src
), scm_cons (dst
, SCM_EOL
));
1238 ramap (SCM ra0
,SCM proc
,SCM ras
)
1240 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1241 long inc
= SCM_ARRAY_DIMS (ra0
)->inc
;
1242 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1243 long base
= SCM_ARRAY_BASE (ra0
) - i
* inc
;
1244 ra0
= SCM_ARRAY_V (ra0
);
1245 if (SCM_NULLP (ras
))
1247 scm_array_set_x (ra0
, scm_apply (proc
, SCM_EOL
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1250 SCM ra1
= SCM_CAR (ras
);
1251 SCM args
, *ve
= &ras
;
1252 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1253 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1254 ra1
= SCM_ARRAY_V (ra1
);
1255 ras
= SCM_CDR (ras
);
1260 ras
= scm_vector (ras
);
1261 ve
= SCM_VELTS (ras
);
1263 for (; i
<= n
; i
++, i1
+= inc1
)
1266 for (k
= SCM_INUM (scm_uniform_vector_length (ras
)); k
--;)
1267 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1268 args
= scm_cons (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1269 scm_array_set_x (ra0
, scm_apply (proc
, args
, SCM_EOL
), SCM_MAKINUM (i
* inc
+ base
));
1277 ramap_cxr (SCM ra0
,SCM proc
,SCM ras
)
1279 SCM ra1
= SCM_CAR (ras
);
1280 SCM e1
= SCM_UNDEFINED
;
1281 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1282 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1283 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra1
)->lbnd
+ 1;
1284 ra0
= SCM_ARRAY_V (ra0
);
1285 ra1
= SCM_ARRAY_V (ra1
);
1286 switch (SCM_TYP7 (ra0
))
1290 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1291 scm_array_set_x (ra0
, scm_apply (proc
, RVREF (ra1
, i1
, e1
), scm_listofnull
), SCM_MAKINUM (i0
));
1295 float *dst
= (float *) SCM_VELTS (ra0
);
1296 switch (SCM_TYP7 (ra1
))
1301 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1302 dst
[i0
] = SCM_DSUBRF (proc
) ((double) ((float *) SCM_VELTS (ra1
))[i1
]);
1306 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1307 dst
[i0
] = SCM_DSUBRF (proc
) (SCM_UNPACK (SCM_VELTS (ra1
)[i1
]));
1314 double *dst
= (double *) SCM_VELTS (ra0
);
1315 switch (SCM_TYP7 (ra1
))
1320 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1321 dst
[i0
] = SCM_DSUBRF (proc
) (((double *) SCM_VELTS (ra1
))[i1
]);
1325 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1326 dst
[i0
] = SCM_DSUBRF (proc
) (SCM_UNPACK (SCM_VELTS (ra1
)[i1
]));
1338 ramap_rp (SCM ra0
,SCM proc
,SCM ras
)
1340 SCM ra1
= SCM_CAR (ras
), ra2
= SCM_CAR (SCM_CDR (ras
));
1341 SCM e1
= SCM_UNDEFINED
, e2
= SCM_UNDEFINED
;
1342 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1343 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
), i2
= SCM_ARRAY_BASE (ra2
);
1344 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1345 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1346 long inc2
= SCM_ARRAY_DIMS (ra1
)->inc
;
1347 ra0
= SCM_ARRAY_V (ra0
);
1348 ra1
= SCM_ARRAY_V (ra1
);
1349 ra2
= SCM_ARRAY_V (ra2
);
1350 switch (SCM_TYP7 (ra1
) == SCM_TYP7 (ra2
) ? SCM_TYP7 (ra1
) : 0)
1353 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1354 if (SCM_BITVEC_REF (ra0
, i0
))
1355 if (SCM_FALSEP (SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
))))
1356 SCM_BITVEC_CLR (ra0
, i0
);
1360 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1361 if (SCM_BITVEC_REF (ra0
, i0
))
1363 /* DIRK:FIXME:: There should be a way to access the elements
1364 of a cell as raw data. Further: How can we be sure that
1365 the values fit into an inum?
1367 SCM n1
= SCM_MAKINUM (((long *) SCM_UNPACK (SCM_CDR (ra1
)))[i1
]);
1368 SCM n2
= SCM_MAKINUM (((long *) SCM_UNPACK (SCM_CDR (ra2
)))[i2
]);
1369 if (SCM_FALSEP (SCM_SUBRF (proc
) (n1
, n2
)));
1370 SCM_BITVEC_CLR (ra0
, i0
);
1375 SCM a1
= scm_make_real (1.0), a2
= scm_make_real (1.0);
1376 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1377 if (SCM_BITVEC_REF (ra0
, i0
))
1379 SCM_REAL_VALUE (a1
) = ((float *) SCM_VELTS (ra1
))[i1
];
1380 SCM_REAL_VALUE (a2
) = ((float *) SCM_VELTS (ra2
))[i2
];
1381 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1382 SCM_BITVEC_CLR (ra0
, i0
);
1388 SCM a1
= scm_make_real (1.0 / 3.0);
1389 SCM a2
= scm_make_real (1.0 / 3.0);
1390 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1391 if (SCM_BITVEC_REF (ra0
, i0
))
1393 SCM_REAL_VALUE (a1
) = ((double *) SCM_VELTS (ra1
))[i1
];
1394 SCM_REAL_VALUE (a2
) = ((double *) SCM_VELTS (ra2
))[i2
];
1395 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1396 SCM_BITVEC_CLR (ra0
, i0
);
1402 SCM a1
= scm_make_complex (1.0, 1.0);
1403 SCM a2
= scm_make_complex (1.0, 1.0);
1404 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1405 if (SCM_BITVEC_REF (ra0
, i0
))
1407 SCM_COMPLEX_REAL (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
];
1408 SCM_COMPLEX_IMAG (a1
) = ((double *) SCM_VELTS (ra1
))[2 * i1
+ 1];
1409 SCM_COMPLEX_REAL (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
];
1410 SCM_COMPLEX_IMAG (a2
) = ((double *) SCM_VELTS (ra2
))[2 * i2
+ 1];
1411 if (SCM_FALSEP (SCM_SUBRF (proc
) (a1
, a2
)))
1412 SCM_BITVEC_CLR (ra0
, i0
);
1423 ramap_1 (SCM ra0
,SCM proc
,SCM ras
)
1425 SCM ra1
= SCM_CAR (ras
);
1426 SCM e1
= SCM_UNDEFINED
;
1427 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1428 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1429 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1430 ra0
= SCM_ARRAY_V (ra0
);
1431 ra1
= SCM_ARRAY_V (ra1
);
1432 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1433 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1434 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
)), SCM_MAKINUM (i0
));
1436 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1437 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
)), SCM_MAKINUM (i0
));
1444 ramap_2o (SCM ra0
,SCM proc
,SCM ras
)
1446 SCM ra1
= SCM_CAR (ras
);
1447 SCM e1
= SCM_UNDEFINED
;
1448 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1449 scm_sizet i0
= SCM_ARRAY_BASE (ra0
), i1
= SCM_ARRAY_BASE (ra1
);
1450 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
, inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1451 ra0
= SCM_ARRAY_V (ra0
);
1452 ra1
= SCM_ARRAY_V (ra1
);
1453 ras
= SCM_CDR (ras
);
1454 if (SCM_NULLP (ras
))
1456 if (scm_tc7_vector
== SCM_TYP7 (ra0
)
1457 || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1459 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1460 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), SCM_UNDEFINED
),
1463 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1464 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), SCM_UNDEFINED
),
1469 SCM ra2
= SCM_CAR (ras
);
1470 SCM e2
= SCM_UNDEFINED
;
1471 scm_sizet i2
= SCM_ARRAY_BASE (ra2
);
1472 long inc2
= SCM_ARRAY_DIMS (ra2
)->inc
;
1473 ra2
= SCM_ARRAY_V (ra2
);
1474 if (scm_tc7_vector
== SCM_TYP7 (ra0
) || scm_tc7_wvect
== SCM_TYP7 (ra0
))
1475 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1476 scm_array_set_x (ra0
,
1477 SCM_SUBRF (proc
) (scm_cvref (ra1
, i1
, SCM_UNDEFINED
), scm_cvref (ra2
, i2
, SCM_UNDEFINED
)),
1480 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
, i2
+= inc2
)
1481 scm_array_set_x (ra0
,
1482 SCM_SUBRF (proc
) (RVREF (ra1
, i1
, e1
), RVREF (ra2
, i2
, e2
)),
1491 ramap_a (SCM ra0
,SCM proc
,SCM ras
)
1493 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1494 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1495 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1496 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1497 ra0
= SCM_ARRAY_V (ra0
);
1498 if (SCM_NULLP (ras
))
1499 for (; n
-- > 0; i0
+= inc0
)
1500 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), SCM_UNDEFINED
), SCM_MAKINUM (i0
));
1503 SCM ra1
= SCM_CAR (ras
);
1504 scm_sizet i1
= SCM_ARRAY_BASE (ra1
);
1505 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1506 ra1
= SCM_ARRAY_V (ra1
);
1507 for (; n
-- > 0; i0
+= inc0
, i1
+= inc1
)
1508 scm_array_set_x (ra0
, SCM_SUBRF (proc
) (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
)),
1515 SCM_REGISTER_PROC(s_array_map_in_order_x
, "array-map-in-order!", 2, 0, 1, scm_array_map_x
);
1518 SCM_DEFINE (scm_array_map_x
, "array-map!", 2, 0, 1,
1519 (SCM ra0
, SCM proc
, SCM lra
),
1520 "@deffnx primitive array-map-in-order! ra0 proc . lra\n"
1521 "@var{array1}, @dots{} must have the same number of dimensions as\n"
1522 "@var{array0} and have a range for each index which includes the range\n"
1523 "for the corresponding index in @var{array0}. @var{proc} is applied to\n"
1524 "each tuple of elements of @var{array1} @dots{} and the result is stored\n"
1525 "as the corresponding element in @var{array0}. The value returned is\n"
1526 "unspecified. The order of application is unspecified.")
1527 #define FUNC_NAME s_scm_array_map_x
1529 SCM_VALIDATE_PROC (2,proc
);
1530 SCM_VALIDATE_REST_ARGUMENT (lra
);
1531 switch (SCM_TYP7 (proc
))
1535 scm_ramapc (ramap
, proc
, ra0
, lra
, FUNC_NAME
);
1536 return SCM_UNSPECIFIED
;
1537 case scm_tc7_subr_1
:
1538 scm_ramapc (ramap_1
, proc
, ra0
, lra
, FUNC_NAME
);
1539 return SCM_UNSPECIFIED
;
1540 case scm_tc7_subr_2
:
1541 case scm_tc7_subr_2o
:
1542 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, FUNC_NAME
);
1543 return SCM_UNSPECIFIED
;
1545 if (!SCM_SUBRF (proc
))
1547 scm_ramapc (ramap_cxr
, proc
, ra0
, lra
, FUNC_NAME
);
1548 return SCM_UNSPECIFIED
;
1549 case scm_tc7_rpsubr
:
1552 if (SCM_FALSEP (scm_array_p (ra0
, SCM_BOOL_T
)))
1554 scm_array_fill_x (ra0
, SCM_BOOL_T
);
1555 for (p
= ra_rpsubrs
; p
->name
; p
++)
1556 if (SCM_EQ_P (proc
, p
->sproc
))
1558 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1560 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, FUNC_NAME
);
1561 lra
= SCM_CDR (lra
);
1563 return SCM_UNSPECIFIED
;
1565 while (SCM_NNULLP (lra
) && SCM_NNULLP (SCM_CDR (lra
)))
1567 scm_ramapc (ramap_rp
, proc
, ra0
, lra
, FUNC_NAME
);
1568 lra
= SCM_CDR (lra
);
1570 return SCM_UNSPECIFIED
;
1573 if (SCM_NULLP (lra
))
1575 SCM prot
, fill
= SCM_SUBRF (proc
) (SCM_UNDEFINED
, SCM_UNDEFINED
);
1576 if (SCM_INUMP(fill
))
1578 prot
= scm_array_prototype (ra0
);
1579 if (SCM_INEXACTP (prot
))
1580 fill
= scm_make_real ((double) SCM_INUM (fill
));
1583 scm_array_fill_x (ra0
, fill
);
1587 SCM tail
, ra1
= SCM_CAR (lra
);
1588 SCM v0
= (SCM_ARRAYP (ra0
) ? SCM_ARRAY_V (ra0
) : ra0
);
1590 /* Check to see if order might matter.
1591 This might be an argument for a separate
1592 SERIAL-ARRAY-MAP! */
1593 if (SCM_EQ_P (v0
, ra1
)
1594 || (SCM_ARRAYP (ra1
) && SCM_EQ_P (v0
, SCM_ARRAY_V (ra1
))))
1595 if (!SCM_EQ_P (ra0
, ra1
)
1596 || (SCM_ARRAYP(ra0
) && !SCM_ARRAY_CONTP(ra0
)))
1598 for (tail
= SCM_CDR (lra
); SCM_NNULLP (tail
); tail
= SCM_CDR (tail
))
1600 ra1
= SCM_CAR (tail
);
1601 if (SCM_EQ_P (v0
, ra1
)
1602 || (SCM_ARRAYP (ra1
) && SCM_EQ_P (v0
, SCM_ARRAY_V (ra1
))))
1605 for (p
= ra_asubrs
; p
->name
; p
++)
1606 if (SCM_EQ_P (proc
, p
->sproc
))
1608 if (!SCM_EQ_P (ra0
, SCM_CAR (lra
)))
1609 scm_ramapc (scm_array_identity
, SCM_UNDEFINED
, ra0
, scm_cons (SCM_CAR (lra
), SCM_EOL
), FUNC_NAME
);
1610 lra
= SCM_CDR (lra
);
1613 scm_ramapc (p
->vproc
, SCM_UNDEFINED
, ra0
, lra
, FUNC_NAME
);
1614 if (SCM_IMP (lra
) || SCM_IMP (SCM_CDR (lra
)))
1615 return SCM_UNSPECIFIED
;
1616 lra
= SCM_CDR (lra
);
1619 scm_ramapc (ramap_2o
, proc
, ra0
, lra
, FUNC_NAME
);
1620 lra
= SCM_CDR (lra
);
1622 for (lra
= SCM_CDR (lra
); SCM_NIMP (lra
); lra
= SCM_CDR (lra
))
1623 scm_ramapc (ramap_a
, proc
, ra0
, lra
, FUNC_NAME
);
1625 return SCM_UNSPECIFIED
;
1632 rafe (SCM ra0
,SCM proc
,SCM ras
)
1634 long i
= SCM_ARRAY_DIMS (ra0
)->lbnd
;
1635 scm_sizet i0
= SCM_ARRAY_BASE (ra0
);
1636 long inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1637 long n
= SCM_ARRAY_DIMS (ra0
)->ubnd
;
1638 ra0
= SCM_ARRAY_V (ra0
);
1639 if (SCM_NULLP (ras
))
1640 for (; i
<= n
; i
++, i0
+= inc0
)
1641 scm_apply (proc
, scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_listofnull
);
1644 SCM ra1
= SCM_CAR (ras
);
1645 SCM args
, *ve
= &ras
;
1646 scm_sizet k
, i1
= SCM_ARRAY_BASE (ra1
);
1647 long inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1648 ra1
= SCM_ARRAY_V (ra1
);
1649 ras
= SCM_CDR (ras
);
1654 ras
= scm_vector (ras
);
1655 ve
= SCM_VELTS (ras
);
1657 for (; i
<= n
; i
++, i0
+= inc0
, i1
+= inc1
)
1660 for (k
= SCM_INUM (scm_uniform_vector_length (ras
)); k
--;)
1661 args
= scm_cons (scm_uniform_vector_ref (ve
[k
], SCM_MAKINUM (i
)), args
);
1662 args
= scm_cons2 (scm_cvref (ra0
, i0
, SCM_UNDEFINED
), scm_cvref (ra1
, i1
, SCM_UNDEFINED
), args
);
1663 scm_apply (proc
, args
, SCM_EOL
);
1670 SCM_DEFINE (scm_array_for_each
, "array-for-each", 2, 0, 1,
1671 (SCM proc
, SCM ra0
, SCM lra
),
1672 "@var{proc} is applied to each tuple of elements of @var{array0} @dots{}\n"
1673 "in row-major order. The value returned is unspecified.")
1674 #define FUNC_NAME s_scm_array_for_each
1676 SCM_VALIDATE_PROC (1,proc
);
1677 SCM_VALIDATE_REST_ARGUMENT (lra
);
1678 scm_ramapc (rafe
, proc
, ra0
, lra
, FUNC_NAME
);
1679 return SCM_UNSPECIFIED
;
1683 SCM_DEFINE (scm_array_index_map_x
, "array-index-map!", 2, 0, 0,
1685 "applies @var{proc} to the indices of each element of @var{array} in\n"
1686 "turn, storing the result in the corresponding element. The value\n"
1687 "returned and the order of application are unspecified.\n\n"
1688 "One can implement @var{array-indexes} as\n"
1690 "(define (array-indexes array)\n"
1691 " (let ((ra (apply make-array #f (array-shape array))))\n"
1692 " (array-index-map! ra (lambda x x))\n"
1695 "Another example:\n"
1697 "(define (apl:index-generator n)\n"
1698 " (let ((v (make-uniform-vector n 1)))\n"
1699 " (array-index-map! v (lambda (i) i))\n"
1702 #define FUNC_NAME s_scm_array_index_map_x
1705 SCM_VALIDATE_NIM (1,ra
);
1706 SCM_VALIDATE_PROC (2,proc
);
1707 switch (SCM_TYP7(ra
))
1710 badarg
:SCM_WRONG_TYPE_ARG (1, ra
);
1711 case scm_tc7_vector
:
1714 SCM
*ve
= SCM_VELTS (ra
);
1715 for (i
= 0; i
< SCM_VECTOR_LENGTH (ra
); i
++)
1716 ve
[i
] = scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
);
1717 return SCM_UNSPECIFIED
;
1719 case scm_tc7_string
:
1720 case scm_tc7_byvect
:
1725 #ifdef HAVE_LONG_LONGS
1726 case scm_tc7_llvect
:
1732 unsigned long int length
= SCM_INUM (scm_uniform_vector_length (ra
));
1733 for (i
= 0; i
< length
; i
++)
1734 scm_array_set_x (ra
, scm_apply (proc
, SCM_MAKINUM (i
), scm_listofnull
),
1736 return SCM_UNSPECIFIED
;
1739 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
1742 SCM inds
= scm_make_uve (SCM_ARRAY_NDIM (ra
), SCM_MAKINUM (-1L));
1743 long *vinds
= (long *) SCM_VELTS (inds
);
1744 int j
, k
, kmax
= SCM_ARRAY_NDIM (ra
) - 1;
1746 return scm_array_set_x (ra
, scm_apply(proc
, SCM_EOL
, SCM_EOL
),
1748 for (k
= 0; k
<= kmax
; k
++)
1749 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1755 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1756 i
= cind (ra
, inds
);
1757 for (; vinds
[k
] <= SCM_ARRAY_DIMS (ra
)[k
].ubnd
; vinds
[k
]++)
1759 for (j
= kmax
+ 1, args
= SCM_EOL
; j
--;)
1760 args
= scm_cons (SCM_MAKINUM (vinds
[j
]), args
);
1761 scm_array_set_x (SCM_ARRAY_V (ra
),
1762 scm_apply (proc
, args
, SCM_EOL
),
1764 i
+= SCM_ARRAY_DIMS (ra
)[k
].inc
;
1769 if (vinds
[k
] < SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
1775 vinds
[k
] = SCM_ARRAY_DIMS (ra
)[k
].lbnd
- 1;
1779 return SCM_UNSPECIFIED
;
1787 raeql_1 (SCM ra0
,SCM as_equal
,SCM ra1
)
1789 SCM e0
= SCM_UNDEFINED
, e1
= SCM_UNDEFINED
;
1790 scm_sizet i0
= 0, i1
= 0;
1791 long inc0
= 1, inc1
= 1;
1793 ra1
= SCM_CAR (ra1
);
1794 if (SCM_ARRAYP(ra0
))
1796 n
= SCM_ARRAY_DIMS (ra0
)->ubnd
- SCM_ARRAY_DIMS (ra0
)->lbnd
+ 1;
1797 i0
= SCM_ARRAY_BASE (ra0
);
1798 inc0
= SCM_ARRAY_DIMS (ra0
)->inc
;
1799 ra0
= SCM_ARRAY_V (ra0
);
1802 n
= SCM_INUM (scm_uniform_vector_length (ra0
));
1803 if (SCM_ARRAYP (ra1
))
1805 i1
= SCM_ARRAY_BASE (ra1
);
1806 inc1
= SCM_ARRAY_DIMS (ra1
)->inc
;
1807 ra1
= SCM_ARRAY_V (ra1
);
1809 switch (SCM_TYP7 (ra0
))
1811 case scm_tc7_vector
:
1814 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1816 if (SCM_FALSEP (as_equal
))
1818 if (SCM_FALSEP (scm_array_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
))))
1821 else if (SCM_FALSEP (scm_equal_p (RVREF (ra0
, i0
, e0
), RVREF (ra1
, i1
, e1
))))
1825 case scm_tc7_string
:
1827 char *v0
= SCM_STRING_CHARS (ra0
) + i0
;
1828 char *v1
= SCM_STRING_CHARS (ra1
) + i1
;
1829 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1834 case scm_tc7_byvect
:
1836 char *v0
= ((char *) SCM_UVECTOR_BASE (ra0
)) + i0
;
1837 char *v1
= ((char *) SCM_UVECTOR_BASE (ra1
)) + i1
;
1838 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1844 for (; n
--; i0
+= inc0
, i1
+= inc1
)
1845 if (SCM_BITVEC_REF (ra0
, i0
) != SCM_BITVEC_REF (ra1
, i1
))
1851 long *v0
= (long *) SCM_VELTS (ra0
) + i0
;
1852 long *v1
= (long *) SCM_VELTS (ra1
) + i1
;
1853 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1860 short *v0
= (short *) SCM_VELTS (ra0
) + i0
;
1861 short *v1
= (short *) SCM_VELTS (ra1
) + i1
;
1862 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1867 #ifdef HAVE_LONG_LONGS
1868 case scm_tc7_llvect
:
1870 long long *v0
= (long long *) SCM_VELTS (ra0
) + i0
;
1871 long long *v1
= (long long *) SCM_VELTS (ra1
) + i1
;
1872 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1880 float *v0
= (float *) SCM_VELTS (ra0
) + i0
;
1881 float *v1
= (float *) SCM_VELTS (ra1
) + i1
;
1882 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1889 double *v0
= (double *) SCM_VELTS (ra0
) + i0
;
1890 double *v1
= (double *) SCM_VELTS (ra1
) + i1
;
1891 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1898 double (*v0
)[2] = (double (*)[2]) SCM_VELTS (ra0
) + i0
;
1899 double (*v1
)[2] = (double (*)[2]) SCM_VELTS (ra1
) + i1
;
1900 for (; n
--; v0
+= inc0
, v1
+= inc1
)
1902 if ((*v0
)[0] != (*v1
)[0])
1904 if ((*v0
)[1] != (*v1
)[1])
1915 raeql (SCM ra0
,SCM as_equal
,SCM ra1
)
1917 SCM v0
= ra0
, v1
= ra1
;
1918 scm_array_dim dim0
, dim1
;
1919 scm_array_dim
*s0
= &dim0
, *s1
= &dim1
;
1920 scm_sizet bas0
= 0, bas1
= 0;
1921 int k
, unroll
= 1, vlen
= 1, ndim
= 1;
1922 if (SCM_ARRAYP (ra0
))
1924 ndim
= SCM_ARRAY_NDIM (ra0
);
1925 s0
= SCM_ARRAY_DIMS (ra0
);
1926 bas0
= SCM_ARRAY_BASE (ra0
);
1927 v0
= SCM_ARRAY_V (ra0
);
1933 s0
->ubnd
= SCM_INUM (scm_uniform_vector_length (v0
)) - 1;
1936 if (SCM_ARRAYP (ra1
))
1938 if (ndim
!= SCM_ARRAY_NDIM (ra1
))
1940 s1
= SCM_ARRAY_DIMS (ra1
);
1941 bas1
= SCM_ARRAY_BASE (ra1
);
1942 v1
= SCM_ARRAY_V (ra1
);
1947 Huh ? Schizophrenic return type. --hwn
1953 s1
->ubnd
= SCM_INUM (scm_uniform_vector_length (v1
)) - 1;
1956 if (SCM_TYP7 (v0
) != SCM_TYP7 (v1
))
1958 for (k
= ndim
; k
--;)
1960 if (s0
[k
].lbnd
!= s1
[k
].lbnd
|| s0
[k
].ubnd
!= s1
[k
].ubnd
)
1964 unroll
= (s0
[k
].inc
== s1
[k
].inc
);
1965 vlen
*= s0
[k
].ubnd
- s1
[k
].lbnd
+ 1;
1968 if (unroll
&& bas0
== bas1
&& SCM_EQ_P (v0
, v1
))
1970 return scm_ramapc (raeql_1
, as_equal
, ra0
, scm_cons (ra1
, SCM_EOL
), "");
1975 scm_raequal (SCM ra0
, SCM ra1
)
1977 return SCM_BOOL(raeql (ra0
, SCM_BOOL_T
, ra1
));
1981 /* GJB:FIXME:: Why not use SCM_DEFINE1 for array-equal? */
1982 SCM_DEFINE1 (scm_array_equal_p
, "array-equal?", scm_tc7_rpsubr
,
1984 "Return @code{#t} iff all arguments are arrays with the same\n"
1985 "shape, the same type, and have corresponding elements which are\n"
1986 "either @code{equal?} or @code{array-equal?}. This function\n"
1987 "differs from @code{equal?} in that a one dimensional shared\n"
1988 "array may be @var{array-equal?} but not @var{equal?} to a\n"
1989 "vector or uniform vector.")
1990 #define FUNC_NAME s_scm_array_equal_p
1996 static char s_array_equal_p
[] = "array-equal?";
2000 scm_array_equal_p (SCM ra0
, SCM ra1
)
2002 if (SCM_IMP (ra0
) || SCM_IMP (ra1
))
2003 callequal
:return scm_equal_p (ra0
, ra1
);
2004 switch (SCM_TYP7(ra0
))
2009 case scm_tc7_string
:
2010 case scm_tc7_byvect
:
2016 case scm_tc7_vector
:
2020 if (!SCM_ARRAYP (ra0
))
2023 switch (SCM_TYP7 (ra1
))
2028 case scm_tc7_string
:
2029 case scm_tc7_byvect
:
2035 case scm_tc7_vector
:
2039 if (!SCM_ARRAYP (ra1
))
2042 return SCM_BOOL(raeql (ra0
, SCM_BOOL_F
, ra1
));
2047 init_raprocs (ra_iproc
*subra
)
2049 for (; subra
->name
; subra
++)
2051 SCM sym
= scm_str2symbol (subra
->name
);
2053 scm_sym2var (sym
, scm_current_module_lookup_closure (), SCM_BOOL_F
);
2054 if (var
!= SCM_BOOL_F
)
2055 subra
->sproc
= SCM_VARIABLE_REF (var
);
2057 subra
->sproc
= SCM_BOOL_F
;
2065 init_raprocs (ra_rpsubrs
);
2066 init_raprocs (ra_asubrs
);
2067 scm_make_subr (s_array_equal_p
, scm_tc7_rpsubr
, scm_array_equal_p
);
2068 scm_smobs
[SCM_TC2SMOBNUM (scm_tc16_array
)].equalp
= scm_raequal
;
2069 #ifndef SCM_MAGIC_SNARFER
2070 #include "libguile/ramap.x"
2072 scm_add_feature (s_scm_array_for_each
);