Created
July 28, 2012 06:10
-
-
Save yamasushi/3192045 to your computer and use it in GitHub Desktop.
Slices of unifom vector(ユニフォームベクタのスライス)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use gauche.uvector) | |
(define (uvector-slices u k) | |
(let [(uvclass (class-of u)) | |
(l (uvector-length u))] | |
(receive (n r) (quotient&remainder l k) | |
(let1 s (* n k) | |
(let loop [(i s) | |
(d (if (= r 0) | |
'() | |
(list (uvector-alias uvclass u s (+ s r) ) ) ) ) ] | |
(cond | |
( (= i 0) d) | |
( (> i 0) | |
(let1 s (- i k) | |
(loop s (cons (uvector-alias uvclass u s (+ s k)) d)) ) ) | |
( (< i 0) | |
(error "i < 0") ) ) ) ) ) ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment