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.devel Subject: Re: [PATCH] Extensions for SRFI-171 (Transducers) Date: Sat, 24 Dec 2022 14:25:28 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000009de9ca05f092d695" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19825"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Dec 24 14:26:12 2022 Return-path: Envelope-to: guile-devel@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 1p94XT-0004yF-MT for guile-devel@m.gmane-mx.org; Sat, 24 Dec 2022 14:26:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p94X6-0004eE-Nu; Sat, 24 Dec 2022 08:25:49 -0500 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 1p94X3-0004e4-A8 for guile-devel@gnu.org; Sat, 24 Dec 2022 08:25:45 -0500 Original-Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p94X0-00060U-Ut for guile-devel@gnu.org; Sat, 24 Dec 2022 08:25:45 -0500 Original-Received: by mail-ej1-x631.google.com with SMTP id gh17so17666942ejb.6 for ; Sat, 24 Dec 2022 05:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=4wfTwuvqPq12eRM0DLAAWbp4VWmUfPSTONarDLv4uKI=; b=akMHBqAzNFw278Y0AsuYbc8KhgI/Sv8IrWMC5ZrbjfG5/V6sx9paYS2lLVechuXfUw ZvOgKXq8v/j2nago11UMk90PGC1XL2EkOup/IXYQG0cDC8tbNNOAQ3MjpZUPx/WPqQSU pbz5bz6dkhjl7eDygB23OVkgfGaVNnvKgdFGJi83b5O8/5eQ9dtIuCxIfWxB4oICixZ9 KholMp5YAXv31snl0fpsxekIvDY/khbU6c6zUVm3vveqDPzcZxYRdeR0ON1fJENbzNHZ /uLjhmcE7YqXk3/3OOOOuvw+j40Y/8KfXKcha1fe/pTf7XOxVvYB0zB+l+HXr3KGnEMQ GF1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=4wfTwuvqPq12eRM0DLAAWbp4VWmUfPSTONarDLv4uKI=; b=oFmrzI+xQ50sEzMU5X+ztV1nECtiukSp7k9HepbcYCVympX4lZs2u1ZdMgwzha/oj6 gE8/iSYVXWD79CqSgO7OSbyDcZ+1csg9KtpxVEOOHXgLJuCp/NeyrssTkS1TMyZbFL5K FMuXaUa3iM/JrCqhI1RsuVkIk/JHrWg4lAHJhXXrnoWYZ3rp090uQa8ZtlJ0mALd9twr G31Komn93ZiOm04wwnnIvPH52bXY9zu5x1FrAM4Ga3sggy7ZNvsgqBj4XXFddcP1D49i 1HidyeHum8Evlee0ah1JoP/vLBK2ZIc+4+5nZ88rxMYDvUyhnrHassyE91zk2yZiWgi7 ep3w== X-Gm-Message-State: AFqh2kq4M+6kcfZN/QSsN8QIwZkZlvzszBnGE35mEnUq9viNW6+zY+1l 5TU0dQEwVDQs0+P8foy01H0eIxYNFJAv4GrNoW8QKzWG6IUWDg== X-Google-Smtp-Source: AMrXdXsD66Cvcc80OAArS5f1vmCBs6pMZs4tNGpVvWTIuDAD0uvlf84B2N25Qf49Kj6kX/DADBtCdDsz03kT1HaNlQ8= X-Received: by 2002:a17:906:f857:b0:835:57c9:6424 with SMTP id ks23-20020a170906f85700b0083557c96424mr1617680ejb.529.1671888340116; Sat, 24 Dec 2022 05:25:40 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x631.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, HTML_MESSAGE=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-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21525 Archived-At: --0000000000009de9ca05f092d695 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable that is strange but with more ,the same ,tests i have no more speed up: with Racket versions of srfi 171 {unified-minterms-set-2 <+ (filter (=CE=BB (x) x) unified-minterms-set-1)} = ;; remove #f results ;; (nodebug ;; {unified-minterms-set-2-length <+ (length unified-minterms-set-2)} ;; (dv unified-minterms-set-2-length)) {unified-minterms-set <+ (remove-duplicates unified-minterms-set-2)} ;; (remove-duplicates-sorted unified-minterms-set-2)} ;; uniq MODIF ;; C12 in Terminal mode with MacOS Ventura M1 and 32" ;; (nodebug ;; {unified-minterms-set-uniq-length <+ (length unified-minterms-set)} ;; (dv unified-minterms-set-uniq-length)) ;;{unified-minterms-set <+ (remove-duplicates (filter (=CE=BB (x) x) unified-minterms-set-1))} ;; C12 in Terminal mode with MacOS Ventura M1 and 32" ;;{unified-minterms-set <+ (list-transduce (compose (tfilter (=CE=BB (x) = x)) (tdelete-duplicates)) rcons unified-minterms-set-1)} ;; C12 in Terminal mode with MacOS Ventura M1 and 31" and Guile: ;; 8'04" MacOS Ventura M1 for C12 ,50" for C11 ;;{unified-minterms-set-2 <+ (filter (=CE=BB (x) x) unified-minterms-set-= 1)} ;; remove #f results ;; (nodebug ;; {unified-minterms-set-2-length <+ (length unified-minterms-set-2)} ;; (dv unified-minterms-set-2-length)) ;;{unified-minterms-set <+ (remove-duplicates unified-minterms-set-2)} ;;(remove-duplicates-sorted unified-minterms-set-2)} ;; uniq MODIF ;; (nodebug ;; {unified-minterms-set-uniq-length <+ (length unified-minterms-set)} ;; (dv unified-minterms-set-uniq-length)) {unified-minterms-set <+ (remove-duplicates (filter (=CE=BB (x) x) unified-minterms-set-1))} ;; 59" for C11, 8'05" for C12 ;; 7'08" ,8'15" MacOS Ventura M1 for C12 and 56" for C11 ;;{unified-minterms-set <+ (list-transduce (compose (tfilter (=CE=BB (x) = x)) (tdelete-duplicates)) rcons unified-minterms-set-1)} some code is commented because i only run one test at a time. I suppose the speed up was only because debug mode slowed down other code but perheaps my test are not reliable, i can only explain some slow down now due to CPU overloaded by another process in the system at different moment in tests. I have no idea how to perform more reliable tests. On Thu, Dec 22, 2022 at 6:32 PM Damien Mattei wrote: > i'm interested with transducers to speed up code: > > ;; 8'21" MacOS Ventura M1 > {unified-minterms-set-2 <+ (filter (=CE=BB (x) x) unified-minterms-set-= 1)} ;; > remove #f results > (nodebug > {unified-minterms-set-2-length <+ (length unified-minterms-set-2)} > (dv unified-minterms-set-2-length)) > > {unified-minterms-set <+ (remove-duplicates unified-minterms-set-2)} > ;;(remove-duplicates-sorted unified-minterms-set-2)} ;; uniq MODIF > (nodebug > {unified-minterms-set-uniq-length <+ (length unified-minterms-set)} > (dv unified-minterms-set-uniq-length)) > > with transducers: > ;; 7'08" MacOS Ventura M1 > {unified-minterms-set <+ (list-transduce (compose (tfilter (=CE=BB (x) = x)) > (tdelete-duplicates)) rcons unified-minterms-set-1)} > > it is an interesting 15% speed up in my code. > > > On Thu, Dec 22, 2022 at 3:52 PM Damien Mattei > wrote: > >> i just understood the scheme :-) >> >> scheme@(guile-user)> (list-transduce (compose (tfilter (=CE=BB (x) x)) >> (tdelete-duplicates)) rcons (list 1 2 #f 3 3 4)) >> $12 =3D (1 2 3 4) >> >> sorry... >> >> >> On Thu, Dec 22, 2022 at 3:33 PM Damien Mattei >> wrote: >> >>> hello, >>> just trying transducers before using it, i try to understand. >>> what is wrong with that: >>> scheme@(guile-user)> (list-transduce (tfilter (=CE=BB (x) x)) >>> (tdelete-duplicates) (list 1 2 #f 3 3 4)) >>> ice-9/boot-9.scm:1685:16: In procedure raise-exception: >>> Wrong number of arguments to #>> srfi/srfi-171.scm:338:2 (reducer)> >>> >>> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. >>> >>> Regards, >>> Damien >>> >>> On Wed, Dec 21, 2022 at 11:01 AM Linus Bj=C3=B6rnstam < >>> linus.bjornstam@veryfast.biz> wrote: >>> >>>> As the author of both the SRFI and the guile code I am very happy you >>>> like it. I don't have a computer at the moment, but I looked through t= he >>>> code and it looked great. >>>> >>>> All additions should have been included in the original SRFI :) >>>> >>>> one comment: your code uses define-public, which the rest of SRFI-171 >>>> code does not. >>>> >>>> I am not in any position to sign code off for inclusion in guile >>>> proper, but if the define-public thing is fixed it very much has my >>>> blessing. >>>> >>>> Best regards >>>> Linus Bj=C3=B6rnstam >>>> >>>> On Wed, 21 Dec 2022, at 01:48, Colin Woodbury wrote: >>>> > Happy holidays everyone, I hope everything is going well for you. >>>> > >>>> > Since discovering SRFI-171 (Transducers) I have fallen in love with >>>> it. >>>> > Transducers let me "talk the way I want to talk" while knowing that >>>> I'm >>>> > being efficient underneath w.r.t. to iteration and allocation. In >>>> using >>>> > Guile's implementation, I noticed a few common idioms missing that >>>> are >>>> > otherwise present in other languages, so I've added them in a series >>>> of >>>> > patches. I've been using these often for a number of weeks without >>>> > issue, but of course have added unit tests as well. >>>> > >>>> > The full details are in the commit messages, but here are the main >>>> highlights: >>>> > >>>> > * rfold: The fundamental reducer. This allows the user to turn any >>>> > two-arg function into a valid reducer, so that they don't need to >>>> worry >>>> > about hand-writing reducers via case-lambda. >>>> > * rfind: Yields the first item in the transduction that matches som= e >>>> > predicate. Nice for locating some specific value from a potentially >>>> > large data source (e.g. a port). >>>> > * twindow: Like tsegment, but yields overlapping slices into the >>>> data. >>>> > Cheers, and have a great holiday. >>>> > >>>> > Colin >>>> > >>>> > Attachments: >>>> > * 0001-srfi-171-add-twindow-and-various-reducers.patch >>>> > * 0002-doc-add-new-SRFI-171-reducers-to-the-manual.patch >>>> > * 0003-srfi-171-add-unit-tests-for-new-functions.patch >>>> >>>> --0000000000009de9ca05f092d695 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
tha= t is strange but with more ,the same ,tests i have no more speed up:
<= div class=3D"gmail_default" style=3D"font-size:large">
with Racket versions of srfi 1= 71

