From: tomas@tuxteam.de
To: Damien Mattei <damien.mattei@gmail.com>
Cc: Nala Ginrut <nalaginrut@gmail.com>, guile-user <guile-user@gnu.org>
Subject: Re: matrix library?
Date: Wed, 4 Oct 2023 20:28:58 +0200 [thread overview]
Message-ID: <ZR2u6nG/fjOvXRF+@tuxteam.de> (raw)
In-Reply-To: <CADEOadcaCi=KBZJJu4KqLACiS6+cP9Q3qORHEA5+96aOBYoTbA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1711 bytes --]
On Wed, Oct 04, 2023 at 05:42:10PM +0200, Damien Mattei wrote:
> thank you. i will try to find a simple example in.
>
> On Wed, Oct 4, 2023 at 1:36 PM Nala Ginrut <nalaginrut@gmail.com> wrote:
> >
> > And I'd mention AIScm which bound tensorflow APIs. It needs more love.
> >
> > https://wedesoft.github.io/aiscm/
> >
> >
> > On Wed, Oct 4, 2023, 17:12 <tomas@tuxteam.de> wrote:
> >>
> >> On Wed, Oct 04, 2023 at 08:46:02AM +0200, Damien Mattei wrote:
> >> > hello,
> >> > does anyone know if it exists a basic matrix library for Guile?
> >> > just need to multiply a matrix and a vector.
> >>
> >> Perhaps this thread from guile-user [1] has something for you
> >>
> >> Cheers
> >>
> >> [1] https://lists.gnu.org/archive/html/guile-user/2018-12/threads.html#00117
That all said, if your case doesn't get much hairier,
it is fairly easy to navigate with Guile's arrays:
(define (dot v1 v2)
"The dot product of v1 and v2"
(let ((sum 0))
(array-for-each
(lambda (x1 x2)
(set! sum (+ sum (* x1 x2))))
v1 v2)
sum))
(define (row m i)
"The i-th row of m, as a vector"
(make-shared-array m (lambda (j) (list i j)) (car (array-dimensions m))))
(define (mat* m v)
"Left multiply matrix m and vector v"
(let* ((height (cadr (array-dimensions m)))
(res (make-typed-array 'f64 0 height)))
(do ((i 0 (1+ i)))
((>= i height))
(array-set! res (dot (row m i) v) i))
res))
(define vec #1f64(1 2 1))
(define mat #2f64((0.5 0.5 0) (0 0.5 0.5) (-0.5 0 0.5)))
(mat* mat vec)
=> (1.5 1.5 0)
CAVEAT: only tested with this one example. Input value checking
left as an...
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2023-10-04 18:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 6:46 matrix library? Damien Mattei
2023-10-04 9:10 ` tomas
2023-10-04 11:36 ` Nala Ginrut
2023-10-04 15:42 ` Damien Mattei
2023-10-04 18:28 ` tomas [this message]
2023-10-04 20:29 ` Damien Mattei
2023-10-05 14:47 ` Damien Mattei
2023-10-06 17:23 ` Damien Mattei
2023-10-06 17:49 ` tomas
2023-10-06 18:33 ` Damien Mattei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZR2u6nG/fjOvXRF+@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=damien.mattei@gmail.com \
--cc=guile-user@gnu.org \
--cc=nalaginrut@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).