unif.test 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. ;;;; unif.test --- tests guile's uniform arrays -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2004, 2006 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 2.1 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-unif)
  19. #:use-module (test-suite lib))
  20. ;;;
  21. ;;; array?
  22. ;;;
  23. (define exception:wrong-num-indices
  24. (cons 'misc-error "^wrong number of indices.*"))
  25. (define exception:length-non-negative
  26. (cons 'read-error ".*array length must be non-negative.*"))
  27. (with-test-prefix "array?"
  28. (let ((bool (make-typed-array 'b #t '(5 6)))
  29. (char (make-typed-array 'a #\a '(5 6)))
  30. (byte (make-typed-array 'u8 0 '(5 6)))
  31. (short (make-typed-array 's16 0 '(5 6)))
  32. (ulong (make-typed-array 'u32 0 '(5 6)))
  33. (long (make-typed-array 's32 0 '(5 6)))
  34. (longlong (make-typed-array 's64 0 '(5 6)))
  35. (float (make-typed-array 'f32 0 '(5 6)))
  36. (double (make-typed-array 'f64 0 '(5 6)))
  37. (complex (make-typed-array 'c64 0 '(5 6)))
  38. (scm (make-typed-array #t 0 '(5 6))))
  39. (with-test-prefix "is bool"
  40. (pass-if (eq? #t (typed-array? bool 'b)))
  41. (pass-if (eq? #f (typed-array? char 'b)))
  42. (pass-if (eq? #f (typed-array? byte 'b)))
  43. (pass-if (eq? #f (typed-array? short 'b)))
  44. (pass-if (eq? #f (typed-array? ulong 'b)))
  45. (pass-if (eq? #f (typed-array? long 'b)))
  46. (pass-if (eq? #f (typed-array? longlong 'b)))
  47. (pass-if (eq? #f (typed-array? float 'b)))
  48. (pass-if (eq? #f (typed-array? double 'b)))
  49. (pass-if (eq? #f (typed-array? complex 'b)))
  50. (pass-if (eq? #f (typed-array? scm 'b))))
  51. (with-test-prefix "is char"
  52. (pass-if (eq? #f (typed-array? bool 'a)))
  53. (pass-if (eq? #t (typed-array? char 'a)))
  54. (pass-if (eq? #f (typed-array? byte 'a)))
  55. (pass-if (eq? #f (typed-array? short 'a)))
  56. (pass-if (eq? #f (typed-array? ulong 'a)))
  57. (pass-if (eq? #f (typed-array? long 'a)))
  58. (pass-if (eq? #f (typed-array? longlong 'a)))
  59. (pass-if (eq? #f (typed-array? float 'a)))
  60. (pass-if (eq? #f (typed-array? double 'a)))
  61. (pass-if (eq? #f (typed-array? complex 'a)))
  62. (pass-if (eq? #f (typed-array? scm 'a))))
  63. (with-test-prefix "is byte"
  64. (pass-if (eq? #f (typed-array? bool 'u8)))
  65. (pass-if (eq? #f (typed-array? char 'u8)))
  66. (pass-if (eq? #t (typed-array? byte 'u8)))
  67. (pass-if (eq? #f (typed-array? short 'u8)))
  68. (pass-if (eq? #f (typed-array? ulong 'u8)))
  69. (pass-if (eq? #f (typed-array? long 'u8)))
  70. (pass-if (eq? #f (typed-array? longlong 'u8)))
  71. (pass-if (eq? #f (typed-array? float 'u8)))
  72. (pass-if (eq? #f (typed-array? double 'u8)))
  73. (pass-if (eq? #f (typed-array? complex 'u8)))
  74. (pass-if (eq? #f (typed-array? scm 'u8))))
  75. (with-test-prefix "is short"
  76. (pass-if (eq? #f (typed-array? bool 's16)))
  77. (pass-if (eq? #f (typed-array? char 's16)))
  78. (pass-if (eq? #f (typed-array? byte 's16)))
  79. (pass-if (eq? #t (typed-array? short 's16)))
  80. (pass-if (eq? #f (typed-array? ulong 's16)))
  81. (pass-if (eq? #f (typed-array? long 's16)))
  82. (pass-if (eq? #f (typed-array? longlong 's16)))
  83. (pass-if (eq? #f (typed-array? float 's16)))
  84. (pass-if (eq? #f (typed-array? double 's16)))
  85. (pass-if (eq? #f (typed-array? complex 's16)))
  86. (pass-if (eq? #f (typed-array? scm 's16))))
  87. (with-test-prefix "is ulong"
  88. (pass-if (eq? #f (typed-array? bool 'u32)))
  89. (pass-if (eq? #f (typed-array? char 'u32)))
  90. (pass-if (eq? #f (typed-array? byte 'u32)))
  91. (pass-if (eq? #f (typed-array? short 'u32)))
  92. (pass-if (eq? #t (typed-array? ulong 'u32)))
  93. (pass-if (eq? #f (typed-array? long 'u32)))
  94. (pass-if (eq? #f (typed-array? longlong 'u32)))
  95. (pass-if (eq? #f (typed-array? float 'u32)))
  96. (pass-if (eq? #f (typed-array? double 'u32)))
  97. (pass-if (eq? #f (typed-array? complex 'u32)))
  98. (pass-if (eq? #f (typed-array? scm 'u32))))
  99. (with-test-prefix "is long"
  100. (pass-if (eq? #f (typed-array? bool 's32)))
  101. (pass-if (eq? #f (typed-array? char 's32)))
  102. (pass-if (eq? #f (typed-array? byte 's32)))
  103. (pass-if (eq? #f (typed-array? short 's32)))
  104. (pass-if (eq? #f (typed-array? ulong 's32)))
  105. (pass-if (eq? #t (typed-array? long 's32)))
  106. (pass-if (eq? #f (typed-array? longlong 's32)))
  107. (pass-if (eq? #f (typed-array? float 's32)))
  108. (pass-if (eq? #f (typed-array? double 's32)))
  109. (pass-if (eq? #f (typed-array? complex 's32)))
  110. (pass-if (eq? #f (typed-array? scm 's32))))
  111. (with-test-prefix "is long long"
  112. (pass-if (eq? #f (typed-array? bool 's64)))
  113. (pass-if (eq? #f (typed-array? char 's64)))
  114. (pass-if (eq? #f (typed-array? byte 's64)))
  115. (pass-if (eq? #f (typed-array? short 's64)))
  116. (pass-if (eq? #f (typed-array? ulong 's64)))
  117. (pass-if (eq? #f (typed-array? long 's64)))
  118. (pass-if (eq? #t (typed-array? longlong 's64)))
  119. (pass-if (eq? #f (typed-array? float 's64)))
  120. (pass-if (eq? #f (typed-array? double 's64)))
  121. (pass-if (eq? #f (typed-array? complex 's64)))
  122. (pass-if (eq? #f (typed-array? scm 's64))))
  123. (with-test-prefix "is float"
  124. (pass-if (eq? #f (typed-array? bool 'f32)))
  125. (pass-if (eq? #f (typed-array? char 'f32)))
  126. (pass-if (eq? #f (typed-array? byte 'f32)))
  127. (pass-if (eq? #f (typed-array? short 'f32)))
  128. (pass-if (eq? #f (typed-array? ulong 'f32)))
  129. (pass-if (eq? #f (typed-array? long 'f32)))
  130. (pass-if (eq? #f (typed-array? longlong 'f32)))
  131. (pass-if (eq? #t (typed-array? float 'f32)))
  132. (pass-if (eq? #f (typed-array? double 'f32)))
  133. (pass-if (eq? #f (typed-array? complex 'f32)))
  134. (pass-if (eq? #f (typed-array? scm 'f32))))
  135. (with-test-prefix "is double"
  136. (pass-if (eq? #f (typed-array? bool 'f64)))
  137. (pass-if (eq? #f (typed-array? char 'f64)))
  138. (pass-if (eq? #f (typed-array? byte 'f64)))
  139. (pass-if (eq? #f (typed-array? short 'f64)))
  140. (pass-if (eq? #f (typed-array? ulong 'f64)))
  141. (pass-if (eq? #f (typed-array? long 'f64)))
  142. (pass-if (eq? #f (typed-array? longlong 'f64)))
  143. (pass-if (eq? #f (typed-array? float 'f64)))
  144. (pass-if (eq? #t (typed-array? double 'f64)))
  145. (pass-if (eq? #f (typed-array? complex 'f64)))
  146. (pass-if (eq? #f (typed-array? scm 'f64))))
  147. (with-test-prefix "is complex"
  148. (pass-if (eq? #f (typed-array? bool 'c64)))
  149. (pass-if (eq? #f (typed-array? char 'c64)))
  150. (pass-if (eq? #f (typed-array? byte 'c64)))
  151. (pass-if (eq? #f (typed-array? short 'c64)))
  152. (pass-if (eq? #f (typed-array? ulong 'c64)))
  153. (pass-if (eq? #f (typed-array? long 'c64)))
  154. (pass-if (eq? #f (typed-array? longlong 'c64)))
  155. (pass-if (eq? #f (typed-array? float 'c64)))
  156. (pass-if (eq? #f (typed-array? double 'c64)))
  157. (pass-if (eq? #t (typed-array? complex 'c64)))
  158. (pass-if (eq? #f (typed-array? scm 'c64))))
  159. (with-test-prefix "is scm"
  160. (pass-if (eq? #f (typed-array? bool #t)))
  161. (pass-if (eq? #f (typed-array? char #t)))
  162. (pass-if (eq? #f (typed-array? byte #t)))
  163. (pass-if (eq? #f (typed-array? short #t)))
  164. (pass-if (eq? #f (typed-array? ulong #t)))
  165. (pass-if (eq? #f (typed-array? long #t)))
  166. (pass-if (eq? #f (typed-array? longlong #t)))
  167. (pass-if (eq? #f (typed-array? float #t)))
  168. (pass-if (eq? #f (typed-array? double #t)))
  169. (pass-if (eq? #f (typed-array? complex #t)))
  170. (pass-if (eq? #t (typed-array? scm #t))))))
  171. ;;;
  172. ;;; array-equal?
  173. ;;;
  174. (with-test-prefix "array-equal?"
  175. (pass-if "#s16(...)"
  176. (array-equal? #s16(1 2 3) #s16(1 2 3))))
  177. ;;;
  178. ;;; array-fill!
  179. ;;;
  180. (with-test-prefix "array-fill!"
  181. (with-test-prefix "bool"
  182. (let ((a (make-bitvector 1 #t)))
  183. (pass-if "#f" (array-fill! a #f) #t)
  184. (pass-if "#t" (array-fill! a #t) #t)))
  185. (with-test-prefix "char"
  186. (let ((a (make-string 1 #\a)))
  187. (pass-if "x" (array-fill! a #\x) #t)))
  188. (with-test-prefix "byte"
  189. (let ((a (make-s8vector 1 0)))
  190. (pass-if "0" (array-fill! a 0) #t)
  191. (pass-if "127" (array-fill! a 127) #t)
  192. (pass-if "-128" (array-fill! a -128) #t)
  193. (pass-if-exception "128" exception:out-of-range
  194. (array-fill! a 128))
  195. (pass-if-exception "-129" exception:out-of-range
  196. (array-fill! a -129))
  197. (pass-if-exception "symbol" exception:wrong-type-arg
  198. (array-fill! a 'symbol))))
  199. (with-test-prefix "short"
  200. (let ((a (make-s16vector 1 0)))
  201. (pass-if "0" (array-fill! a 0) #t)
  202. (pass-if "123" (array-fill! a 123) #t)
  203. (pass-if "-123" (array-fill! a -123) #t)))
  204. (with-test-prefix "ulong"
  205. (let ((a (make-u32vector 1 1)))
  206. (pass-if "0" (array-fill! a 0) #t)
  207. (pass-if "123" (array-fill! a 123) #t)
  208. (pass-if-exception "-123" exception:out-of-range
  209. (array-fill! a -123) #t)))
  210. (with-test-prefix "long"
  211. (let ((a (make-s32vector 1 -1)))
  212. (pass-if "0" (array-fill! a 0) #t)
  213. (pass-if "123" (array-fill! a 123) #t)
  214. (pass-if "-123" (array-fill! a -123) #t)))
  215. (with-test-prefix "float"
  216. (let ((a (make-f32vector 1 1.0)))
  217. (pass-if "0.0" (array-fill! a 0) #t)
  218. (pass-if "123.0" (array-fill! a 123.0) #t)
  219. (pass-if "-123.0" (array-fill! a -123.0) #t)
  220. (pass-if "0" (array-fill! a 0) #t)
  221. (pass-if "123" (array-fill! a 123) #t)
  222. (pass-if "-123" (array-fill! a -123) #t)
  223. (pass-if "5/8" (array-fill! a 5/8) #t)))
  224. (with-test-prefix "double"
  225. (let ((a (make-f64vector 1 1/3)))
  226. (pass-if "0.0" (array-fill! a 0) #t)
  227. (pass-if "123.0" (array-fill! a 123.0) #t)
  228. (pass-if "-123.0" (array-fill! a -123.0) #t)
  229. (pass-if "0" (array-fill! a 0) #t)
  230. (pass-if "123" (array-fill! a 123) #t)
  231. (pass-if "-123" (array-fill! a -123) #t)
  232. (pass-if "5/8" (array-fill! a 5/8) #t))))
  233. ;;;
  234. ;;; array-in-bounds?
  235. ;;;
  236. (with-test-prefix "array-in-bounds?"
  237. (pass-if (let ((a (make-array #f '(425 425))))
  238. (eq? #f (array-in-bounds? a 0)))))
  239. ;;;
  240. ;;; array-prototype
  241. ;;;
  242. (with-test-prefix "array-type"
  243. (with-test-prefix "on make-foo-vector"
  244. (pass-if "bool"
  245. (eq? 'b (array-type (make-bitvector 1))))
  246. (pass-if "char"
  247. (eq? 'a (array-type (make-string 1))))
  248. (pass-if "byte"
  249. (eq? 'u8 (array-type (make-u8vector 1))))
  250. (pass-if "short"
  251. (eq? 's16 (array-type (make-s16vector 1))))
  252. (pass-if "ulong"
  253. (eq? 'u32 (array-type (make-u32vector 1))))
  254. (pass-if "long"
  255. (eq? 's32 (array-type (make-s32vector 1))))
  256. (pass-if "long long"
  257. (eq? 's64 (array-type (make-s64vector 1))))
  258. (pass-if "float"
  259. (eq? 'f32 (array-type (make-f32vector 1))))
  260. (pass-if "double"
  261. (eq? 'f64 (array-type (make-f64vector 1))))
  262. (pass-if "complex"
  263. (eq? 'c64 (array-type (make-c64vector 1))))
  264. (pass-if "scm"
  265. (eq? #t (array-type (make-vector 1)))))
  266. (with-test-prefix "on make-typed-array"
  267. (let ((types '(b a u8 s8 u16 s16 u32 s32 u64 u64 f32 f64 c32 c64)))
  268. (for-each (lambda (type)
  269. (pass-if (symbol->string type)
  270. (eq? type
  271. (array-type (make-typed-array type
  272. *unspecified*
  273. '(5 6))))))
  274. types))))
  275. ;;;
  276. ;;; array-set!
  277. ;;;
  278. (with-test-prefix "array-set!"
  279. (with-test-prefix "bitvector"
  280. ;; in Guile 1.8.0 a bug in bitvector_set() caused a segv in array-set!
  281. ;; on a bitvector like the following
  282. (let ((a (make-bitvector 1)))
  283. (pass-if "one elem set #t"
  284. (begin
  285. (array-set! a #t 0)
  286. (eq? #t (array-ref a 0))))
  287. (pass-if "one elem set #f"
  288. (begin
  289. (array-set! a #f 0)
  290. (eq? #f (array-ref a 0))))))
  291. (with-test-prefix "byte"
  292. (let ((a (make-s8vector 1)))
  293. (pass-if "-128"
  294. (begin (array-set! a -128 0) #t))
  295. (pass-if "0"
  296. (begin (array-set! a 0 0) #t))
  297. (pass-if "127"
  298. (begin (array-set! a 127 0) #t))
  299. (pass-if-exception "-129" exception:out-of-range
  300. (begin (array-set! a -129 0) #t))
  301. (pass-if-exception "128" exception:out-of-range
  302. (begin (array-set! a 128 0) #t))))
  303. (with-test-prefix "short"
  304. (let ((a (make-s16vector 1)))
  305. ;; true if n can be array-set! into a
  306. (define (fits? n)
  307. (false-if-exception (begin (array-set! a n 0) #t)))
  308. (with-test-prefix "store/fetch"
  309. ;; Check array-ref gives back what was put with array-set!.
  310. ;; In Guile 1.6.4 and earlier, array-set! only demanded an inum and
  311. ;; would silently truncate to a short.
  312. (do ((n 1 (1+ (* 2 n)))) ;; n=2^k-1
  313. ((not (fits? n)))
  314. (array-set! a n 0)
  315. (pass-if n
  316. (= n (array-ref a 0))))
  317. (do ((n -1 (* 2 n))) ;; -n=2^k
  318. ((not (fits? n)))
  319. (array-set! a n 0)
  320. (pass-if n
  321. (= n (array-ref a 0))))))))
  322. ;;;
  323. ;;; array-set!
  324. ;;;
  325. (with-test-prefix "array-set!"
  326. (with-test-prefix "one dim"
  327. (let ((a (make-array #f '(3 5))))
  328. (pass-if "start"
  329. (array-set! a 'y 3)
  330. #t)
  331. (pass-if "end"
  332. (array-set! a 'y 5)
  333. #t)
  334. (pass-if-exception "start-1" exception:out-of-range
  335. (array-set! a 'y 2))
  336. (pass-if-exception "end+1" exception:out-of-range
  337. (array-set! a 'y 6))
  338. (pass-if-exception "two indexes" exception:out-of-range
  339. (array-set! a 'y 6 7))))
  340. (with-test-prefix "two dim"
  341. (let ((a (make-array #f '(3 5) '(7 9))))
  342. (pass-if "start"
  343. (array-set! a 'y 3 7)
  344. #t)
  345. (pass-if "end"
  346. (array-set! a 'y 5 9)
  347. #t)
  348. (pass-if-exception "start i-1" exception:out-of-range
  349. (array-set! a 'y 2 7))
  350. (pass-if-exception "end i+1" exception:out-of-range
  351. (array-set! a 'y 6 9))
  352. (pass-if-exception "one index" exception:wrong-num-indices
  353. (array-set! a 'y 4))
  354. (pass-if-exception "three indexes" exception:wrong-num-indices
  355. (array-set! a 'y 4 8 0)))))
  356. ;;;
  357. ;;; make-shared-array
  358. ;;;
  359. (define exception:mapping-out-of-range
  360. (cons 'misc-error "^mapping out of range")) ;; per scm_make_shared_array
  361. (with-test-prefix "make-shared-array"
  362. ;; this failed in guile 1.8.0
  363. (pass-if "vector unchanged"
  364. (let* ((a (make-array #f '(0 7)))
  365. (s (make-shared-array a list '(0 7))))
  366. (array-equal? a s)))
  367. (pass-if-exception "vector, high too big" exception:mapping-out-of-range
  368. (let* ((a (make-array #f '(0 7))))
  369. (make-shared-array a list '(0 8))))
  370. (pass-if-exception "vector, low too big" exception:out-of-range
  371. (let* ((a (make-array #f '(0 7))))
  372. (make-shared-array a list '(-1 7))))
  373. (pass-if "truncate columns"
  374. (array-equal? (make-shared-array #2((a b c) (d e f) (g h i)) list 3 2)
  375. #2((a b) (d e) (g h))))
  376. (pass-if "pick one column"
  377. (array-equal? (make-shared-array #2((a b c) (d e f) (g h i))
  378. (lambda (i) (list i 2))
  379. '(0 2))
  380. #(c f i)))
  381. (pass-if "diagonal"
  382. (array-equal? (make-shared-array #2((a b c) (d e f) (g h i))
  383. (lambda (i) (list i i))
  384. '(0 2))
  385. #(a e i)))
  386. ;; this failed in guile 1.8.0
  387. (pass-if "2 dims from 1 dim"
  388. (array-equal? (make-shared-array #1(a b c d e f g h i j k l)
  389. (lambda (i j) (list (+ (* i 3) j)))
  390. 4 3)
  391. #2((a b c) (d e f) (g h i) (j k l))))
  392. (pass-if "reverse columns"
  393. (array-equal? (make-shared-array #2((a b c) (d e f) (g h i))
  394. (lambda (i j) (list i (- 2 j)))
  395. 3 3)
  396. #2((c b a) (f e d) (i h g))))
  397. (pass-if "fixed offset, 0 based becomes 1 based"
  398. (let* ((x #2((a b c) (d e f) (g h i)))
  399. (y (make-shared-array x
  400. (lambda (i j) (list (1- i) (1- j)))
  401. '(1 3) '(1 3))))
  402. (and (eq? (array-ref x 0 0) 'a)
  403. (eq? (array-ref y 1 1) 'a))))
  404. ;; this failed in guile 1.8.0
  405. (pass-if "stride every third element"
  406. (array-equal? (make-shared-array #1(a b c d e f g h i j k l)
  407. (lambda (i) (list (* i 3)))
  408. 4)
  409. #1(a d g j)))
  410. (pass-if "shared of shared"
  411. (let* ((a #2((1 2 3) (4 5 6) (7 8 9)))
  412. (s1 (make-shared-array a (lambda (i) (list i 1)) 3))
  413. (s2 (make-shared-array s1 list '(1 2))))
  414. (and (eqv? 5 (array-ref s2 1))
  415. (eqv? 8 (array-ref s2 2))))))
  416. ;;;
  417. ;;; uniform-vector-ref
  418. ;;;
  419. (with-test-prefix "uniform-vector-ref"
  420. (with-test-prefix "byte"
  421. (let ((a (make-s8vector 1)))
  422. (pass-if "0"
  423. (begin
  424. (array-set! a 0 0)
  425. (= 0 (uniform-vector-ref a 0))))
  426. (pass-if "127"
  427. (begin
  428. (array-set! a 127 0)
  429. (= 127 (uniform-vector-ref a 0))))
  430. (pass-if "-128"
  431. (begin
  432. (array-set! a -128 0)
  433. (= -128 (uniform-vector-ref a 0)))))))
  434. ;;;
  435. ;;; syntax
  436. ;;;
  437. (with-test-prefix "syntax"
  438. (pass-if "rank and lower bounds"
  439. ;; uniform u32 array of rank 2 with index ranges 2..3 and 7..8.
  440. (let ((a '#2u32@2@7((1 2) (3 4))))
  441. (and (array? a)
  442. (typed-array? a 'u32)
  443. (= (array-rank a) 2)
  444. (let loop ((bounds '((2 7) (2 8) (3 7) (3 8)))
  445. (result #t))
  446. (if (null? bounds)
  447. result
  448. (and result
  449. (loop (cdr bounds)
  450. (apply array-in-bounds? a (car bounds)))))))))
  451. (pass-if "negative lower bound"
  452. (let ((a '#1@-3(a b)))
  453. (and (array? a)
  454. (= (array-rank a) 1)
  455. (array-in-bounds? a -3) (array-in-bounds? a -2)
  456. (eq? 'a (array-ref a -3))
  457. (eq? 'b (array-ref a -2)))))
  458. (pass-if-exception "negative length" exception:length-non-negative
  459. (with-input-from-string "'#1:-3(#t #t)" read)))
  460. ;;;
  461. ;;; equal? with vector and one-dimensional array
  462. ;;;
  463. (pass-if "vector equal? one-dimensional array"
  464. (equal? (make-shared-array #2((a b c) (d e f) (g h i))
  465. (lambda (i) (list i i))
  466. '(0 2))
  467. #(a e i)))