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

35 commits

Author SHA1 Message Date
Daniel Llorens
e0bcda4ad9 Fix bitvectors and non-zero lower bound arrays in truncated-print
* module/ice-9/arrays.scm (array-print-prefix): New private function.
* libguile/arrays.c (scm_i_print_array): Reuse (array-print-prefix) from
  (ice-9 arrays). Make sure to release the array handle.
* module/ice-9/pretty-print.scm (truncated-print): Support
  bitvectors.
  Don't try to guess the array prefix but call array-print-prefix from
  (ice-9 arrays) instead.
  Fix call to print-sequence to support non-zero lower bound arrays.
* test-suite/tests/arrays.test: Test that arrays print properly.
* test-suite/tests/print.test: Test truncated-print with bitvectors,
  non-zero lower bound arrays.
2017-10-31 13:23:44 +01:00
Daniel Llorens
7e93950552 Final names for new array functions
Globally rename (array-from* -> array-slice), (array-from ->
array-cell-ref), (array-amend! -> array-cell-set!), (array-for-each-cell
-> array-slice-for-each).
2017-01-09 09:02:04 +01:00
Daniel Llorens
fa4a22971a Deprecate scm_from_contiguous_array
scm_from_contiguous_array() was undocumented, unused within Guile, and
can be replaced by make-array + array-copy! without requiring contiguity
and without loss of performance.

* libguile/arrays.c (scm_array_contents): Do not rely on
  SCM_I_ARRAY_CONTP.
* test-suite/tests/arrays.test: Test array-contents with 0-rank array.
* libguile/arrays.h: Declare scm_i_shap2ra(),
  SCM_SET_ARRAY_CONTIGUOUS_FLAG, SCM_CLR_ARRAY_CONTIGUOUS_FLAG so that
  scm_from_contiguous_array() can keep using them.
* libguile/deprecated.c (scm_from_contiguous_array): Move here from
  arrays.c.
* libguile/deprecated.h (scm_from_contiguous_array): Deprecate.
* NEWS: Add deprecation notice.
2016-11-23 13:05:49 +01:00
Daniel Llorens
d1435ea6bd New functions array-from, array-from*, array-amend!
* libguile/arrays.h (scm_array_from, scm_array_from_s,
  scm_array_amend_x): New declarations.

* libguile/arrays.c (scm_array_from, scm_array_from_s,
  scm_array_amend_x): New functions, export as array-from, array-from*,
  array-amend!.

* test-suite/tests/arrays.test: Tests for array-from, array-from*,
  array-amend!. Replace with-test-prefix/c&e with with-test-prefix where
  the array read syntax isn't used.
2016-11-23 13:04:26 +01:00
Daniel Llorens
4e766795b2 Avoid unneeded internal use of array handles
* libguile/arrays.c (scm_shared_array_root): Adopt uniform check order.

  (scm_shared_array_offset, scm_shared_array_increments): Use the array
  fields directly just as scm_shared_array_root does.

  (scm_c_array_rank): Moved from libguile/generalized-arrays.c. Don't
  use array handles, but follow the same type check sequence as the
  other array functions (shared-array-root, etc).

  (scm_array_rank): Moved from libguile/generalized-arrays.h.

* libguile/arrays.h: Move prototypes here.

* test-suite/tests/arrays.test: Tests for shared-array-offset,
  shared-array-increments.
2016-11-23 11:49:35 +01:00
Daniel Llorens
d236d4d33f Fix compilation of rank 0 typed array literals
* module/system/vm/assembler.scm (simple-uniform-vector?): array-length
  fails for rank 0 arrays; fix the shape condition.

* test-suite/tests/arrays.test: Test reading of #0f64(x) in compilation
  context.
2016-11-23 11:49:35 +01:00
Daniel Llorens
eb3d623da5 Non-vector 1D arrays print as #1()
* libguile/arrays.c (scm_i_print_array): Print the dimension whenever
  the array is a true scm_tc7_array.

* test-suite/tests/arrays.test: Check that non-vector 1D arrays print as
  expected.
2015-02-18 09:32:30 +01:00
Daniel Llorens
ea342aa6f7 Run some of arrays.test under both compiler & interpreter
* test-suite/test-suite/lib.scm (c&e): accept (pass-if exp) clause.

* test-suite/tests/arrays.test: use with-prefix/c&e instead of
  with-prefix where possible.
