From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: matrix library? Date: Wed, 4 Oct 2023 22:29:26 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32418"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Nala Ginrut , guile-user To: tomas@tuxteam.de Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Oct 04 22:30:15 2023 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qo8Vb-0008G8-Gf for guile-user@m.gmane-mx.org; Wed, 04 Oct 2023 22:30:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo8V5-00069L-Ag; Wed, 04 Oct 2023 16:29:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo8V3-00068I-RU for guile-user@gnu.org; Wed, 04 Oct 2023 16:29:41 -0400 Original-Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qo8V2-0000k9-1X for guile-user@gnu.org; Wed, 04 Oct 2023 16:29:41 -0400 Original-Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5346b64f17aso308383a12.2 for ; Wed, 04 Oct 2023 13:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696451378; x=1697056178; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kzPS8vTYuQmG9zc8BR4yBqja4mBSvNhsG8Ke7PerPTo=; b=JX6gf1IaK+R3/qtCQ7Kj4spP1mOJef7IK6KucRXsCUv13YoRKqwvZXkIpIewTf88mO WRtnFloxoxMccK106pjGzAyN9NjWKh6463U5K8Qq2t6J8KazNpxla3h8qT/DbLrMM9G8 o7Ar+6FhZC7f+nOuNOTL7KoCv/FFuiRENR3TAifQmof7npAFTpsuWiVOy0fXIvYYtTY6 jGkycZVE2is0JRvrMGZGX5EvfeY8royUgDCqtKEJvvgGYENutohTlbUiOq+nJbpIiJvA o9bWexEsHLmjp4GMNfg3Rru1RqxHDhhF0b08nXX7+EXsThBgffdWYICGfhl1rnrE8BDd XrUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696451378; x=1697056178; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kzPS8vTYuQmG9zc8BR4yBqja4mBSvNhsG8Ke7PerPTo=; b=YCfJCDMJtaqlcsdDaCWQMcLQgtPCbDMYGiUasnXgCNsX+I0AizC7LPB0HXQTevdK6g JIjQkYIcS5EKCkWtRZ5jdC+3JIjFjOhD2WazDLs7VhdRy6k2YoQIsBxgJN5TvLbZ7MgA 62GgjaskvpFdd+uWeWIPp4fPGRN+Rm3GblPub2/1oA8wABmd2QujcdNvK8I+wuL65KOG 3avnsnzv1/M1GxeM5UgNAmXV6f5qE0Dov7fqfgZVCmNPco7KehEpDsbLCRav5Dfry9ZH BO6Wz6DV4Q3vB6d46pd5TbmKgx1tZgHk/06kRRu3ay90moI949NU03GkiSBHkPhs5sbx QFxQ== X-Gm-Message-State: AOJu0Yzug03UeUwzhZOdr3cXN0v4YZouPV1BAqnWGZV0CSf9j23qwlYB YF/t5kR5/FaJShepueedV0eWGX+6OezcCAPG9FzEI/Mi X-Google-Smtp-Source: AGHT+IFowFwXfjGgMRZhJdoaGcAZwnEaFJQy0p1Or58lBg5GSW9MGf3GaTeF9KFqGGc9rn7r0GTgJBKWgRbpf/bPEiw= X-Received: by 2002:a17:906:1d:b0:9b2:9a0e:9972 with SMTP id 29-20020a170906001d00b009b29a0e9972mr2968228eja.13.1696451378143; Wed, 04 Oct 2023 13:29:38 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=damien.mattei@gmail.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19230 Archived-At: yes i will re-implement that from scratch because i can not find something easy in libraries to use. I already made it for Racket/Scheme+: (struct matrix-vect (v)) ;; matrix based on vector of vectors (define (create-matrix-vect-by-function fct lin col) (matrix-vect (create-vector-2d fct lin col))) ;; return the line and column values of dimension (define (dim-matrix-vect M) (when (not (matrix-vect? M)) (error "argument is not of type matrix")) {v <+ (matrix-vect-v M)} {lin <+ (vector-length v)} {col <+ (vector-length {v[0]})} (values lin col)) (define (multiply-matrix-matrix M1 M2) {(n1 p1) <+ (dim-matrix-vect M1)} {(n2 p2) <+ (dim-matrix-vect M2)} (when {p1 =E2=89=A0 n2} (error "matrix-by-vectors.* : matrix product impossible, incompatible dimensions")) {v1 <+ (matrix-vect-v M1)} {v2 <+ (matrix-vect-v M2)} (define (res i j) (for/sum ([k (in-range p1)]) {v1[i][k] * v2[k][j]})) {v <+ (create-vector-2d res n1 p2)} ;(display "v=3D") (display v) (newline) (matrix-vect v)) (define (vector->matrix-column v) (matrix-vect (vector-map (lambda (x) (make-vector 1 x)) v))) (define (matrix-column->vector Mc) {v <+ (matrix-vect-v Mc)} (vector-map (lambda (v2) {v2[0]}) v)) (define (multiply-matrix-vector M v) ;; args: matrix ,vector ; return vect= or {Mc <+ (vector->matrix-column v)} ;(display Mc) (matrix-column->vector (multiply-matrix-matrix M Mc))) there should be no difference for computation in Guile ,just that i will use GOOPS instead of struct and that it should be a guile module written in scheme+ syntax.... see it when finished.... On Wed, Oct 4, 2023 at 8:28=E2=80=AFPM wrote: > > 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=E2=80=AFPM Nala Ginrut 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 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.ht= ml#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))) > ((>=3D 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) > > =3D> (1.5 1.5 0) > > CAVEAT: only tested with this one example. Input value checking > left as an... > > Cheers > -- > t >