From 5145dd3aa0c02c9fc496d1432fc4410674206e1d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:05:31 -0800 Subject: Import Upstream version 3a2 --- determ.scm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'determ.scm') 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))) -- cgit v1.2.3