lloda pushed a commit to branch lloda-array-support
in repository guile.
commit 7d3851686b194e5c3d2044d12895116e9e8509ec
Author: Daniel Llorens <[email protected]>
Date: Wed Dec 9 12:57:19 2015 +0100
New export (array-for-each-cell-in-order)
* libguile/arrays.h (array-for-each-cell-in-order): Declare.
* libguile/arrays.c (array-for-each-cell-in-order): Define.
---
libguile/arrays.c | 14 +++++++++++++-
libguile/arrays.h | 1 +
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/libguile/arrays.c b/libguile/arrays.c
index de86023..0e8c6c2 100644
--- a/libguile/arrays.c
+++ b/libguile/arrays.c
@@ -594,6 +594,7 @@ SCM_DEFINE (scm_array_for_each_cell, "array-for-each-cell",
2, 0, 1,
{
// FIXME replace stack by scm_gc_malloc_pointerless()
int const N = scm_ilength(a_);
+ int const frank = scm_to_int(frank_);
scm_t_array_handle ah[N];
SCM a[N];
scm_t_array_dim * as[N];
@@ -606,7 +607,6 @@ SCM_DEFINE (scm_array_for_each_cell, "array-for-each-cell",
2, 0, 1,
rank[n] = scm_array_handle_rank(ah+n);
}
// checks.
- int const frank = scm_to_int(frank_);
ssize_t s[frank];
char const * msg = NULL;
if (frank<0)
@@ -757,6 +757,17 @@ SCM_DEFINE (scm_array_for_each_cell,
"array-for-each-cell", 2, 0, 1,
#undef FUNC_NAME
+SCM_DEFINE (scm_array_for_each_cell_in_order, "array-for-each-cell-in-order",
2, 0, 1,
+ (SCM frank_, SCM op, SCM a_),
+ "Same as array-for-each-cell, but visit the cells sequentially\n"
+ "and in row-major order.\n")
+#define FUNC_NAME s_scm_array_for_each_cell_in_order
+{
+ return scm_array_for_each_cell (frank_, op, a_);
+}
+#undef FUNC_NAME
+
+
/* args are RA . DIMS */
SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
(SCM ra, SCM args),
@@ -1131,6 +1142,7 @@ scm_i_print_array (SCM array, SCM port, scm_print_state
*pstate)
return scm_i_print_array_dimension (&h, 0, 0, port, pstate);
}
+
void
scm_init_arrays ()
{
diff --git a/libguile/arrays.h b/libguile/arrays.h
index 5a88b72..b43e93c 100644
--- a/libguile/arrays.h
+++ b/libguile/arrays.h
@@ -53,6 +53,7 @@ SCM_API SCM scm_array_from_s (SCM ra, SCM indices);
SCM_API SCM scm_array_from (SCM ra, SCM indices);
SCM_API SCM scm_array_amend_x (SCM ra, SCM b, SCM indices);
SCM_API SCM scm_array_for_each_cell (SCM frank, SCM op, SCM args);
+SCM_API SCM scm_array_for_each_cell_in_order (SCM frank, SCM op, SCM args);
SCM_API SCM scm_list_to_array (SCM ndim, SCM lst);
SCM_API SCM scm_list_to_typed_array (SCM type, SCM ndim, SCM lst);