2014-09-30 11:35:08 +02:00
Daniel Llorens
2c1ccb02c5 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-02-10 21:58:28 +01:00
Daniel Llorens
c6eaad9757 Add tests for more kinds of typed arrays.
* test-suite/tests/arrays.test: Add more type array tests.
2014-02-10 21:58:28 +01:00
Daniel Llorens
35f45ed6d0 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-02-10 21:25:42 +01:00
Daniel Llorens
c545f7164a Refactor array-contents
* 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: Test array-contents.
2014-02-10 21:18:48 +01:00
Daniel Llorens
dd60e9348e 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-02-10 21:09:23 +01:00
Daniel Llorens
d41d5bf05e Test that typed-array? returns #f with non-array argument
* test-suite/tests/arrays.test: ditto.
2014-02-09 12:55:49 +01:00
Daniel Llorens
d747313100 Change uses of scm_is_simple_vector to scm_is_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_sort_x, scm_sort, scm_stable_sort_x)
  (scm_stable_sort): Remove scm_is_vector check; scm_is_array is
  sufficient.
* 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-02-08 18:26:49 +01:00
Andy Wingo
8051cf2304 Merge commit 'fb7dd00169'
This commit also renames uniform-vector-element-type-code to
array-type-code.

Conflicts:
	libguile/uniform.c
	libguile/uniform.h
	test-suite/tests/arrays.test
2014-02-08 15:31:37 +01:00
Andy Wingo
fb7dd00169 Deprecate general "uniform-vector" interface
* libguile/uniform.h:
* libguile/uniform.c (scm_is_uniform_vector, scm_uniform_vector_p)
  (scm_c_uniform_vector_length, scm_uniform_vector_length)
  (scm_uniform_vector_element_type, scm_uniform_vector_element_size)
  (scm_c_uniform_vector_ref, scm_uniform_vector_ref):
  (scm_c_uniform_vector_set_x, scm_uniform_vector_set_x):
  (scm_uniform_vector_to_list)
  (scm_uniform_vector_elements, scm_uniform_vector_writable_elements):
  Deprecate.  This interface lacked both generality and specificity.
  The general replacement is array-length, array-ref, and friends on the
  scheme side, or the array handle interface on the C side.  On the
  specific side of things, there are the specific bytevector, srfi-4,
  and bitvector interfaces.

* test-suite/tests/arrays.test:
* test-suite/tests/bitvectors.test:
* test-suite/tests/ports.test:
* test-suite/tests/srfi-4.test: Update to use array interfaces.

* doc/ref/api-foreign.texi (Void Pointers and Byte Access):
* doc/ref/srfi-modules.texi (SRFI-4): Update.
2014-02-08 14:28:07 +01:00
Daniel Llorens
69843ac1b9 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-02-06 21:40:38 +01:00
Daniel Llorens
a6f8d3ddd8 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-02-06 21:40:38 +01:00
Daniel Llorens
ee23869521 Tests for transpose-array
* test-suite/tests/arrays.test: test transpose-array for ranks 1, 2, 3.
2014-02-06 21:40:38 +01:00
Daniel Llorens
1080ce25bc Tests for shared-array-root
* test-suite/tests/arrays.test: check shared-array-root against
  make-shared-array, array-contents.
2014-02-06 21:40:38 +01:00
Daniel Llorens
c4aca3b9da 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): Use scm_c_array_length.
  (scm_c_uniform_vector_ref): Use scm_c_array_ref_1.
  (scm_c_uniform_vector_set): Use scm_c_array_set_1_x.
  (scm_uniform_vector_writable_elements): Use scm_array_get_handle, and
  assert that the rank is 1.

* test-suite/test/arrays.test: Rename the uniform-vector-ref block to
  uniform-vector.  Exercise uniform-vector-length and shared arrays
  remaining uniform.

Modifications by Andy Wingo <wingo@pobox.com>.
2014-02-06 11:17:47 +01:00
Daniel Llorens
ab1ca17986 Remove double indirection in array-fill!
* libguile/array-map.c: new function rafill, like scm_array_fill_int,
  but factors GVSET out of the loop. Use it in scm_array_fill_x instead of
  scm_array_fill_int.
* test-suite/tests/arrays.test: add test for array-fill! with stride != 1.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-05 22:54:14 +02:00
Daniel Llorens
b5159a471a Tests for array-copy!
* test-suite/tests/arrays.test: tests for arguments of rank 0, 1 and 2.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2013-04-05 22:54:14 +02:00
Andy Wingo
118ff892be deprecate generalized vectors in favor of arrays
* libguile/generalized-arrays.h:
* libguile/generalized-arrays.c (scm_c_array_length):
  (scm_array_length): New functions.

* module/ice-9/deprecated.scm:
* libguile/generalized-vectors.c:
* libguile/generalized-vectors.h:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_generalized_vector_p)
  (scm_generalized_vector_length, scm_generalized_vector_ref)
  (scm_generalized_vector_set_x, scm_generalized_vector_to_list):
  Deprecate.

* libguile/uniform.c (scm_uniform_vector_to_list): Use
  scm_array_to_list.

* module/ice-9/boot-9.scm (case): Arrays are generalized vectors.

* module/srfi/srfi-4/gnu.scm (define-any->vector): Use the array
  functions instead of the generalized-vector functions.

