summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2014-01-27Arrays are not an array implementationlloda-array-cleanupDaniel Llorens3-13/+11
* 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-27array-contents returns root for empty arrays with empty rootDaniel Llorens2-3/+7
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-27Fix compilation bugs with some kinds of typed arraysDaniel Llorens1-1/+9
* 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-27Preallocate index list in scm_array_index_map_xDaniel Llorens2-18/+26
* 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-27Rename scm_t_array_handle.array to .rootDaniel Llorens9-23/+23
Globally rename this field (after shared-array-root), since it's not an array.
2014-01-27Match types used in arrays.c to struct field typesDaniel Llorens1-22/+24
* 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-27Bounds error in vector_handle_ref/set is implementation errorDaniel Llorens3-9/+5
* 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-27Don't use ASET in scm_array_index_map_xDaniel Llorens1-5/+5
* libguile/array-map.c: (scm_array_index_map_x): replace ASET by direct use of handle->impl.
2014-01-27In scm_ramapc, only check unrolled axes for emptinessDaniel Llorens1-69/+50
* 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-27Fix scm_ramapc bugs with 0-inc arraysDaniel Llorens2-24/+35
* 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-27Fix corner cases of scm_ramapcDaniel Llorens2-208/+211
* 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-27Rewrite scm_ramapc()Daniel Llorens2-129/+137
* 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-27Check more cases of array-contentsDaniel Llorens2-3/+13
* 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-27Check the documented matching behavior of array-map!/copy!Daniel Llorens2-45/+67
* 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-27Simplify ASET in array-map.cDaniel Llorens1-1/+1
* libguile/array-map.c: (ASET): this is only ever used with a true vector type, so remove use of inc/base/lbnd.
2014-01-27Inline ASET in array-index-map! for rank 1 argumentsDaniel Llorens1-8/+14
* 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-27Fix compilation errors when reading arrays at the replDaniel Llorens2-22/+83
* 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-27Factor out make1array() in scm_ramapc()Daniel Llorens1-96/+93
* libguile/array-map.c: (scm_ramapc): factor out vector->array conversion to aux function make1array.
2014-01-27Raw pointer loop in array-copy! for vector/vector caseDaniel Llorens1-5/+16
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-27Have array impl->vref, vset take SCM, not handlesDaniel Llorens7-65/+66
* 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-27Fix array map functions with empty argumentsDaniel Llorens2-86/+102
* 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-27Fix empty array bug in array-index-map!Daniel Llorens2-13/+38
* 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-27Avoid using array_handle fields in impl->vref/vsetDaniel Llorens2-6/+6
* 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-27Remove undocumented casting behavior in srfi4 vector_elementsDaniel Llorens1-21/+1
* libguile/srfi-4.c: scm_##tag##vector_writable_elements: if the argument's type doesn't match the tag, throw type error.
2014-01-27Test that typed-array? returns #f with non-array argumentDaniel Llorens1-1/+7
* test-suite/tests/arrays.test: ditto.
2014-01-27Avoid array API in make-srfi-4-vectorDaniel Llorens3-26/+23
* 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-27Replace SCM_IMP in array-map.cDaniel Llorens1-1/+2
* libguile/array-map.c - scm_ramapc: check scm_array_contents with scm_is_false.
2014-01-27Fix comment in scm_array_get_handleDaniel Llorens1-9/+5
libguile/array-handle.c: (scm_array_get_handle): comment applies to either branch.
2014-01-27Don't bother with array handle in scm_c_array_rankDaniel Llorens1-8/+7
* libguile/generalized-arrays.c: (scm_c_array_rank): compute rank directly from object.
2014-01-27Use underlying vector implementation directly in array handlesDaniel Llorens6-61/+33
* 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-27Match uniform_vector_elements with vector_elementsDaniel Llorens3-68/+43
* 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-27Fix rank-1 indirection in array-map.cDaniel Llorens1-2/+2
* array-map.c: (AREF, ASET): fix buggy indirection carried over from old generalized_vector-ref/set!.
2014-01-27Online documentation for vector-ref, vector-set!Daniel Llorens1-53/+35
* libguile/vectors.c: (scm_vector_ref, scm_vector_set!): embed the comments as documentation.
2014-01-27vector-length rejects non vector? argDaniel Llorens1-17/+15
* libguile/vectors.c - scm_c_vector_length: error if SCM_I_IS_VECTOR (v) fails. - scm_vector_length: Documentation for vector-length.
2014-01-27vector-ref, vector-set! reject non vector? argsDaniel Llorens1-33/+1
* libguile/vectors.c: (scm_c_vector_ref, scm_c_vector_set_x): throw type error if v is not vector?.
2014-01-27Identify scm_is_vector with scm_is_simple_vectorDaniel Llorens10-47/+103
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-27For uniform vectors SCM_I_ARRAYP can't be trueDaniel Llorens2-28/+41
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-27Fix bad uses of base and lbnd on rank 1 arraysDaniel Llorens4-34/+25
* 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-27Reorder arrays.testDaniel Llorens1-152/+152
* 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-27Don't use scm_is_generalized_vector in transpose-arrayDaniel Llorens2-8/+21
* 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-27Tests for transpose-arrayDaniel Llorens1-0/+32
* test-suite/tests/arrays.test: test transpose-array for ranks 1, 2, 3.
2014-01-27Don't use scm_is_generalized_vector in shared-array-rootDaniel Llorens1-5/+6
* libguile/arrays.c: (scm_shared_array_root): replace check for scm_is_generalized_vector.
2014-01-27Tests for shared-array-rootDaniel Llorens1-0/+29
* test-suite/tests/arrays.test: check shared-array-root against make-shared-array, array-contents.
2014-01-27Remove unnecessary conditions in array constructorsDaniel Llorens1-3/+4
* libguile/arrays.c: (scm_make_type_array, scm_from_contigous_typed_array, scm_from_contigous_array): Remove conditions known to be true.
2014-01-27Remove generalized-vectors.h includesDaniel Llorens2-2/+0
* libguile/srfi-4.c, libguile/uniform.h: ditto.
2014-01-27Replace scm_c_generalized_vector_length in arrays.cDaniel Llorens1-5/+5
* 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-27Replace scm_c_generalized_vector_length in random.cDaniel Llorens1-2/+2
* libguile/random.c: (random:solid-sphere!): array is of known rank 1, so use scm_c_array_length() instead.
2014-01-27Don't use generalized-vector in array-map.c (II)Daniel Llorens1-25/+24
* 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-27Don't use generalized-vector in array-map.c (I)Daniel Llorens1-21/+37
* 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-27Don't use generalized-vector functions in uniform.cDaniel Llorens2-14/+51
* 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.