2006-02-01 Ludovic Courtès <ludovic.courtes@laas.fr>
[bpt/guile.git] / libguile / unif.h
CommitLineData
0f2d19dd
JB
1/* classes: h_files */
2
b29058ff
DH
3#ifndef SCM_UNIF_H
4#define SCM_UNIF_H
5
21959222 6/* Copyright (C) 1995,1996,1997,1999,2000,2001, 2004 Free Software Foundation, Inc.
b29058ff 7 *
73be1d9e
MV
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
b29058ff 12 *
73be1d9e 13 * This library is distributed in the hope that it will be useful,
0f2d19dd 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
b29058ff 17 *
73be1d9e
MV
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
92205699 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73be1d9e 21 */
d3a6bc94 22
0f2d19dd
JB
23\f
24
b4309c3c 25#include "libguile/__scm.h"
9598a406 26#include "libguile/print.h"
0f2d19dd
JB
27
28\f
1d7bdb25 29
20930f28
MV
30/* This file contains the definitions for arrays and bit vectors.
31 Uniform numeric vectors are now in srfi-4.c.
32*/
33
34
35/** Arrays */
36
4cf8074f
MV
37typedef struct scm_t_array_dim
38{
39 ssize_t lbnd;
40 ssize_t ubnd;
41 ssize_t inc;
42} scm_t_array_dim;
1d7bdb25 43
33b001fd 44SCM_API SCM scm_array_p (SCM v, SCM prot);
f301dbf3
MV
45SCM_API SCM scm_typed_array_p (SCM v, SCM type);
46SCM_API SCM scm_make_array (SCM fill, SCM bounds);
47SCM_API SCM scm_make_typed_array (SCM type, SCM fill, SCM bounds);
33b001fd 48SCM_API SCM scm_array_rank (SCM ra);
04b87de5 49SCM_API size_t scm_c_array_rank (SCM ra);
33b001fd
MV
50SCM_API SCM scm_array_dimensions (SCM ra);
51SCM_API SCM scm_shared_array_root (SCM ra);
52SCM_API SCM scm_shared_array_offset (SCM ra);
53SCM_API SCM scm_shared_array_increments (SCM ra);
33b001fd
MV
54SCM_API SCM scm_make_shared_array (SCM oldra, SCM mapfunc, SCM dims);
55SCM_API SCM scm_transpose_array (SCM ra, SCM args);
56SCM_API SCM scm_enclose_array (SCM ra, SCM axes);
57SCM_API SCM scm_array_in_bounds_p (SCM v, SCM args);
e0e49670 58SCM_API SCM scm_array_ref (SCM v, SCM args);
33b001fd
MV
59SCM_API SCM scm_array_set_x (SCM v, SCM obj, SCM args);
60SCM_API SCM scm_array_contents (SCM ra, SCM strict);
02339e5b
MV
61SCM_API SCM scm_uniform_array_read_x (SCM ra, SCM port_or_fd,
62 SCM start, SCM end);
63SCM_API SCM scm_uniform_array_write (SCM v, SCM port_or_fd,
64 SCM start, SCM end);
20930f28 65SCM_API SCM scm_array_to_list (SCM v);
f301dbf3
MV
66SCM_API SCM scm_list_to_array (SCM ndim, SCM lst);
67SCM_API SCM scm_list_to_typed_array (SCM type, SCM ndim, SCM lst);
68SCM_API SCM scm_array_type (SCM ra);
69
70SCM_API int scm_is_array (SCM obj);
71SCM_API int scm_is_typed_array (SCM obj, SCM type);
20930f28 72
0cd6cb2f 73SCM_API SCM scm_ra2contig (SCM ra, int copy);
20930f28 74
9598a406
MV
75struct scm_t_array_handle;
76
77typedef SCM (*scm_i_t_array_ref) (struct scm_t_array_handle *, ssize_t);
78typedef void (*scm_i_t_array_set) (struct scm_t_array_handle *, ssize_t, SCM);
79
80typedef struct scm_t_array_handle {
6e708ef2
MV
81 SCM array;
82 size_t base;
83 scm_t_array_dim *dims;
84 scm_t_array_dim dim0;
9598a406
MV
85 scm_i_t_array_ref ref;
86 scm_i_t_array_set set;
87 const void *elements;
88 void *writable_elements;
6e708ef2
MV
89} scm_t_array_handle;
90
91SCM_API void scm_array_get_handle (SCM array, scm_t_array_handle *h);
92SCM_API size_t scm_array_handle_rank (scm_t_array_handle *h);
93SCM_API scm_t_array_dim *scm_array_handle_dims (scm_t_array_handle *h);
0cd6cb2f 94SCM_API ssize_t scm_array_handle_pos (scm_t_array_handle *h, SCM indices);
6e708ef2
MV
95SCM_API const SCM *scm_array_handle_elements (scm_t_array_handle *h);
96SCM_API SCM *scm_array_handle_writable_elements (scm_t_array_handle *h);
cdd6e0a8 97SCM_API void scm_array_handle_release (scm_t_array_handle *h);
6e708ef2 98
9598a406
MV
99/* See inline.h for scm_array_handle_ref and scm_array_handle_set */
100
20930f28
MV
101\f
102/** Bit vectors */
103
104SCM_API SCM scm_bitvector_p (SCM vec);
105SCM_API SCM scm_bitvector (SCM bits);
106SCM_API SCM scm_make_bitvector (SCM len, SCM fill);
107SCM_API SCM scm_bitvector_length (SCM vec);
108SCM_API SCM scm_bitvector_ref (SCM vec, SCM idx);
109SCM_API SCM scm_bitvector_set_x (SCM vec, SCM idx, SCM val);
110SCM_API SCM scm_list_to_bitvector (SCM list);
111SCM_API SCM scm_bitvector_to_list (SCM vec);
112SCM_API SCM scm_bitvector_fill_x (SCM vec, SCM val);
113
33b001fd
MV
114SCM_API SCM scm_bit_count (SCM item, SCM seq);
115SCM_API SCM scm_bit_position (SCM item, SCM v, SCM k);
116SCM_API SCM scm_bit_set_star_x (SCM v, SCM kv, SCM obj);
117SCM_API SCM scm_bit_count_star (SCM v, SCM kv, SCM obj);
118SCM_API SCM scm_bit_invert_x (SCM v);
0cd6cb2f 119SCM_API SCM scm_istr2bve (SCM str);
21959222 120
20930f28
MV
121SCM_API int scm_is_bitvector (SCM obj);
122SCM_API SCM scm_c_make_bitvector (size_t len, SCM fill);
123SCM_API size_t scm_c_bitvector_length (SCM vec);
124SCM_API SCM scm_c_bitvector_ref (SCM vec, size_t idx);
125SCM_API void scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val);
f0b91039
MV
126SCM_API const scm_t_uint32 *scm_array_handle_bit_elements (scm_t_array_handle *h);
127SCM_API scm_t_uint32 *scm_array_handle_bit_writable_elements (scm_t_array_handle *h);
128SCM_API size_t scm_array_handle_bit_elements_offset (scm_t_array_handle *h);
129SCM_API const scm_t_uint32 *scm_bitvector_elements (SCM vec,
130 scm_t_array_handle *h,
cdd6e0a8 131 size_t *offp,
f0b91039
MV
132 size_t *lenp,
133 ssize_t *incp);
134SCM_API scm_t_uint32 *scm_bitvector_writable_elements (SCM vec,
135 scm_t_array_handle *h,
cdd6e0a8 136 size_t *offp,
f0b91039
MV
137 size_t *lenp,
138 ssize_t *incp);
bfad4005 139
0cd6cb2f
MV
140/* internal. */
141
04b87de5
MV
142typedef struct scm_i_t_array
143{
144 SCM v; /* the contents of the array, e.g., a vector or uniform vector. */
145 unsigned long base;
146} scm_i_t_array;
147
148SCM_API scm_t_bits scm_i_tc16_array;
149SCM_API scm_t_bits scm_i_tc16_enclosed_array;
150
151#define SCM_I_ARRAY_FLAG_CONTIGUOUS (1 << 16)
152
153#define SCM_I_ARRAYP(a) SCM_TYP16_PREDICATE (scm_i_tc16_array, a)
154#define SCM_I_ENCLOSED_ARRAYP(a) \
155 SCM_TYP16_PREDICATE (scm_i_tc16_enclosed_array, a)
156#define SCM_I_ARRAY_NDIM(x) ((size_t) (SCM_CELL_WORD_0 (x) >> 17))
157#define SCM_I_ARRAY_CONTP(x) (SCM_CELL_WORD_0(x) & SCM_I_ARRAY_FLAG_CONTIGUOUS)
158
159#define SCM_I_ARRAY_MEM(a) ((scm_i_t_array *) SCM_CELL_WORD_1 (a))
160#define SCM_I_ARRAY_V(a) (SCM_I_ARRAY_MEM (a)->v)
161#define SCM_I_ARRAY_BASE(a) (SCM_I_ARRAY_MEM (a)->base)
162#define SCM_I_ARRAY_DIMS(a) \
163 ((scm_t_array_dim *)((char *) SCM_I_ARRAY_MEM (a) + sizeof (scm_i_t_array)))
164
0cd6cb2f
MV
165SCM_API SCM scm_i_make_ra (int ndim, int enclosed);
166SCM_API SCM scm_i_cvref (SCM v, size_t p, int enclosed);
167SCM_API SCM scm_i_read_array (SCM port, int c);
168
21959222
MV
169/* deprecated. */
170
6e708ef2
MV
171#if SCM_ENABLE_DEPRECATED
172
21959222 173SCM_API SCM scm_make_uve (long k, SCM prot);
6e708ef2
MV
174SCM_API SCM scm_array_prototype (SCM ra);
175SCM_API SCM scm_list_to_uniform_array (SCM ndim, SCM prot, SCM lst);
176SCM_API SCM scm_dimensions_to_uniform_array (SCM dims, SCM prot, SCM fill);
21959222 177SCM_API SCM scm_make_ra (int ndim);
0cd6cb2f 178SCM_API SCM scm_shap2ra (SCM args, const char *what);
21959222 179SCM_API SCM scm_cvref (SCM v, unsigned long pos, SCM last);
0cd6cb2f 180SCM_API void scm_ra_set_contp (SCM ra);
02339e5b 181SCM_API long scm_aind (SCM ra, SCM args, const char *what);
0cd6cb2f 182SCM_API int scm_raprin1 (SCM exp, SCM port, scm_print_state *pstate);
04b87de5 183
0cd6cb2f 184#endif
20930f28 185
33b001fd 186SCM_API void scm_init_unif (void);
0f2d19dd 187
b29058ff 188#endif /* SCM_UNIF_H */
89e00824
ML
189
190/*
191 Local Variables:
192 c-file-style: "gnu"
193 End:
194*/