[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 09/16: Don't use array handles in scm_c_array_rank
From: |
Daniel Llorens |
Subject: |
[Guile-commits] 09/16: Don't use array handles in scm_c_array_rank |
Date: |
Fri, 13 Nov 2015 14:30:50 +0000 |
lloda pushed a commit to branch lloda-array-support
in repository guile.
commit 5f056bdb64061246b0ea194013eb4644b9b4c2c9
Author: Daniel Llorens <address@hidden>
Date: Thu Feb 12 10:15:42 2015 +0100
Don't use array handles in scm_c_array_rank
* libguile/arrays.c (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.
---
libguile/arrays.c | 21 ++++++++++++++++++++
libguile/arrays.h | 3 ++
libguile/generalized-arrays.c | 43 ++++++++++------------------------------
libguile/generalized-arrays.h | 3 --
4 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/libguile/arrays.c b/libguile/arrays.c
index 04896f5..c9333b8 100644
--- a/libguile/arrays.c
+++ b/libguile/arrays.c
@@ -64,6 +64,27 @@
(SCM_SET_CELL_WORD_0 ((x), SCM_CELL_WORD_0 (x) &
~(SCM_I_ARRAY_FLAG_CONTIGUOUS << 16)))
+size_t
+scm_c_array_rank (SCM array)
+{
+ if (SCM_I_ARRAYP (array))
+ return SCM_I_ARRAY_NDIM (array);
+ else if (scm_is_array (array))
+ return 1;
+ else
+ scm_wrong_type_arg_msg ("array-rank", SCM_ARG1, array, "array");
+}
+
+SCM_DEFINE (scm_array_rank, "array-rank", 1, 0, 0,
+ (SCM array),
+ "Return the number of dimensions of the array @var{array.}\n")
+#define FUNC_NAME s_scm_array_rank
+{
+ return scm_from_size_t (scm_c_array_rank (array));
+}
+#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.")
diff --git a/libguile/arrays.h b/libguile/arrays.h
index bd216ae..9b7fd6c 100644
--- a/libguile/arrays.h
+++ b/libguile/arrays.h
@@ -56,6 +56,9 @@ SCM_API SCM scm_array_amend_x (SCM ra, SCM b, SCM indices);
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);
+SCM_API size_t scm_c_array_rank (SCM ra);
+SCM_API SCM scm_array_rank (SCM ra);
+
/* internal. */
#define SCM_I_ARRAY_FLAG_CONTIGUOUS (1 << 0) /* currently unused */
diff --git a/libguile/generalized-arrays.c b/libguile/generalized-arrays.c
index 9a001eb..99125f2 100644
--- a/libguile/generalized-arrays.c
+++ b/libguile/generalized-arrays.c
@@ -1,5 +1,5 @@
/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006,
2009, 2010, 2013, 2014 Free Software Foundation, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
@@ -104,27 +104,6 @@ SCM_DEFINE (scm_typed_array_p, "typed-array?", 2, 0, 0,
}
#undef FUNC_NAME
-size_t
-scm_c_array_rank (SCM array)
-{
- scm_t_array_handle handle;
- size_t res;
-
- scm_array_get_handle (array, &handle);
- res = scm_array_handle_rank (&handle);
- scm_array_handle_release (&handle);
- return res;
-}
-
-SCM_DEFINE (scm_array_rank, "array-rank", 1, 0, 0,
- (SCM array),
- "Return the number of dimensions of the array @var{array.}\n")
-#define FUNC_NAME s_scm_array_rank
-{
- return scm_from_size_t (scm_c_array_rank (array));
-}
-#undef FUNC_NAME
-
size_t
scm_c_array_length (SCM array)
@@ -144,7 +123,7 @@ scm_c_array_length (SCM array)
return res;
}
-SCM_DEFINE (scm_array_length, "array-length", 1, 0, 0,
+SCM_DEFINE (scm_array_length, "array-length", 1, 0, 0,
(SCM array),
"Return the length of an array: its first dimension.\n"
"It is an error to ask for the length of an array of rank 0.")
@@ -155,7 +134,7 @@ SCM_DEFINE (scm_array_length, "array-length", 1, 0, 0,
#undef FUNC_NAME
-SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0,
+SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0,
(SCM ra),
"@code{array-dimensions} is similar to @code{array-shape} but
replaces\n"
"elements with a @code{0} minimum with one greater than the
maximum. So:\n"
@@ -168,7 +147,7 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0,
0,
scm_t_array_dim *s;
SCM res = SCM_EOL;
size_t k;
-
+
scm_array_get_handle (ra, &handle);
s = scm_array_handle_dims (&handle);
k = scm_array_handle_rank (&handle);
@@ -186,7 +165,7 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0,
0,
}
#undef FUNC_NAME
-SCM_DEFINE (scm_array_type, "array-type", 1, 0, 0,
+SCM_DEFINE (scm_array_type, "array-type", 1, 0, 0,
(SCM ra),
"")
#define FUNC_NAME s_scm_array_type
@@ -197,7 +176,7 @@ SCM_DEFINE (scm_array_type, "array-type", 1, 0, 0,
scm_array_get_handle (ra, &h);
type = scm_array_handle_element_type (&h);
scm_array_handle_release (&h);
-
+
return type;
}
#undef FUNC_NAME
@@ -220,7 +199,7 @@ SCM_DEFINE (scm_array_type_code,
}
#undef FUNC_NAME
-SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
+SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
(SCM ra, SCM args),
"Return @code{#t} if its arguments would be acceptable to\n"
"@code{array-ref}.")
@@ -376,7 +355,7 @@ SCM_DEFINE (scm_i_array_set_x, "array-set!", 2, 2, 1,
#undef FUNC_NAME
-static SCM
+static SCM
array_to_list (scm_t_array_handle *h, size_t dim, unsigned long pos)
{
if (dim == scm_array_handle_rank (h))
@@ -397,7 +376,7 @@ array_to_list (scm_t_array_handle *h, size_t dim, unsigned
long pos)
}
}
-SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
+SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
(SCM array),
"Return a list representation of @var{array}.\n\n"
"It is easiest to specify the behavior of this function by\n"
@@ -410,8 +389,8 @@ SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
#define FUNC_NAME s_scm_array_to_list
{
scm_t_array_handle h;
- SCM res;
-
+ SCM res;
+
scm_array_get_handle (array, &h);
res = array_to_list (&h, 0, 0);
scm_array_handle_release (&h);
diff --git a/libguile/generalized-arrays.h b/libguile/generalized-arrays.h
index dfdb8bd..cfa6905 100644
--- a/libguile/generalized-arrays.h
+++ b/libguile/generalized-arrays.h
@@ -41,9 +41,6 @@ SCM_INTERNAL SCM scm_array_p_2 (SCM);
SCM_API int scm_is_typed_array (SCM obj, SCM type);
SCM_API SCM scm_typed_array_p (SCM v, SCM type);
-SCM_API size_t scm_c_array_rank (SCM ra);
-SCM_API SCM scm_array_rank (SCM ra);
-
SCM_API size_t scm_c_array_length (SCM ra);
SCM_API SCM scm_array_length (SCM ra);
- [Guile-commits] branch lloda-array-support updated (5adfbef -> fea3974), Daniel Llorens, 2015/11/13
- [Guile-commits] 01/16: Avoid unneeded internal use of array handles, Daniel Llorens, 2015/11/13
- [Guile-commits] 04/16: Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle, Daniel Llorens, 2015/11/13
- [Guile-commits] 02/16: Remove scm_from_contiguous_array, Daniel Llorens, 2015/11/13
- [Guile-commits] 05/16: Compile in C99 mode, Daniel Llorens, 2015/11/13
- [Guile-commits] 06/16: New functions array-from, array-from*, array-set-from!, Daniel Llorens, 2015/11/13
- [Guile-commits] 07/16: Tests & doc for array-from, array-from*, array-set-from!, Daniel Llorens, 2015/11/13
- [Guile-commits] 10/16: Fix compilation of rank 0 typed array literals, Daniel Llorens, 2015/11/13
- [Guile-commits] 09/16: Don't use array handles in scm_c_array_rank,
Daniel Llorens <=
- [Guile-commits] 03/16: Unuse array 'contiguous' flag, Daniel Llorens, 2015/11/13
- [Guile-commits] 11/16: Remove deprecated array functions, Daniel Llorens, 2015/11/13
- [Guile-commits] 08/16: Rename array-set-from!, scm_array_set_from_x to array-amend!, scm_array_amend_x, Daniel Llorens, 2015/11/13
- [Guile-commits] 12/16: Speed up for multi-arg cases of scm_ramap functions, Daniel Llorens, 2015/11/13
- [Guile-commits] 13/16: Remove deprecated and unused generalized-vector functions, Daniel Llorens, 2015/11/13
- [Guile-commits] 14/16: Do not use array handles in scm_vector, Daniel Llorens, 2015/11/13
- [Guile-commits] 16/16: Draft documentation for (array-for-each-cell), Daniel Llorens, 2015/11/13
- [Guile-commits] 15/16: Draft of (array-for-each-cell), Daniel Llorens, 2015/11/13