summaryrefslogtreecommitdiffstats
path: root/determ.scm
diff options
context:
space:
mode:
Diffstat (limited to 'determ.scm')
-rw-r--r--determ.scm32
1 files changed, 16 insertions, 16 deletions
diff --git a/determ.scm b/determ.scm
index 1078750..0962e4a 100644
--- a/determ.scm
+++ b/determ.scm
@@ -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)))