mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
fix equal? between an array and a non-array
OK let's try again. While the thanks go to Daniel Llorens del Río for the tip, the blame continues going to me :) * test-suite/Makefile.am: * test-suite/tests/arrays.test: Add a test. * libguile/array-map.c (raeql): Handle a few 0-dimensional cases. If the shapes of the arrays don't match, just return #f instead of raising an error.
This commit is contained in:
parent
d26383f427
commit
3ffd1ba96e
3 changed files with 39 additions and 7 deletions
|
@ -863,20 +863,29 @@ raeql (SCM ra0, SCM as_equal, SCM ra1)
|
|||
scm_t_array_dim *s0 = &dim0, *s1 = &dim1;
|
||||
unsigned long bas0 = 0, bas1 = 0;
|
||||
int k, unroll = 1, vlen = 1, ndim = 1;
|
||||
|
||||
if (SCM_I_ARRAYP (ra0))
|
||||
{
|
||||
if (SCM_I_ARRAY_NDIM (ra0) == 0)
|
||||
return scm_is_true (scm_equal_p (scm_array_ref (ra0, SCM_EOL), ra1));
|
||||
ndim = SCM_I_ARRAY_NDIM (ra0);
|
||||
s0 = SCM_I_ARRAY_DIMS (ra0);
|
||||
bas0 = SCM_I_ARRAY_BASE (ra0);
|
||||
v0 = SCM_I_ARRAY_V (ra0);
|
||||
}
|
||||
else
|
||||
else if (scm_is_generalized_vector (v0))
|
||||
{
|
||||
s0->inc = 1;
|
||||
s0->lbnd = 0;
|
||||
s0->ubnd = scm_c_generalized_vector_length (v0) - 1;
|
||||
unroll = 0;
|
||||
}
|
||||
else if (SCM_I_ARRAYP (ra1) && SCM_I_ARRAY_NDIM (ra1) == 0)
|
||||
return scm_is_true (scm_equal_p (ra0, scm_array_ref (ra1, SCM_EOL)));
|
||||
else
|
||||
/* It's just not working out, dear. */
|
||||
return 0;
|
||||
|
||||
if (SCM_I_ARRAYP (ra1))
|
||||
{
|
||||
if (ndim != SCM_I_ARRAY_NDIM (ra1))
|
||||
|
@ -885,18 +894,17 @@ raeql (SCM ra0, SCM as_equal, SCM ra1)
|
|||
bas1 = SCM_I_ARRAY_BASE (ra1);
|
||||
v1 = SCM_I_ARRAY_V (ra1);
|
||||
}
|
||||
else
|
||||
else if (scm_is_generalized_vector (v1))
|
||||
{
|
||||
/*
|
||||
Huh ? Schizophrenic return type. --hwn
|
||||
*/
|
||||
if (1 != ndim)
|
||||
return 0;
|
||||
s1->inc = 1;
|
||||
s1->lbnd = 0;
|
||||
s1->ubnd = scm_c_generalized_vector_length (v1) - 1;
|
||||
unroll = 0;
|
||||
}
|
||||
else
|
||||
/* It's not you, it's me. */
|
||||
return 0;
|
||||
|
||||
if (SCM_TYP7 (v0) != SCM_TYP7 (v1))
|
||||
return 0;
|
||||
for (k = ndim; k--;)
|
||||
|
|
|
@ -24,6 +24,7 @@ SUBDIRS = standalone
|
|||
SCM_TESTS = tests/alist.test \
|
||||
tests/and-let-star.test \
|
||||
tests/arbiters.test \
|
||||
tests/arrays.test \
|
||||
tests/asm-to-bytecode.test \
|
||||
tests/bit-operations.test \
|
||||
tests/brainfuck.test \
|
||||
|
|
23
test-suite/tests/arrays.test
Normal file
23
test-suite/tests/arrays.test
Normal file
|
@ -0,0 +1,23 @@
|
|||
;;;; arrays.test --- tests guile's arrays -*- scheme -*-
|
||||
;;;;
|
||||
;;;; Copyright 2010 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; This library is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;;; License as published by the Free Software Foundation; either
|
||||
;;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This library is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;;; Lesser General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;;; License along with this library; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
(define-module (test-suite test-unif)
|
||||
#:use-module (test-suite lib))
|
||||
|
||||
(pass-if "equal? on array and non-array"
|
||||
(not (equal? #2f64((0 1) (2 3)) 100)))
|
Loading…
Add table
Add a link
Reference in a new issue