diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:31 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:31 -0800 |
commit | 5145dd3aa0c02c9fc496d1432fc4410674206e1d (patch) | |
tree | 540afc30c51da085f5bd8ec3f4c89f6496e7900d /determ.scm | |
parent | 8466d8cfa486fb30d1755c4261b781135083787b (diff) | |
download | slib-5145dd3aa0c02c9fc496d1432fc4410674206e1d.tar.gz slib-5145dd3aa0c02c9fc496d1432fc4410674206e1d.zip |
Import Upstream version 3a2upstream/3a2
Diffstat (limited to 'determ.scm')
-rw-r--r-- | determ.scm | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -1,5 +1,5 @@ ;;; "determ.scm" Matrix Algebra -;Copyright 2002 Aubrey Jaffer +;Copyright 2002, 2004 Aubrey Jaffer ; ;Permission to copy this software, to modify it, to redistribute it, ;to distribute modified versions, and to use it for any purpose is @@ -24,30 +24,30 @@ ;;@noindent ;;A Matrix can be either a list of lists (rows) or an array. -;;As with linear-algebra texts, this package uses 1-based coordinates. +;;Unlike linear-algebra texts, this package uses 0-based coordinates. ;;; Internal conversion routines (define (matrix2array matrix prototype) - (let* ((shp (list (list 1 (length matrix)) - (list 1 (length (car matrix))))) - (mat (apply create-array '#() shp))) - (do ((idx 1 (+ 1 idx)) + (let* ((dim1 (length matrix)) + (dim2 (length (car matrix))) + (mat (make-array '#() dim1 dim2))) + (do ((idx 0 (+ 1 idx)) (rows matrix (cdr rows))) - ((> idx (cadar shp)) rows) - (do ((jdx 1 (+ 1 jdx)) + ((>= idx dim1) rows) + (do ((jdx 0 (+ 1 jdx)) (row (car rows) (cdr row))) - ((> jdx (cadadr shp))) + ((>= jdx dim2)) (array-set! mat (car row) idx jdx))) - mat)) + mat)) (define (matrix2lists matrix) - (let ((shp (array-shape matrix))) - (do ((idx (cadar shp) (+ -1 idx)) - (rows '() - (cons (do ((jdx (cadadr shp) (+ -1 jdx)) + (let ((dims (array-dimensions matrix))) + (do ((idx (+ -1 (car dims)) (+ -1 idx)) + (rows '() + (cons (do ((jdx (+ -1 (cadr dims)) (+ -1 jdx)) (row '() (cons (array-ref matrix idx jdx) row))) - ((< jdx (caadr shp)) row)) + ((< jdx 0) row)) rows))) - ((< idx (caar shp)) rows)))) + ((< idx 0) rows)))) (define (coerce-like-arg matrix arg) (cond ((array? arg) (matrix2array matrix arg)) (else matrix))) |