1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00
Commit graph

16580 commits

Author SHA1 Message Date
Daniel Llorens
257e163c75 Arrays are not an array implementation
* libguile/bitvectors.c: match other uses of SCM_ARRAY_IMPLEMENTATION.
* libguile/generalized-arrays.c
  (scm_is_array): don't use scm_i_array_implementation_for_obj on arrays.
  (scm_is_typed_array): idem. Use impl->get_handle instead of
  scm_array_get_handle to avoid calling scm_i_array_implementation_for_obj
  twice.
* libguile/arrays.c: remove SCM_ARRAY_IMPLEMENTATION on scm_tc7_array type.
2014-01-27 21:49:10 +01:00
Daniel Llorens
96f7332263 array-contents returns root for empty arrays with empty root
This fixes a compiler issue where (uniform-array->bytevector #2f64())
failed because of the stricter definition of uniform-vector? on this branch.

Perhaps it would be better if uniform-array->bytevector didn't require
a contiguous argument.

* libguile/arrays.c: (scm_array_contents): return the root regardless of
  the value of SCM_I_ARRAY_DIMS (ra)->inc.
* test-suite/tests/arrays.test: check.
2014-01-27 21:49:10 +01:00
Daniel Llorens
f6ec824401 Fix compilation bugs with some kinds of typed arrays
* module/language/glil/compile-assembly.scm: pass (array-contents x)
  to uniform-array->bytevector instead of x, when x is a typed array.
* test-suite/tests/arrays.test: test an instance of the above that
  failed in Guile 2.0.9.
2014-01-27 21:49:10 +01:00
Daniel Llorens
dcc91f931c Preallocate index list in scm_array_index_map_x
* libguile/array-map.c
  - (scm_array_index_map_x): preallocate the index list instead of
    constructing it on each rank-1 iteration.
  - (ramap, rafe): use SCM_I_ARRAY_V just once.
2014-01-27 21:48:44 +01:00
Daniel Llorens
d0b47b4946 Rename scm_t_array_handle.array to .root
Globally rename this field (after shared-array-root), since it's not an array.
2014-01-27 21:48:44 +01:00
Daniel Llorens
99c0a58a2f Match types used in arrays.c to struct field types
* libguile/arrays.c
  - scm_shared_array_root: check for SCM_I_ARRAYP first.
  - scm_i_shap2ra:
    * check valid bounds in the '(lbnd ubnd) case. This makes
      (make-array 0 '(4 -3)) fail with a 'bad dimension' instead of
      with a 'wrong index' error.
    * use ssize_t for lbnd/ubnd/inc, not long.
  - scm_make_shared_array: use ssize_t for indices, not long.
  - scm_transpose_array: use size_t for ndim, not ulong.
  - scm_i_print_array: idem.
2014-01-27 21:48:03 +01:00
Daniel Llorens
d2053db7d8 Bounds error in vector_handle_ref/set is implementation error
* libguile/vectors.c: bounds are already checked unless impl is called
  directly, so don't check again.
* libguile/strings.c, libguile/bitvectors.c: fix comments.
2014-01-27 21:48:03 +01:00
Daniel Llorens
86263a20cd Don't use ASET in scm_array_index_map_x
* libguile/array-map.c: (scm_array_index_map_x): replace ASET by direct
  use of handle->impl.
2014-01-27 21:48:03 +01:00
Daniel Llorens
ce6fce6af3 In scm_ramapc, only check unrolled axes for emptiness
* libguile/array-map.c: (scm_ramapc)
  - Don't check emptiness while preparing ra0, but only after kroll is known,
    and only before kroll. len = 0 will be caught by the unrolled loop.
  - Use ra0 axis length in unroll check depth for rest args, not ra1's.
  - Recover early exit feature when cproc returns 0.
2014-01-27 21:48:03 +01:00
Daniel Llorens
3ee4c76453 Fix scm_ramapc bugs with 0-inc arrays
* libguile/array-map.c: (scm_ramapc): Cannot flag empty on the product
  inc * dim * dim ... Check every dim.
* test-suite/tests/ramap.test: Tests the 0-inc, non empty case for both
  array-map! and array-copy!.
2014-01-27 21:48:02 +01:00
Daniel Llorens
2bd96d9ecd Fix corner cases of scm_ramapc
* libguile/array-map.c
  - (scm_ramapc): mismatched axes limit unrollk (kroll). Reorganize
    the function to do all checking as we go.
  - (scm_ra_matchp): unused; remove.
  - (find_unrollk): inlined in scm_ramapc; remove.
  - (klen): inlined in scm_ramapc; remove.
  - (rafill): n is size_t.
  - (racp): n is size_t. Use n and not i0end to bound the loop.
  - (ramap): Use n and not i0end to bound the loop. This is needed for the rank
    0 case to work with the new scm_ramapc, as inc may be set to 0 in that case.
  - (rafe): idem.
* test-suite/tests/ramap.test
  - check that size mismatch prevents unrolling (matching behavior III) with
    both array-copy! and array-map!.
  - check that non-contiguous stride in non-ref args prevents unrolling
    (rank 2, discontinuous) with both array-copy! and array-map!.
  - check rank 0 cases with array-for-each, array-map!.
2014-01-27 21:48:02 +01:00
Daniel Llorens
cdd7cc9e9b Rewrite scm_ramapc()
* libguile/array-map.c
  - (cind): replace by cindk, that operates only on the unrolled index set.
  - (klen): new function.
  - (make1array): take extra inc argument.
  - (scm_ramapc): rewrite to unroll as many axes as possible instead of just all
    or one.
  - (AREF): lbnd is known to be 0: remove.
  - (ASET): v is known to come from SCM_I_ARRAY_V; assume base, inc, lbnd.
  - (racp): use ssize_t instead of long for the indices.
  - (scm_array_index_map_x): build the index list at the last-but-one axis, then
    set the car of the last element, instead of building the list at the last axis.
* test-suite/tests/ramap.test
  - add array-map! test with offset arguments.
2014-01-27 21:48:02 +01:00
Daniel Llorens
7c78a99f80 Check more cases of array-contents
* libguile/arrays.c: (scm_array_contents): fix comment.
* test-suite/tests/arrays.test: add cases that depend on correct
  setting of CONTIGUOUS_FLAG.
2014-01-27 21:48:02 +01:00
Daniel Llorens
ebe19774ea Check the documented matching behavior of array-map!/copy!
* test-suite/tests/arrays.test: move array-copy! tests to ramap.test.
* test-suite/tests/ramap.test: check the dissimilar matching behavior of
  array-copy! and array-map! with arguments of different size.
2014-01-27 21:48:02 +01:00
Daniel Llorens
aba084e95e Simplify ASET in array-map.c
* libguile/array-map.c: (ASET): this is only ever used with a true vector
  type, so remove use of inc/base/lbnd.
2014-01-27 21:48:02 +01:00
Daniel Llorens
1c22510af4 Inline ASET in array-index-map! for rank 1 arguments
* libguile/array-map.c: (scm_array_index_map_x): branch to special case on
    rank 1, instead of !SCM_I_ARRAYP (ra). Inline ASET in this case.
2014-01-27 21:48:02 +01:00
Daniel Llorens
b713626073 Fix compilation errors when reading arrays at the repl
* compile-assembly.scm
  - vector-fold2: handle rank 1 arrays, since this is called with
    the result of array-contents which need not be a vector.
  - dump-constants: fix uses of vector-fold2. Replace vector-length
    on result of array-contents by array-length.
* libguile/arrays.c
  - scm_array_contents: branch cases not on scm_is_generalized_vector but
    on SCM_I_ARRAYP. Thus lbnd!=0, which could happen with
    scm_is_generalized_vector, never appears in the output.
* test-suite/tests/arrays.test
  - tests for array-contents.
2014-01-27 21:48:02 +01:00
Daniel Llorens
d4f63dacdd Factor out make1array() in scm_ramapc()
* libguile/array-map.c: (scm_ramapc): factor out vector->array conversion
  to aux function make1array.
2014-01-27 21:45:54 +01:00
Daniel Llorens
4552a0c406 Raw pointer loop in array-copy! for vector/vector case
This special case improves

(define a (make-array 1. 1000000 10))
(define b (make-array *unspecified* 1000000 10))
(define c (transpose-array (make-array *unspecified* 10 1000000) 1 0))
,time (array-copy! a b)
,time (array-copy! a c)

from 0.041598s / 0.072561 to 0.012164s / 0.041886s on a i7-3930K.

* libguile/array-map.c: (racp): if both src and dst are on vectors, use
  the element pointers to do the copy.
2014-01-27 21:45:54 +01:00
Daniel Llorens
8190effae2 Have array impl->vref, vset take SCM, not handles
* libguile/array-handle.h
  - scm_i_t_array_ref, scm_i_t_array_set take SCM.
  - scm_array_handle_ref, scm_array_handle_set: pass h->array.
* libguile/array-map.c
  - AREF, ASET, rafill, racp, ramap, rafe: pass storage vector SCM
    instead of handle.
* libguile/bitvector.c
  - bitvector_handle_ref, bitvector_handle_set_x: take bitvector arg.
* libguile/bytevectors.c
  - bv_handle_ref, bv_handle_set_x: take bytevector arg.
  - scm_i_print_bytevectors: don't use array handles.
* libguile/deprecated.c
  - scm_generalized_vector_to_list: pass h.array.
* libguile/strings.c
  - string_handle_ref, string_handle_set: take string arg.
* libguile/uniform.c
  - scm_c_uniform_vector_ref, scm_c_uniform_vector_set_x: pass h.array.
* libguile/vectors.c
  - vector_handle_ref, vector_handle_set: take vector arg.
2014-01-27 21:45:54 +01:00
Daniel Llorens
f1fcf88b1f Fix array map functions with empty arguments
* libguile/array-map.c
  - scm_ra_matchp: look for empty axes and return new case 5 if so. Use
    array handles to remove the SCM_I_ARRAYP / not branch.
  - scm_ramapc: Heed case 5.
* test-suite/tests/ramap.test
  - test empty arguments for array-copy! and array-for-each. Note those
    that failed in 2.0.9.
2014-01-27 21:45:18 +01:00
Daniel Llorens
e26994b9e9 Fix empty array bug in array-index-map!
* libguile/array-map.c: (scm_array_index_map_x): bail out if any one of the
  axes is empty.
* test-suite/tests/ramap.test: add tests for empty array-case of
  array-index-map!. The 'f64 case with not-last emtpy axis is broken in 2.0.9.
2014-01-27 21:45:18 +01:00
Daniel Llorens
3e226ece5f Avoid using array_handle fields in impl->vref/vset
* libguile/bytevectors.c: (bv_handle_set_x, bv_handle_ref): get length
  and element type fields from the bytevector, not from the handle.
* libguile/vectors.c: (vector_handle_set, vector_handle_ref): get length
  from the vector, not from the handle.
2014-01-27 21:45:18 +01:00
Daniel Llorens
95cd688421 Remove undocumented casting behavior in srfi4 vector_elements
* libguile/srfi-4.c: scm_##tag##vector_writable_elements: if the argument's
  type doesn't match the tag, throw type error.
2014-01-27 21:45:18 +01:00
Daniel Llorens
9cbd17fc50 Test that typed-array? returns #f with non-array argument
* test-suite/tests/arrays.test: ditto.
2014-01-27 21:45:18 +01:00
Daniel Llorens
ecd6c04527 Avoid array API in make-srfi-4-vector
* libguile/bytevector.h: publish SCM_BYTEVECTOR_TYPE_SIZE, bytevector_ref_fns
  and bytevector_set_fns from libguile/bytevector.c.
* libguile/bytevector.c: bv_handle_ref, bv_handle_set: prefer
  SCM_BYTEVECTOR_TYPE_SIZE to scm_array_handle_uniform_element_size.
* libguile/srfi-4.c: scm_make_srfi_4_vector: don't use array handles.
2014-01-27 21:45:18 +01:00
Daniel Llorens
c9b62794e0 Replace SCM_IMP in array-map.c
* libguile/array-map.c
  - scm_ramapc: check scm_array_contents with scm_is_false.
2014-01-27 21:45:18 +01:00
Daniel Llorens
f5b2888e83 Fix comment in scm_array_get_handle
libguile/array-handle.c: (scm_array_get_handle): comment applies to either branch.
2014-01-27 21:45:18 +01:00
Daniel Llorens
3e5f10e8a2 Don't bother with array handle in scm_c_array_rank
* libguile/generalized-arrays.c: (scm_c_array_rank): compute rank directly from
  object.
2014-01-27 21:45:18 +01:00
Daniel Llorens
a70333d296 Use underlying vector implementation directly in array handles
* libguile/array-handle.c
  - scm_array_get_handle: if the object is an array, point impl to
    the underlying vector instead of array impl, then fix the axes. Avoid
    calling scm_i_array_implementation_for_obj twice.
* libguile/arrays.c
  - array_handle_ref, array_handle_set, array_get_handle: remove.
* libguile/bitvectors.c, libguile/bytevectors.c, libguile/strings.c,
  libguile/vectors.c: fix base = 0 in the array handle.
* libguile/vectors.c: (vector_handle_set, vector_handle_ref): do not
  use h->dims.
2014-01-27 21:45:18 +01:00
Daniel Llorens
ba7e018b61 Match uniform_vector_elements with vector_elements
* libguile/vectors.c
  - (scm_vector_writable_elements): allow any non-uniform rank 1 array,
    after the doc. Match the implementation with scm_uniform_vector_elements.
  - (scm_vector_elements): after the above.
* libguile/uniform.c
  - (scm_uniform_vector_writable_elements): ditto for uniform rank 1 arrays.
* libguile/sort.c
  - revert the changes in 7a6fd9, except for the argument type test; allow
    what scm_vector_(writable_)elements allows.
2014-01-27 21:45:18 +01:00
Daniel Llorens
766f399d3b Fix rank-1 indirection in array-map.c
* array-map.c: (AREF, ASET): fix buggy indirection carried over
  from old generalized_vector-ref/set!.
2014-01-27 21:45:18 +01:00
Daniel Llorens
d848953d8c Online documentation for vector-ref, vector-set!
* libguile/vectors.c: (scm_vector_ref, scm_vector_set!): embed the
  comments as documentation.
2014-01-27 21:45:18 +01:00
Daniel Llorens
e1df3b3ea7 vector-length rejects non vector? arg
* libguile/vectors.c
  - scm_c_vector_length:  error if SCM_I_IS_VECTOR (v) fails.
  - scm_vector_length: Documentation for vector-length.
2014-01-27 21:45:17 +01:00
Daniel Llorens
fa156321d4 vector-ref, vector-set! reject non vector? args
* libguile/vectors.c: (scm_c_vector_ref, scm_c_vector_set_x):
  throw type error if v is not vector?.
2014-01-27 21:45:17 +01:00
Daniel Llorens
70a63479ad Identify scm_is_vector with scm_is_simple_vector
This patch fixes the bug (vector-ref #1@1(1 2 3) 1) => 2.

* libguile/vectors.c: (scm_is_vector): just as scm_is_simple_vector.
* libguile/filesys.c, libguile/random.c, libguile/stime.c, libguile/trees.c,
  libguile/validate.h: use scm_is_vector instead of scm_is_simple_vector.
* libguile/sort.c
  - scm_restricted_vector_sort_x: use scm_array_handle_writable_elements
    instead of scm_vector_writable_elements, to work with non-vector
    rank-1 array objects.
  - scm_sort_x: check for scm_is_array instead of scm_is_vector. Rank
    check is in restricted_vector_sort_x.
  - scm_sort: ditto.
  - scm_stable_sort_x: like scm_restricted_vector_sort_x.
  - scm_stable_sort: like scm_sort.
* test-suite/tests/arrays.test: fix header.
* test-suite/tests/random.test: new coverage test covering
  random:normal-vector!
* test-suite/Makefile.am: include random.test in make check.
2014-01-27 21:45:17 +01:00
Daniel Llorens
413c715679 For uniform vectors SCM_I_ARRAYP can't be true
This fixes an inconsistency where uniform-vector? of a shared array could
be true but -ref operations failed to account correctly for lbnd.

* libguile/uniform.c
  - scm_is_uniform_vector: SCM_I_ARRAYP disqualifies obj as uniform vector.
  - scm_c_uniform_vector_length: lbnd is known 0, so don't use it.
  - scm_c_uniform_vector_ref: lbnd/base/inc are known to be 0/0/1.
  - scm_c_uniform_vector_set_x!: idem.
  - scm_uniform_vector_writable_elements: check uvec's type.
* test-suite/tests/arrays.test
  - group the exception types at the top.
  - check that uniform-vector functions do not accept general arrays.
2014-01-27 21:45:17 +01:00
Daniel Llorens
943f690a30 Fix bad uses of base and lbnd on rank 1 arrays
* libguile/array-map.c
   - rafill, ramap, rafe, racp: object from SCM_I_ARRAY_V always
     has base 0, lbnd 0 and inc 1; make use of this.
 * libguile/arrays.c
   - array_handle_ref, array_handle_set: idem.
   - array_get_handle: sanity check.
 * libguile/generalized-vectors.c
   - scm_c_generalized_vector_ref, scm_c_generalized_vector_set_x:
     pos should be base when idx is lbnd. Furthermore, pos should be signed and
     have its overflow checked; do this by handling the job to
     scm_c_array_ref_1, scm_c_array_set_1_x.
 * libguile/generalized-vectors.h
   - fix prototypes.
2014-01-27 21:45:17 +01:00
Daniel Llorens
499a9804c7 Reorder arrays.test
* test-suite/tests/arrays.test: dependence reordering: first sanity, then
  make-array, then array-equal?, then make-shared-array, shared-array-root,
  then the rest, many of which use make-shared-array.
2014-01-27 21:45:17 +01:00
Daniel Llorens
b8ff37f5ea Don't use scm_is_generalized_vector in transpose-array
* libguile/arrays.c (scm_transpose_array)
  - Use scm_c_array_rank(), which contains an implicit is_array test.
  - Handle the rank 0 case.
* test-suite/tests/arrays.test
  - Add test for rank 0 case.
  - Add failure test for non array argument.
2014-01-27 21:45:17 +01:00
Daniel Llorens
82c481dd11 Tests for transpose-array
* test-suite/tests/arrays.test: test transpose-array for ranks 1, 2, 3.
2014-01-27 21:45:17 +01:00
Daniel Llorens
aaeb4e5bfb Don't use scm_is_generalized_vector in shared-array-root
* libguile/arrays.c: (scm_shared_array_root): replace check for
  scm_is_generalized_vector.
2014-01-27 21:45:17 +01:00
Daniel Llorens
e0c58a5042 Tests for shared-array-root
* test-suite/tests/arrays.test: check shared-array-root against
  make-shared-array, array-contents.
2014-01-27 21:45:17 +01:00
Daniel Llorens
951ce0f413 Remove unnecessary conditions in array constructors
* libguile/arrays.c: (scm_make_type_array, scm_from_contigous_typed_array,
  scm_from_contigous_array): Remove conditions known to be true.
2014-01-27 21:45:17 +01:00
Daniel Llorens
0362859c28 Remove generalized-vectors.h includes
* libguile/srfi-4.c, libguile/uniform.h: ditto.
2014-01-27 21:45:17 +01:00
Daniel Llorens
000d4fb3a5 Replace scm_c_generalized_vector_length in arrays.c
* libguile/arrays.c: (scm_array_contents, scm_make_shared_array):
  arrays are known of rank 1 so replace by scm_c_array_length.
2014-01-27 21:45:17 +01:00
Daniel Llorens
5a4f40f903 Replace scm_c_generalized_vector_length in random.c
* libguile/random.c: (random:solid-sphere!): array is of known
  rank 1, so use scm_c_array_length() instead.
2014-01-27 21:45:17 +01:00
Daniel Llorens
b370eedc5e Don't use generalized-vector in array-map.c (II)
* libguile/array-map.c
  - replace scm_is_generalized_vector by scm_is_array && !SCM_I_ARRAY_P.
  - replace scm_c_generalized_vector_length by scm_c_array_length.
  - remove header.
2014-01-27 21:45:17 +01:00
Daniel Llorens
ad93aa0195 Don't use generalized-vector in array-map.c (I)
* array-map.c: (AREF, ASET): new internal functions replace
  scm_c_generalized_vector_ref/set. These remove a redundant check for
  rank in the generalized_vector set.
2014-01-27 21:45:17 +01:00
Daniel Llorens
4569bbf7f6 Don't use generalized-vector functions in uniform.c
* libguile/uniform.c
  - (scm_is_uniform_vector): replace scm_is_generalized_vector and
    scm_generalized_vector_get_handle by scm_is_array and manual rank check.
  - (scm_c_uniform_vector_length): inline length computation. This
    removes a redundant rank check.
  - (scm_c_uniform_vector_ref): inline impl->vref use. This removes
    a redundant rank check.
  - (scm_c_uniform_vector_set): inline impl->vset use. This removes
    a redundant rank check.
  - (scm_uniform_vector_writable_elements): replace
    scm_generalized_vector_get_handle by scm_array_get_handle.

* test-suite/test/arrays.test
  - rename uniform-vector-ref block to uniform-vector.
  - exercise uniform-vector-length and shared arrays remaining uniform.
2014-01-27 21:45:17 +01:00