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