* test-suite/tests/arrays.test: Remove generalized-vector->list test;
  covered by array->list test.

* test-suite/tests/bitvectors.test:
* test-suite/tests/bytevectors.test:
* test-suite/tests/srfi-4.test: Adapt to test using array interfaces
  instead of generalized-vector interfaces.

* doc/ref/api-compound.texi: Remove generalized vector docs.
* doc/ref/api-data.texi:
* doc/ref/srfi-modules.texi: Adapt.
2013-02-18 16:57:15 +01:00
Andy Wingo
336c921146 optimize access to arrays of rank 1 or 2
* libguile/array-handle.c (scm_array_handle_pos_1):
  (scm_array_handle_pos_2): New functions.

* libguile/generalized-arrays.c (scm_c_array_ref_1, scm_c_array_ref_2):
  (scm_c_array_set_1_x, scm_c_array_set_2_x): New functions.
  (scm_i_array_ref, scm_i_array_set_x): New subr bindings for array-ref
  and array-set! that avoid consing for arrays of rank 1 or 2.

* test-suite/tests/arrays.test ("array-set!"): Fix expected exception
  for wrong number of indices.
2013-02-18 16:38:24 +01:00
Ludovic Courtès
1d4e6ee301 Fix `generalized-vector->list' indexing bug with shared arrays.
Fixes <http://bugs.gnu.org/12465>.
Reported by Daniel Llorens <daniel.llorens@bluewin.ch>.

* libguile/generalized-vectors.c (scm_generalized_vector_to_list): Fix
  initial value of POS; pass the `h.base + pos', not just `pos' as the
  `vref' argument.

* test-suite/tests/arrays.test ("array->list")["http://bugs.gnu.org/12465
  - ok", "http://bugs.gnu.org/12465 - bad]: New tests.
  ("generalized-vector->list"): New test prefix.
2012-11-03 00:20:57 +01:00
Ludovic Courtès
80aeb9af0d test-suite: Add a nameless form of `pass-if-equal'.
* test-suite/test-suite/lib.scm (pass-if-equal): Add a nameless pattern.
* test-suite/tests/arrays.test ("array->list"): Use `pass-if-equal'.
2012-11-02 23:43:45 +01:00
Andy Wingo
2b414e247f fix generalized-vector-{ref,set!} for slices
* libguile/generalized-vectors.c (scm_c_generalized_vector_ref):
  (scm_c_generalized_vector_set_x): Fix for the case in which base was
  not 1, lbnd was not 0, or inc was not 1.

* test-suite/tests/arrays.test (array): Add a test.  Thanks to Daniel
  Llorens for the report.
2011-12-22 17:03:04 -05:00
Andy Wingo
e48a2f8705 add docs and tests for array->list
* libguile/generalized-arrays.c (scm_array_to_list): Add docs.
* test-suite/tests/arrays.test ("array->list"): Add tests.
2010-04-07 21:04:37 +02:00
Andy Wingo
a587d6a973 more fixes to equal? for arrays
* libguile/array-map.c (array_compare, scm_array_equal_p): Rewrite as
  something that operates on the generic array handle infrastructure.
  Based on array->list.
  (scm_i_array_equal_p): Change the docs, as array-equal? is now the same
  as equal?, except that it typechecks its args.

* doc/ref/api-compound.texi (Array Procedures): Update array-equal?
  docs.

* libguile/deprecated.h:
* libguile/deprecated.c (scm_raequal): Deprecate.

* libguile/bytevectors.c (scm_bytevector_eq_p): Bugfix: bytevectors are
  bytevector=? only if their element type is the same.

* libguile/eq.c (scm_equal_p): Only dispatch to scm_array_equal_p if
  both args are arrays (generically).

* test-suite/tests/arrays.test ("equal?"): Add some more tests.
2010-04-01 00:25:06 +02:00
Andy Wingo
e275b8a220 rename unif.test to arrays.test
* test-suite/tests/arrays.test: Move all unif.test here. Unif.test was
  mostly testing arrays anyway. Incorporate the existing arrays.test.

* test-suite/tests/unif.test: Deleted.
* test-suite/Makefile.am: Update.
2010-03-31 21:17:05 +02:00
Andy Wingo
3ffd1ba96e 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.
2010-03-31 00:05:01 +02:00
Andy Wingo
d26383f427 Revert "fix equal? between an array and a non-array"
This reverts commit 9d031d4d57.
2010-03-30 23:51:40 +02:00
Andy Wingo
9d031d4d57 fix equal? between an array and a non-array
* libguile/eq.c (scm_equal_p): Only call scm_array_equal_p if both
  arguments are generalized arrays; otherwise they are not equal. Thanks
  to Daniel Llorens del Río for the tip.

* test-suite/Makefile.am:
* test-suite/tests/arrays.test: Add a test.
2010-03-30 21:23:06 +02:00