diff --git a/libguile/unif.c b/libguile/unif.c index 3eeaa85fa..f61f4e3b1 100644 --- a/libguile/unif.c +++ b/libguile/unif.c @@ -406,15 +406,58 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0, k = SCM_ARRAY_NDIM (ra); s = SCM_ARRAY_DIMS (ra); while (k--) - res = scm_cons (s[k].lbnd ? scm_cons2 (SCM_MAKINUM (s[k].lbnd), SCM_MAKINUM (s[k].ubnd), SCM_EOL) : - SCM_MAKINUM (1 + (s[k].ubnd)) - , res); + res = scm_cons (s[k].lbnd + ? scm_cons2 (SCM_MAKINUM (s[k].lbnd), + SCM_MAKINUM (s[k].ubnd), + SCM_EOL) + : SCM_MAKINUM (1 + s[k].ubnd), + res); return res; } } #undef FUNC_NAME +SCM_DEFINE (scm_shared_array_root, "shared-array-root", 1, 0, 0, + (SCM ra), + "Return the root vector of a shared array.") +#define FUNC_NAME s_scm_shared_array_root +{ + SCM_ASSERT (SCM_ARRAYP (ra), ra, SCM_ARG1, FUNC_NAME); + return SCM_ARRAY_V (ra); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_shared_array_offset, "shared-array-offset", 1, 0, 0, + (SCM ra), + "Return the root vector index of the first element in the array.") +#define FUNC_NAME s_scm_shared_array_offset +{ + SCM_ASSERT (SCM_ARRAYP (ra), ra, SCM_ARG1, FUNC_NAME); + return SCM_MAKINUM (SCM_ARRAY_BASE (ra)); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_shared_array_increments, "shared-array-increments", 1, 0, 0, + (SCM ra), + "For each dimension, return the distance between elements in the root vector.") +#define FUNC_NAME s_scm_shared_array_increments +{ + SCM res = SCM_EOL; + scm_sizet k; + scm_array_dim *s; + SCM_ASSERT (SCM_ARRAYP (ra), ra, SCM_ARG1, FUNC_NAME); + k = SCM_ARRAY_NDIM (ra); + s = SCM_ARRAY_DIMS (ra); + while (k--) + res = scm_cons (SCM_MAKINUM (s[k].inc), res); + return res; +} +#undef FUNC_NAME + + static char s_bad_ind[] = "Bad scm_array index"; diff --git a/libguile/unif.h b/libguile/unif.h index 0c133a27a..f840c3d82 100644 --- a/libguile/unif.h +++ b/libguile/unif.h @@ -101,6 +101,9 @@ extern SCM scm_uniform_vector_length (SCM v); extern SCM scm_array_p (SCM v, SCM prot); extern SCM scm_array_rank (SCM ra); extern SCM scm_array_dimensions (SCM ra); +extern SCM scm_shared_array_root (SCM ra); +extern SCM scm_shared_array_offset (SCM ra); +extern SCM scm_shared_array_increments (SCM ra); extern long scm_aind (SCM ra, SCM args, const char *what); extern SCM scm_make_ra (int ndim); extern SCM scm_shap2ra (SCM args, const char *what);