[CM] matrix display
James Hearon
j_hearon at hotmail.com
Thu May 1 10:47:18 PDT 2025
Hi,
I see the r6r5 info on use of 'library' now.
https://www.gnu.org/software/guile/manual/html_node/R6RS-Libraries.html
For those tspl4/examples the display output is a bit odd and generally single line.
My primitive try at matrix formatting is too brute force, but the output is more of what I was looking for. If nothing exists already in snd I may have missed, maybe I can come up with some combination of the tspl4/examples and improvements on my nested do loops approach for matrix display.
(with-let (sublet *libgsl*)
(let* ( (n 4) ;num rows
(p 4) ;num cols
(m (gsl_matrix_alloc n p))
(myrow (gsl_vector_alloc n)) ;alloc gsl vectors
(mycol (gsl_vector_alloc p))
(my_i (gsl_vector_alloc n))
(my_j (gsl_vector_alloc 16)) ;4x4
(r 0.0) ;row indicator
(c 0.0) ;col indicator
)
(format #t "\n\nGSL MATRIX: \n" )
;nested do to load matrix
(do ((i 0 (+ i 1)))
((= i n))
(do ((j 0 (+ j 1)))
((= j 4))
(gsl_matrix_set m i j 1.12) ;sets i j values all to 1.12
))
;2nd nested do to put matrix i j values into separate gsl_vectors
(do ((i 0 (+ i 1)))
((= i n))
(do ((j 0 (+ j 1)))
((= j 4))
(gsl_vector_set my_i i (gsl_matrix_get m i j))
(gsl_vector_set my_j j (gsl_matrix_get m i j))
))
;3rd nested do to print gsl_vector values
(do ((i 0 (+ i 1)))
((= i n))
(let ((r (gsl_vector_get my_i i)) ;print i for row num or r for row value
)
(format #t "r: ~A " i)
)
(do ((j 0 (+ j 1))) ;j is col
((= j 4))
(let ((c (gsl_vector_get my_j j))
)
(format #t " c~A: ~A"j c)
)
)
(format #t "\n")
)
(gsl_matrix_free m)
(gsl_vector_free myrow)
(gsl_vector_free mycol)
(gsl_vector_free my_i)
(gsl_vector_free my_j)
))
________________________________
From: cmdist-bounces at ccrma.Stanford.EDU <cmdist-bounces at ccrma.Stanford.EDU> on behalf of cmdist-request at ccrma.Stanford.EDU <cmdist-request at ccrma.Stanford.EDU>
Sent: Wednesday, April 30, 2025 9:00 AM
To: cmdist at ccrma.Stanford.EDU <cmdist at ccrma.Stanford.EDU>
Subject: Cmdist Digest, Vol 203, Issue 3
Send Cmdist mailing list submissions to
cmdist at ccrma.stanford.edu
To subscribe or unsubscribe via the World Wide Web, visit
https://cm-mail.stanford.edu/mailman/listinfo/cmdist
or, via email, send a message with subject or body 'help' to
cmdist-request at ccrma.stanford.edu
You can reach the person managing the list at
cmdist-owner at ccrma.stanford.edu
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Cmdist digest..."
Today's Topics:
1. matrix display (James Hearon)
----------------------------------------------------------------------
Message: 1
Date: Wed, 30 Apr 2025 17:53:37 +0000
From: James Hearon <j_hearon at hotmail.com>
To: "cmdist at ccrma.Stanford.EDU" <cmdist at ccrma.Stanford.EDU>
Subject: [CM] matrix display
Message-ID:
<SA1PR14MB5981064825E0FDAA36F469D7E5832 at SA1PR14MB5981.namprd14.prod.outlook.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I'm working thru libgsl.scm defs and trying to come up with good way to display a
gsl_matrix. I found some code in s7test.scm (dofit...etc.), but couldn't follow it exactly. Then I tried my own version using gsl_vectors and nested do loops, but still not happy with it.
Then came across another approach https://www.scheme.com/tspl4/examples.html<https://www.scheme.com/tspl4/examples.html>
under Section 12.1. Matrix and Vector Multiplication, which uses a keyword 'library' along with export and import to utilize a group of different defines related to matrix activities.
(library (tspl matrix)
(export make-matrix matrix? matrix-rows matrix-columns
matrix-ref matrix-set! mul)
(import (rnrs)) ...
Seems the 'library' keyword is unbound in snd. Just curious if there was some alternative in snd I missed to be able to cobble together a group of definitions into some sort of useable structure? (His individual matrix definitions work fine in snd if you forgo the 'library' part and substitute parentheses for brackets in the definitions). Or maybe there's a better way to format or display rows and cols in snd I also missed.
Regards,
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20250430/2ba43b26/attachment-0001.html>
------------------------------
_______________________________________________
Cmdist mailing list
Cmdist at ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist
End of Cmdist Digest, Vol 203, Issue 3
**************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20250501/d23b5ec2/attachment-0001.html>
More information about the Cmdist
mailing list