unif.h 6.8 KB

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