Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

174 lines (135 sloc) 4.736 kB
#lang scheme
(require "array.ss")
;;; Array Types
(printf "~n(arange 12)~n")
(describe-array (arange 12))
(printf "~n(arange 12 #:type u8)~n")
(describe-array (arange 12 #:type u8))
(printf "~n(arange 12 #:type s8)~n")
(describe-array (arange 12 #:type s8))
(printf "~n(arange 12 #:type s64)~n")
(describe-array (arange 12 #:type s64))
(printf "~n(arange 12 #:type f32)~n")
(describe-array (arange 12 #:type f32))
(printf "~n(arange 12 #:type f64)~n")
(describe-array (arange 12 #:type f64))
;;; Row major
(printf "~n(make-array '(3 4) #:fill 0)~n")
(describe-array (make-array '(3 4) #:fill 0))
(printf "~n(make-array '(3 4) #:type s32 #:fill 0)~n")
(describe-array (make-array '(3 4) #:type s32 #:fill 0))
(printf "~n(make-array '(3 4) #:type f32 #:fill 0)~n")
(describe-array (make-array '(3 4) #:type f32 #:fill 0))
(printf "~n(make-array '(3 4) #:type f64 #:fill 0)~n")
(describe-array (make-array '(3 4) #:type f64 #:fill 0))
;;; Column major
(printf "~n(make-array '(3 4) #:order 'column #:fill 0)~n")
(describe-array (make-array '(3 4) #:order 'column #:fill 0))
(printf "~n(make-array '(3 4) #:type s32 #:order 'column #:fill 0)~n")
(describe-array (make-array '(3 4) #:type s32 #:order 'column #:fill 0))
(printf "~n(make-array '(3 4) #:type f32 #:order 'column #:fill 0)~n")
(describe-array (make-array '(3 4) #:type f32 #:order 'column #:fill 0))
(printf "~n(make-array '(3 4) #:type f64 #:order 'column #:fill 0)~n")
(describe-array (make-array '(3 4) #:type f64 #:order 'column #:fill 0))
;;; Transpose
(printf "~n(transpose (reshape (arange 12) '(3 4)))~n")
(describe-array (transpose (reshape (arange 12) '(3 4))))
;;;
(printf "~n(define a (reshape (arange 12 #:type f32) '(3 4)))~n")
(define a (reshape (arange 12 #:type f32) '(3 4)))
(define a-t (transpose a))
(describe-array a)
(printf "a = ")
(print-array a)
(printf "(transpose a) = ")
(print-array a-t)
;;; Test build-array
(printf "~n(define b (build-array '(3 4) (lambda (i j) (* i j))))~n")
(define b (build-array '(3 4) (lambda (i j) (* i j))))
(describe-array b)
(printf "b = ")
(print-array b)
(printf "~n(define c (build-array '(3 4) (lambda (i j) (* i j)) #:order 'column))~n")
(define c (build-array '(3 4) (lambda (i j) (* i j)) #:order 'column))
(describe-array c)
(printf "c = ")
(print-array c)
(printf "~n(define d1 (build-array~n")
(printf " '(3 4)~n")
(printf " (lambda (i j) (make-rectangular (* i j) (+ i j)))~n")
(printf " #:type cf64))~n")
(define d1 (build-array
'(3 4)
(lambda (i j) (make-rectangular (* i j) (+ i j)))
#:type cf64))
;(describe-array d1)
(printf "d1 = ")
(print-array d1)
(define d1-real (real d1))
(printf "(real d1) = ")
(print-array d1-real)
(define d1-imag (imag d1))
(printf "(imag d1) = ")
(print-array d1-imag)
(printf "~n(define d2 (build-array~n")
(printf " '(3 4)~n")
(printf " (lambda (i j) (make-rectangular (* i j) (+ i j)))~n")
(printf " #:type cs16))~n")
(define d2 (build-array
'(3 4)
(lambda (i j) (make-rectangular (* i j) (+ i j)))
#:type cs16))
;(describe-array d2)
(printf "d2 = ")
(print-array d2)
(define d2-real (real d2))
(printf "(real d2) = ")
(print-array d2-real)
(define d2-imag (imag d2))
(printf "(imag d2) = ")
(print-array d2-imag)
;;; Test simple slices
(printf "~n(define e (array-ref* a '(* 3)))~n")
(define e (array-ref* a '(* 3)))
;(describe-array e)
(printf "e = ")
(print-array e)
(printf "~n(define f (array-ref* a '(1 *)))~n")
(define f (array-ref* a '(1 *)))
;(describe-array f)
(printf "f = ")
(print-array f)
(printf "~n(define g (array-ref* a '(1 (* * 2))))~n")
(define g (array-ref* a '(1 (* * 2))))
;(describe-array g)
(printf "g = ")
(print-array g)
(printf "~n(define h (array-ref* a '(1 (1 * 2))))~n")
(define h (array-ref* a '(1 (1 * 2))))
;(describe-array h)
(printf "h = ")
(print-array h)
(printf "~n(define i (array-ref* a '(* (* * 2))))~n")
(define i (array-ref* a '(* (* * 2))))
;(describe-array i)
(printf "i = ")
(print-array i)
(printf "~n(define j (reshape (arange 60) '(3 4 5)))~n")
(define j (reshape (arange 60) '(3 4 5)))
(printf "j = ")
(print-array j)
(printf "~n(define k (reshape (arange 360) '(3 4 5 6)))~n")
(define k (reshape (arange 360) '(3 4 5 6)))
(printf "k = ")
(print-array k)
;;; Test list->array
(printf "~n(define l (list->array '((1 2 3)(4 5 6)(7 8 9))))~n")
(define l (list->array '((1 2 3)(4 5 6)(7 8 9))))
(describe-array l)
(printf "l = ")
(print-array l)
(printf "~n(define m (list->array '((1 2 3)(4 5 6)(7 8 9)) #:order 'column))~n")
(define m (list->array '((1 2 3)(4 5 6)(7 8 9)) #:order 'column))
(describe-array m)
(printf "m = ")
(print-array m)
Jump to Line
Something went wrong with that request. Please try again.