diff options
author | Daniel Llorens <daniel.llorens@bluewin.ch> | 2013-04-08 13:13:21 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2014-01-27 21:45:17 +0100 |
commit | 4569bbf7f6b930f49758023f15ab1b9020036db9 (patch) | |
tree | e26384ca79e968b7d3b6bdafcf190569b56bc5ed | |
parent | 07f4a9151eda892e391800b5d53d4c50f93feb4e (diff) | |
download | guile-4569bbf7f6b930f49758023f15ab1b9020036db9.tar.gz |
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.
-rw-r--r-- | libguile/uniform.c | 41 | ||||
-rw-r--r-- | test-suite/tests/arrays.test | 24 |
2 files changed, 51 insertions, 14 deletions
diff --git a/libguile/uniform.c b/libguile/uniform.c index f8cd2d37b..6df7806fd 100644 --- a/libguile/uniform.c +++ b/libguile/uniform.c @@ -87,10 +87,11 @@ scm_is_uniform_vector (SCM obj) scm_t_array_handle h; int ret = 0; - if (scm_is_generalized_vector (obj)) + if (scm_is_array (obj)) { - scm_generalized_vector_get_handle (obj, &h); - ret = SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h.element_type); + scm_array_get_handle (obj, &h); + ret = 1 == scm_array_handle_rank (&h) + && SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h.element_type); scm_array_handle_release (&h); } return ret; @@ -99,11 +100,16 @@ scm_is_uniform_vector (SCM obj) size_t scm_c_uniform_vector_length (SCM uvec) { + scm_t_array_handle h; + size_t ret; if (!scm_is_uniform_vector (uvec)) scm_wrong_type_arg_msg ("uniform-vector-length", 1, uvec, "uniform vector"); - return scm_c_generalized_vector_length (uvec); + scm_array_get_handle (uvec, &h); + ret = h.dims[0].ubnd - h.dims[0].lbnd + 1; + scm_array_handle_release (&h); + return ret; } SCM_DEFINE (scm_uniform_vector_p, "uniform-vector?", 1, 0, 0, @@ -169,11 +175,20 @@ SCM_DEFINE (scm_uniform_vector_element_size, "uniform-vector-element-size", 1, 0 #undef FUNC_NAME SCM -scm_c_uniform_vector_ref (SCM v, size_t idx) +scm_c_uniform_vector_ref (SCM v, size_t pos) { + scm_t_array_handle h; + SCM ret; + if (!scm_is_uniform_vector (v)) scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector"); - return scm_c_generalized_vector_ref (v, idx); + + scm_array_get_handle (v, &h); + pos = h.base + h.dims[0].lbnd + pos * h.dims[0].inc; + ret = h.impl->vref (&h, pos); + scm_array_handle_release (&h); + return ret; + } SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0, @@ -187,11 +202,17 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0, #undef FUNC_NAME void -scm_c_uniform_vector_set_x (SCM v, size_t idx, SCM val) +scm_c_uniform_vector_set_x (SCM v, size_t pos, SCM val) { + scm_t_array_handle h; + if (!scm_is_uniform_vector (v)) scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector"); - scm_c_generalized_vector_set_x (v, idx, val); + + scm_array_get_handle (v, &h); + pos = h.base + h.dims[0].lbnd + pos * h.dims[0].inc; + h.impl->vset (&h, pos, val); + scm_array_handle_release (&h); } SCM_DEFINE (scm_uniform_vector_set_x, "uniform-vector-set!", 3, 0, 0, @@ -225,12 +246,12 @@ scm_uniform_vector_elements (SCM uvec, } void * -scm_uniform_vector_writable_elements (SCM uvec, +scm_uniform_vector_writable_elements (SCM uvec, scm_t_array_handle *h, size_t *lenp, ssize_t *incp) { void *ret; - scm_generalized_vector_get_handle (uvec, h); + scm_array_get_handle (uvec, h); /* FIXME nonlocal exit */ ret = scm_array_handle_uniform_writable_elements (h); if (lenp) diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test index 0b3d57ca2..9d8637122 100644 --- a/test-suite/tests/arrays.test +++ b/test-suite/tests/arrays.test @@ -574,12 +574,12 @@ (eqv? 8 (array-ref s2 2)))))) ;;; -;;; uniform-vector-ref +;;; uniform-vector ;;; -(with-test-prefix "uniform-vector-ref" +(with-test-prefix "uniform-vector" - (with-test-prefix "byte" + (with-test-prefix "uniform-vector-ref byte" (let ((a (make-s8vector 1))) @@ -594,7 +594,23 @@ (pass-if "-128" (begin (array-set! a -128 0) - (= -128 (uniform-vector-ref a 0))))))) + (= -128 (uniform-vector-ref a 0)))))) + + (with-test-prefix "shared with rank 1 remain uniform vectors" + + (let ((a #f64(1 2 3 4))) + + (pass-if "change offset" + (let ((b (make-shared-array a (lambda (i) (list (+ i 1))) 3))) + (and (uniform-vector? b) + (= 3 (uniform-vector-length b)) + (array-equal? b #f64(2 3 4))))) + + (pass-if "change stride" + (let ((c (make-shared-array a (lambda (i) (list (* i 2))) 2))) + (and (uniform-vector? c) + (= 2 (uniform-vector-length c)) + (array-equal? c #f64(1 3)))))))) ;;; ;;; syntax |