{unified-minterms-= set-2 <+ (filter (=CE=BB (x) x) unified-minterms-set-1)} ;; remove #f re= sults
=C2=A0 ;; (nodebug
=C2=A0 ;; =C2=A0{unified-minterms-set-2-leng= th <+ (length unified-minterms-set-2)}
=C2=A0 ;; =C2=A0(dv unified-mi= nterms-set-2-length))

=C2=A0 {unified-minterms-set <+ (remove-dup= licates unified-minterms-set-2)} ;; (remove-duplicates-sorted unified-minte= rms-set-2)} ;; uniq MODIF
=C2=A0 ;; C12 in Terminal mode with MacOS Vent= ura M1 and 32"
=C2=A0
=C2=A0 ;; (nodebug
=C2=A0 ;; =C2=A0{un= ified-minterms-set-uniq-length <+ (length unified-minterms-set)}
=C2= =A0 ;; =C2=A0(dv unified-minterms-set-uniq-length))

=C2=A0 ;;{unifie= d-minterms-set <+ (remove-duplicates (filter (=CE=BB (x) x) unified-mint= erms-set-1))} ;; C12 in Terminal mode with MacOS Ventura M1 and 32"=C2=A0
=C2=A0 ;;{unified-minterms-set <+ (list-transduce (compose (= tfilter (=CE=BB (x) x)) (tdelete-duplicates)) rcons unified-minterms-set-1)= } ;; C12 in Terminal mode with MacOS Ventura M1 and 31"

and Guile:

=C2=A0;; 8'04" MacOS Ventura M1 for C12 ,50&= quot; for C11
=C2=A0 ;;{unified-minterms-set-2 <+ (filter (=CE=BB (x)= x) unified-minterms-set-1)} ;; remove #f results
=C2=A0 ;; (nodebug
= =C2=A0 ;; =C2=A0{unified-minterms-set-2-length <+ (length unified-minter= ms-set-2)}
=C2=A0 ;; =C2=A0(dv unified-minterms-set-2-length))

= =C2=A0 ;;{unified-minterms-set <+ (remove-duplicates unified-minterms-se= t-2)} ;;(remove-duplicates-sorted unified-minterms-set-2)} ;; uniq MODIF=C2=A0 ;; (nodebug
=C2=A0 ;; =C2=A0{unified-minterms-set-uniq-length &l= t;+ (length unified-minterms-set)}
=C2=A0 ;; =C2=A0(dv unified-minterms-= set-uniq-length))

=C2=A0 {unified-minterms-set <+ (remove-duplica= tes (filter (=CE=BB (x) x) unified-minterms-set-1))} ;; 59" for C11, 8= '05" for C12
=C2=A0
=C2=A0 ;; 7'08" ,8'15"= ; MacOS Ventura M1 for C12 and 56" for C11
=C2=A0 ;;{unified-minter= ms-set <+ (list-transduce (compose (tfilter (=CE=BB (x) x)) (tdelete-dup= licates)) rcons unified-minterms-set-1)}
=C2=A0
some code is commented because i o= nly run one test at a time.

I suppose the speed up was only because debug mode slowed down other cod= e but perheaps my test are not reliable, i can only explain some slow down = now due to CPU overloaded by another process in the system at different mom= ent in tests. I have no idea how to perform more reliable tests.
<= /div>
O= n Thu, Dec 22, 2022 at 6:32 PM Damien Mattei <damien.mattei@gmail.com> wrote:
i'm interested with transducers to= speed up code:

;; 8'= 21" MacOS Ventura M1
=C2=A0 {unified-minterms-set-2 <+ (filter (= =CE=BB (x) x) unified-minterms-set-1)} ;; remove #f results
=C2=A0 (node= bug
=C2=A0 =C2=A0{unified-minterms-set-2-length <+ (length unified-mi= nterms-set-2)}
=C2=A0 =C2=A0(dv unified-minterms-set-2-length))

= =C2=A0 {unified-minterms-set <+ (remove-duplicates unified-minterms-set-= 2)} ;;(remove-duplicates-sorted unified-minterms-set-2)} ;; uniq MODIF
= =C2=A0 (nodebug
=C2=A0 =C2=A0{unified-minterms-set-uniq-length <+ (le= ngth unified-minterms-set)}
=C2=A0 =C2=A0(dv unified-minterms-set-uniq-l= ength))

with transducers:=
;; 7'08&qu= ot; MacOS Ventura M1
=C2=A0 {unified-minterms-set <+ (list-transduce = (compose (tfilter (=CE=BB (x) x)) (tdelete-duplicates)) rcons unified-minte= rms-set-1)}
it is an inte= resting 15% speed up in my code.


On Thu, Dec 22, 2022 at 3:52 PM Damien Mattei= <damien.ma= ttei@gmail.com> wrote:
i just understood the scheme :-)

scheme@(guile-user)> (list-transduce (compose (tfil= ter (=CE=BB (x) x)) (tdelete-duplicates)) rcons (list 1 2 #f 3 3 4))
$12= =3D (1 2 3 4)
=
sorry...

=
On Thu= , Dec 22, 2022 at 3:33 PM Damien Mattei <damien.mattei@gmail.com> wrote:
hello,
just trying transducers befo= re using it, i try to understand.
what is wrong with that:
scheme@(guile-user)> (list-transduce (tfi= lter (=CE=BB (x) x)) (tdelete-duplicates) (list 1 2 #f 3 3 4))
ice-9/boo= t-9.scm:1685:16: In procedure raise-exception:
Wrong number of arguments= to #<procedure 10786aa60 at srfi/srfi-171.scm:338:2 (reducer)>
Entering a new prompt.=C2=A0 Type `,bt' for a backtrace or `,q' t= o continue.
Regards,
Damien

On = Wed, Dec 21, 2022 at 11:01 AM Linus Bj=C3=B6rnstam <linus.bjornstam@veryfast.biz<= /a>> wrote:
A= s the author of both the SRFI and the guile code I am very happy you like i= t. I don't have a computer at the moment, but I looked through the code= and it looked great.

All additions should have been included in the original SRFI :)

one comment: your code uses define-public, which the rest of SRFI-171 code = does not.

I am not in any position to sign code off for inclusion in guile proper, bu= t if the define-public thing is fixed it very much has my blessing.

Best regards
=C2=A0 Linus Bj=C3=B6rnstam

On Wed, 21 Dec 2022, at 01:48, Colin Woodbury wrote:
> Happy holidays everyone, I hope everything is going well for you.
>
> Since discovering SRFI-171 (Transducers) I have fallen in love with it= .
> Transducers let me "talk the way I want to talk" while knowi= ng that I'm
> being efficient underneath w.r.t. to iteration and allocation. In usin= g
> Guile's implementation, I noticed a few common idioms missing that= are
> otherwise present in other languages, so I've added them in a seri= es of
> patches. I've been using these often for a number of weeks without=
> issue, but of course have added unit tests as well.
>
> The full details are in the commit messages, but here are the main hig= hlights:
>
>=C2=A0 * rfold: The fundamental reducer. This allows the user to turn a= ny
> two-arg function into a valid reducer, so that they don't need to = worry
> about hand-writing reducers via case-lambda.
>=C2=A0 * rfind: Yields the first item in the transduction that matches = some
> predicate. Nice for locating some specific value from a potentially > large data source (e.g. a port).
>=C2=A0 * twindow: Like tsegment, but yields overlapping slices into the= data.
> Cheers, and have a great holiday.
>
> Colin
>
> Attachments:
> * 0001-srfi-171-add-twindow-and-various-reducers.patch
> * 0002-doc-add-new-SRFI-171-reducers-to-the-manual.patch
> * 0003-srfi-171-add-unit-tests-for-new-functions.patch

--0000000000009de9ca05f092d695--