From: Daniel Llorens <dll@jast.ch>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: array-copy! is slow & array-map.c
Date: Wed, 3 Apr 2013 23:04:07 +0200 [thread overview]
Message-ID: <A8A1B3E9-D5EA-4718-9A1A-5BC38A0DA881@jast.ch> (raw)
In-Reply-To: <87mwtfmlap.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 124 bytes --]
Attached 1st a patch with some array-copy! tests, then the array-fill! patch split in two parts.
Thanks!
Daniel
[-- Attachment #2: 0001-Tests-for-array-copy.patch --]
[-- Type: application/octet-stream, Size: 2162 bytes --]
From 292014d961eca156afec7f97954c117916518aa3 Mon Sep 17 00:00:00 2001
From: Daniel Llorens <daniel.llorens@bluewin.ch>
Date: Wed, 3 Apr 2013 22:31:47 +0200
Subject: [PATCH 1/3] Tests for array-copy!
* test-suite/tests/arrays.test: tests for arguments of rank 0, 1 and 2.
---
test-suite/tests/arrays.test | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test
index d88a1cb..7f1bbde 100644
--- a/test-suite/tests/arrays.test
+++ b/test-suite/tests/arrays.test
@@ -294,6 +294,46 @@
(pass-if "5/8" (array-fill! a 5/8) #t))))
;;;
+;;; array-copy!
+;;;
+
+(with-test-prefix "array-copy!"
+
+ (with-test-prefix "rank 2"
+ (pass-if (let ((a #2((1 2) (3 4)))
+ (b (make-array 0 2 2))
+ (c (make-array 0 2 2))
+ (d (make-array 0 2 2))
+ (e (make-array 0 2 2)))
+ (array-copy! a b)
+ (array-copy! a (transpose-array c 1 0))
+ (array-copy! (transpose-array a 1 0) d)
+ (array-copy! (transpose-array a 1 0) (transpose-array e 1 0))
+ (and (equal? a #2((1 2) (3 4)))
+ (equal? b #2((1 2) (3 4)))
+ (equal? c #2((1 3) (2 4)))
+ (equal? d #2((1 3) (2 4)))
+ (equal? e #2((1 2) (3 4)))))))
+
+ (with-test-prefix "rank 1"
+ (pass-if (let* ((a #2((1 2) (3 4)))
+ (b (make-shared-array a (lambda (j) (list 1 j)) 2))
+ (c (make-shared-array a (lambda (i) (list (- 1 i) 1)) 2))
+ (d (make-array 0 2))
+ (e (make-array 0 2)))
+ (array-copy! b d)
+ (array-copy! c e)
+ (and (equal? d #(3 4))
+ (equal? e #(4 2))))))
+
+ (with-test-prefix "rank 0"
+ (pass-if (let ((a #0(99))
+ (b (make-array 0)))
+ (array-copy! a b)
+ (equal? b #0(99))))))
+
+
+;;;
;;; array-in-bounds?
;;;
--
1.8.2
[-- Attachment #3: 0002-Remove-double-indirection-in-array-fill.patch --]
[-- Type: application/octet-stream, Size: 2800 bytes --]
From 76432b25fda11957142e94653aafbc798ef4d880 Mon Sep 17 00:00:00 2001
From: Daniel Llorens <daniel.llorens@bluewin.ch>
Date: Wed, 3 Apr 2013 22:40:40 +0200
Subject: [PATCH 2/3] 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.
---
libguile/array-map.c | 21 +++++++++++++++++++--
test-suite/tests/arrays.test | 10 +++++++++-
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/libguile/array-map.c b/libguile/array-map.c
index b5b8cec..c86ea84 100644
--- a/libguile/array-map.c
+++ b/libguile/array-map.c
@@ -318,6 +318,23 @@ scm_ramapc (void *cproc_ptr, SCM data, SCM ra0, SCM lra, const char *what)
}
}
+static int
+rafill (SCM dst, SCM fill)
+{
+ long n = (SCM_I_ARRAY_DIMS (dst)->ubnd - SCM_I_ARRAY_DIMS (dst)->lbnd + 1);
+ scm_t_array_handle h;
+ size_t i;
+ ssize_t inc;
+ scm_generalized_vector_get_handle (SCM_I_ARRAY_V (dst), &h);
+ i = h.base + h.dims[0].lbnd + SCM_I_ARRAY_BASE (dst)*h.dims[0].inc;
+ inc = SCM_I_ARRAY_DIMS (dst)->inc * h.dims[0].inc;
+
+ for (; n-- > 0; i += inc)
+ h.impl->vset (&h, i, fill);
+
+ scm_array_handle_release (&h);
+ return 1;
+}
SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0,
(SCM ra, SCM fill),
@@ -325,14 +342,14 @@ SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0,
"returned is unspecified.")
#define FUNC_NAME s_scm_array_fill_x
{
- scm_ramapc (scm_array_fill_int, fill, ra, SCM_EOL, FUNC_NAME);
+ scm_ramapc (rafill, fill, ra, SCM_EOL, FUNC_NAME);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
/* to be used as cproc in scm_ramapc to fill an array dimension with
"fill". */
-int
+int
scm_array_fill_int (SCM ra, SCM fill, SCM ignore SCM_UNUSED)
#define FUNC_NAME s_scm_array_fill_x
{
diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test
index 7f1bbde..7b96b11 100644
--- a/test-suite/tests/arrays.test
+++ b/test-suite/tests/arrays.test
@@ -291,7 +291,15 @@
(pass-if "0" (array-fill! a 0) #t)
(pass-if "123" (array-fill! a 123) #t)
(pass-if "-123" (array-fill! a -123) #t)
- (pass-if "5/8" (array-fill! a 5/8) #t))))
+ (pass-if "5/8" (array-fill! a 5/8) #t)))
+
+ (with-test-prefix "noncompact"
+ (let* ((a (make-array 0 3 3))
+ (b (make-shared-array a (lambda (i) (list i i)) 3)))
+ (array-fill! b 9)
+ (pass-if
+ (and (equal? b #(9 9 9))
+ (equal? a #2((9 0 0) (0 9 0) (0 0 9))))))))
;;;
;;; array-copy!
--
1.8.2
[-- Attachment #4: 0003-Deprecate-scm_array_fill_int.patch --]
[-- Type: application/octet-stream, Size: 3479 bytes --]
From ef8e5b980c6d5a4dbea12fbed1ac7bc16277b859 Mon Sep 17 00:00:00 2001
From: Daniel Llorens <daniel.llorens@bluewin.ch>
Date: Wed, 3 Apr 2013 22:52:21 +0200
Subject: [PATCH 3/3] Deprecate scm_array_fill_int()
* libguile/array-map.h, libgule/array-map.c: move scm_array_fill_int
to the deprecated section.
---
doc/guile-api.alist | 1 -
libguile/array-map.c | 41 ++++++++++++++++++++---------------------
libguile/array-map.h | 2 +-
3 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/doc/guile-api.alist b/doc/guile-api.alist
index 5830c91..78d3a5c 100644
--- a/doc/guile-api.alist
+++ b/doc/guile-api.alist
@@ -1359,7 +1359,6 @@
(scm_array_copy_x (groups scm C) (scan-data T))
(scm_array_dimensions (groups scm C) (scan-data T))
(scm_array_equal_p (groups scm C) (scan-data T))
-(scm_array_fill_int (groups scm C) (scan-data T))
(scm_array_fill_x (groups scm C) (scan-data T))
(scm_array_for_each (groups scm C) (scan-data T))
(scm_array_identity (groups scm C) (scan-data T))
diff --git a/libguile/array-map.c b/libguile/array-map.c
index c86ea84..2779458 100644
--- a/libguile/array-map.c
+++ b/libguile/array-map.c
@@ -347,26 +347,6 @@ SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0,
}
#undef FUNC_NAME
-/* to be used as cproc in scm_ramapc to fill an array dimension with
- "fill". */
-int
-scm_array_fill_int (SCM ra, SCM fill, SCM ignore SCM_UNUSED)
-#define FUNC_NAME s_scm_array_fill_x
-{
- unsigned long i;
- unsigned long n = SCM_I_ARRAY_DIMS (ra)->ubnd - SCM_I_ARRAY_DIMS (ra)->lbnd + 1;
- long inc = SCM_I_ARRAY_DIMS (ra)->inc;
- unsigned long base = SCM_I_ARRAY_BASE (ra);
-
- ra = SCM_I_ARRAY_V (ra);
-
- for (i = base; n--; i += inc)
- GVSET (ra, i, fill);
-
- return 1;
-}
-#undef FUNC_NAME
-
static int
racp (SCM src, SCM dst)
@@ -411,10 +391,29 @@ SCM_DEFINE (scm_array_copy_x, "array-copy!", 2, 0, 0,
}
#undef FUNC_NAME
-/* Functions callable by ARRAY-MAP! */
#if SCM_ENABLE_DEPRECATED == 1
+/* to be used as cproc in scm_ramapc to fill an array dimension with
+ "fill". */
+int
+scm_array_fill_int (SCM ra, SCM fill, SCM ignore SCM_UNUSED)
+{
+ unsigned long i;
+ unsigned long n = SCM_I_ARRAY_DIMS (ra)->ubnd - SCM_I_ARRAY_DIMS (ra)->lbnd + 1;
+ long inc = SCM_I_ARRAY_DIMS (ra)->inc;
+ unsigned long base = SCM_I_ARRAY_BASE (ra);
+
+ ra = SCM_I_ARRAY_V (ra);
+
+ for (i = base; n--; i += inc)
+ GVSET (ra, i, fill);
+
+ return 1;
+}
+
+/* Functions callable by ARRAY-MAP! */
+
int
scm_ra_eqp (SCM ra0, SCM ras)
{
diff --git a/libguile/array-map.h b/libguile/array-map.h
index eb1aa37..b0592d8 100644
--- a/libguile/array-map.h
+++ b/libguile/array-map.h
@@ -31,7 +31,6 @@
SCM_API int scm_ra_matchp (SCM ra0, SCM ras);
SCM_API int scm_ramapc (void *cproc, SCM data, SCM ra0, SCM lra,
const char *what);
-SCM_API int scm_array_fill_int (SCM ra, SCM fill, SCM ignore);
SCM_API SCM scm_array_fill_x (SCM ra, SCM fill);
SCM_API SCM scm_array_copy_x (SCM src, SCM dst);
SCM_API SCM scm_array_map_x (SCM ra0, SCM proc, SCM lra);
@@ -42,6 +41,7 @@ SCM_INTERNAL void scm_init_array_map (void);
#if SCM_ENABLE_DEPRECATED == 1
+SCM_DEPRECATED int scm_array_fill_int (SCM ra, SCM fill, SCM ignore);
SCM_DEPRECATED int scm_ra_eqp (SCM ra0, SCM ras);
SCM_DEPRECATED int scm_ra_lessp (SCM ra0, SCM ras);
SCM_DEPRECATED int scm_ra_leqp (SCM ra0, SCM ras);
--
1.8.2
next prev parent reply other threads:[~2013-04-03 21:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1257718.1364809945.854.guile-devel@gnu.org>
2013-04-01 17:15 ` array-copy! is slow & array-map.c (was: Extremly slow for format & string-join) Daniel Llorens
2013-04-02 10:19 ` Daniel Llorens
2013-04-02 14:06 ` Daniel Llorens
2013-04-03 12:50 ` array-copy! is slow & array-map.c Ludovic Courtès
2013-04-03 14:50 ` Daniel Llorens
2013-04-03 17:03 ` Ludovic Courtès
2013-04-03 17:06 ` Ludovic Courtès
2013-04-03 17:59 ` Daniel Llorens
2013-04-03 17:07 ` Ludovic Courtès
2013-04-03 19:36 ` Ludovic Courtès
[not found] ` <ECA152EF-A180-45EF-9E8F-D40DD28A2779@jast.ch>
[not found] ` <87mwtfmlap.fsf@gnu.org>
2013-04-03 21:04 ` Daniel Llorens [this message]
2013-04-05 17:20 ` Ludovic Courtès
2013-04-05 17:29 ` Daniel Llorens
2013-04-05 20:32 ` Ludovic Courtès
2013-04-05 20:36 ` Ludovic Courtès
2013-04-06 22:59 ` Daniel Llorens
2013-04-06 23:01 ` Fwd: " Daniel Llorens
2013-04-07 9:18 ` Ludovic Courtès
2013-04-03 19:42 ` Ludovic Courtès
2013-04-02 14:55 ` array-copy! is slow & array-map.c (was: Extremly slow for format & string-join) Daniel Llorens
2013-04-02 14:57 ` Daniel Llorens
2013-04-02 15:14 ` Daniel Llorens
2013-04-03 12:05 ` array-copy! is slow & array-map.c Ludovic Courtès
2013-04-03 12:23 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A8A1B3E9-D5EA-4718-9A1A-5BC38A0DA881@jast.ch \
--to=dll@jast.ch \
--cc=guile-devel@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).