mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-16 08:40:19 +02:00
Merge commit 'fb7dd00169
'
This commit also renames uniform-vector-element-type-code to array-type-code. Conflicts: libguile/uniform.c libguile/uniform.h test-suite/tests/arrays.test
This commit is contained in:
commit
8051cf2304
11 changed files with 91 additions and 331 deletions
|
@ -81,178 +81,6 @@ scm_array_handle_uniform_writable_elements (scm_t_array_handle *h)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
scm_is_uniform_vector (SCM obj)
|
||||
{
|
||||
scm_t_array_handle h;
|
||||
int ret = 0;
|
||||
|
||||
if (scm_is_array (obj))
|
||||
{
|
||||
scm_array_get_handle (obj, &h);
|
||||
ret = (scm_array_handle_rank (&h) == 1
|
||||
&& SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h.element_type));
|
||||
scm_array_handle_release (&h);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t
|
||||
scm_c_uniform_vector_length (SCM uvec)
|
||||
{
|
||||
if (!scm_is_uniform_vector (uvec))
|
||||
scm_wrong_type_arg_msg ("uniform-vector-length", 1, uvec,
|
||||
"uniform vector");
|
||||
return scm_c_array_length (uvec);
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_p, "uniform-vector?", 1, 0, 0,
|
||||
(SCM obj),
|
||||
"Return @code{#t} if @var{obj} is a uniform vector.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_p
|
||||
{
|
||||
return scm_from_bool (scm_is_uniform_vector (obj));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_element_type, "uniform-vector-element-type", 1, 0, 0,
|
||||
(SCM v),
|
||||
"Return the type of the elements in the uniform vector, @var{v}.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_element_type
|
||||
{
|
||||
scm_t_array_handle h;
|
||||
SCM ret;
|
||||
|
||||
if (!scm_is_uniform_vector (v))
|
||||
scm_wrong_type_arg_msg (FUNC_NAME, SCM_ARG1, v, "uniform vector");
|
||||
scm_array_get_handle (v, &h);
|
||||
ret = scm_array_handle_element_type (&h);
|
||||
scm_array_handle_release (&h);
|
||||
return ret;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_element_type_code,
|
||||
"uniform-vector-element-type-code", 1, 0, 0,
|
||||
(SCM v),
|
||||
"Return the type of the elements in the uniform vector, @var{v},\n"
|
||||
"as an integer code.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_element_type_code
|
||||
{
|
||||
scm_t_array_handle h;
|
||||
SCM ret;
|
||||
|
||||
if (!scm_is_uniform_vector (v))
|
||||
scm_wrong_type_arg_msg (FUNC_NAME, SCM_ARG1, v, "uniform vector");
|
||||
scm_array_get_handle (v, &h);
|
||||
ret = scm_from_uint16 (h.element_type);
|
||||
scm_array_handle_release (&h);
|
||||
return ret;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_element_size, "uniform-vector-element-size", 1, 0, 0,
|
||||
(SCM v),
|
||||
"Return the number of bytes allocated to each element in the\n"
|
||||
"uniform vector, @var{v}.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_element_size
|
||||
{
|
||||
scm_t_array_handle h;
|
||||
size_t len;
|
||||
ssize_t inc;
|
||||
SCM ret;
|
||||
scm_uniform_vector_elements (v, &h, &len, &inc);
|
||||
ret = scm_from_size_t (scm_array_handle_uniform_element_size (&h));
|
||||
scm_array_handle_release (&h);
|
||||
return ret;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM
|
||||
scm_c_uniform_vector_ref (SCM v, size_t pos)
|
||||
{
|
||||
if (!scm_is_uniform_vector (v))
|
||||
scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector");
|
||||
return scm_c_array_ref_1 (v, pos);
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
|
||||
(SCM v, SCM idx),
|
||||
"Return the element at index @var{idx} of the\n"
|
||||
"homogeneous numeric vector @var{v}.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_ref
|
||||
{
|
||||
return scm_c_uniform_vector_ref (v, scm_to_size_t (idx));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
void
|
||||
scm_c_uniform_vector_set_x (SCM v, size_t pos, SCM val)
|
||||
{
|
||||
if (!scm_is_uniform_vector (v))
|
||||
scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector");
|
||||
scm_c_array_set_1_x (v, val, pos);
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_set_x, "uniform-vector-set!", 3, 0, 0,
|
||||
(SCM v, SCM idx, SCM val),
|
||||
"Set the element at index @var{idx} of the\n"
|
||||
"homogeneous numeric vector @var{v} to @var{val}.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_set_x
|
||||
{
|
||||
scm_c_uniform_vector_set_x (v, scm_to_size_t (idx), val);
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_to_list, "uniform-vector->list", 1, 0, 0,
|
||||
(SCM uvec),
|
||||
"Convert the uniform numeric vector @var{uvec} to a list.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_to_list
|
||||
{
|
||||
if (!scm_is_uniform_vector (uvec))
|
||||
scm_wrong_type_arg_msg (FUNC_NAME, SCM_ARG1, uvec, "uniform vector");
|
||||
return scm_array_to_list (uvec);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
const void *
|
||||
scm_uniform_vector_elements (SCM uvec,
|
||||
scm_t_array_handle *h,
|
||||
size_t *lenp, ssize_t *incp)
|
||||
{
|
||||
return scm_uniform_vector_writable_elements (uvec, h, lenp, incp);
|
||||
}
|
||||
|
||||
void *
|
||||
scm_uniform_vector_writable_elements (SCM uvec,
|
||||
scm_t_array_handle *h,
|
||||
size_t *lenp, ssize_t *incp)
|
||||
{
|
||||
void *ret;
|
||||
scm_array_get_handle (uvec, h);
|
||||
if (scm_array_handle_rank (h) != 1)
|
||||
scm_wrong_type_arg_msg (0, SCM_ARG1, uvec, "uniform vector");
|
||||
ret = scm_array_handle_uniform_writable_elements (h);
|
||||
if (lenp)
|
||||
{
|
||||
scm_t_array_dim *dim = scm_array_handle_dims (h);
|
||||
*lenp = dim->ubnd - dim->lbnd + 1;
|
||||
*incp = dim->inc;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_uniform_vector_length, "uniform-vector-length", 1, 0, 0,
|
||||
(SCM v),
|
||||
"Return the number of elements in the uniform vector @var{v}.")
|
||||
#define FUNC_NAME s_scm_uniform_vector_length
|
||||
{
|
||||
return scm_from_size_t (scm_c_uniform_vector_length (v));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
void
|
||||
scm_init_uniform (void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue