companion_cube changed the topic of #ocaml to: Discussion about the OCaml programming language | http://www.ocaml.org | OCaml 5.2.0 released: https://ocaml.org/releases/5.2.0 | Try OCaml in your browser: https://try.ocamlpro.com | Public channel logs at https://libera.irclog.whitequark.org/ocaml/
Everything has quit [Quit: leaving]
<discocaml> <gabyfle> Hi ! For some reasons I don't have any ocaml stubs in my system. I'm using opam to install ocaml compilers. Does anyone knows how to get them properly ? Thanks a lot in advance :p
raskol has quit [Ping timeout: 260 seconds]
<discocaml> <gabyfle> Hi ! For some reasons I don't have any ocaml stubs in my system. I'm using opam to install ocaml compilers. Does anyone knows how to get them properly ?
<discocaml> <gabyfle> When I do a
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```
<discocaml> <gabyfle> ocamlc -where
<discocaml> <gabyfle> ```
<discocaml> <gabyfle>
<discocaml> <gabyfle> I got this:
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```
<discocaml> <gabyfle> /home/<me>/.opam/5.2.0-flambda/lib/ocaml
<discocaml> <gabyfle> ```
<discocaml> <gabyfle> But there aren't any stubs in there none of the usual ocaml header files that I could use :/
<discocaml> <gabyfle> Thanks a lot in advance :p
raskol has joined #ocaml
Tuplanolla has quit [Quit: Leaving.]
cr1901_ is now known as cr1901
companion_cube has quit [Quit: WeeChat 4.3.3]
ocabot has quit [Remote host closed the connection]
discocaml has quit [Remote host closed the connection]
ocabot has joined #ocaml
discocaml has joined #ocaml
companion_cube has joined #ocaml
pi3ce_ has quit [Read error: Connection reset by peer]
pi3ce has joined #ocaml
pi3ce has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
pi3ce has joined #ocaml
<discocaml> <softwaresirppi> Ohh okayy thank you!
euphores has quit [Quit: Leaving.]
bartholin has joined #ocaml
semarie has joined #ocaml
Anarchos has joined #ocaml
anpad has quit [Quit: ZNC 1.8.2 - https://znc.in]
anpad has joined #ocaml
Anarchos has quit [Client Quit]
Serpent7776 has joined #ocaml
bibi_ has quit [Quit: Konversation terminated!]
<discocaml> <lukstafi> Ah I don't think that the first approach works with dynamic first-class modules either, I need the following bloat / workaround: `let module M = (val get_m ()) in let u = M.get_u () in f (module M) u`. So I'm guessing explicits will not make it any worse.
<discocaml> <lukstafi> Or `let module M = (val get_m ()) in f1 (module M) ()` where `let f : (module M : MT) -> unit -> unit` and `MT` has abstract types -- `f1 (get_m ()) ()` doesn't work.
omniscient has joined #ocaml
neiluj has joined #ocaml
bartholin has quit [Quit: Leaving]
omniscient has quit [Ping timeout: 255 seconds]
omniscient has joined #ocaml
alexherbo2 has joined #ocaml
<discocaml> <lukstafi> The last part is wrong, if the abstract types are not used dynamic first-class modules are ok.
<discocaml> <gabyfle> Hi ! I'm currently working on this: <https://github.com/gabyfle/SoundML> and I'm having a bottleneck in my computations due to a type conversion problem. When computing a spectrogram, the output is a Complex Biggarray (in fact, a Owl's Ndarray but it's just bigarrays under the hood). The problem is that sometimes we only want the real parts of the complex values inside this array that is, if our array is {z | z € A} with z € C (the complex
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```ocaml
<discocaml> <gabyfle> let real (x : (Complex.t, Bigarray.complex32_elt) Owl.Dense.Ndarray.Generic.t) =
<discocaml> <gabyfle> let ttime = Unix.gettimeofday () in
<discocaml> <gabyfle> let dims = Audio.G.shape x in
<discocaml> <gabyfle> let re = Audio.G.create Bigarray.Float32 dims 0. in
<discocaml> <gabyfle> Audio.G.iteri_nd (fun i z -> Audio.G.set re i Complex.(z.re)) x ;
<discocaml> <gabyfle> Owl.Log.debug "Elapsed time for Complex z -> Re(z) compute: %f"
<discocaml> <gabyfle> (Unix.gettimeofday () -. ttime) ;
<discocaml> <gabyfle> re
<discocaml> <gabyfle> ```
<discocaml> <gabyfle>
<discocaml> <gabyfle> Under the hood, `iteri_nd` is just a `for` loop on the elements of the bigarray. Here comes the bottleneck:
<discocaml> <gabyfle>
<discocaml> <gabyfle>
<discocaml> <gabyfle> This is the elapsed time for the computation of the complex spectrogram and the evaluation of `real c` where `c` is our complex bigarray:
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```ocaml
<discocaml> <gabyfle> 2024-10-28 12:22:16.311 DEBUG : Elapsed time for specgram compute: 0.134960
<discocaml> <gabyfle> 2024-10-28 12:22:16.785 DEBUG : Elapsed time for Complex z -> Re(z) compute: 0.473705
<discocaml> <gabyfle> ```
<discocaml> <gabyfle>
<discocaml> <gabyfle> As you can see, `real c` takes as much as 3 times the time to compute the specgram which is absolutely not wanted. Does anyone have any idea on how could I make this way faster ?
<discocaml> <gabyfle> Hi ! I'm currently working on this: <https://github.com/gabyfle/SoundML> and I'm having a bottleneck in my computations due to a type conversion problem. When computing a spectrogram, the output is a Complex Biggarray (in fact, a Owl's Ndarray but it's just bigarrays under the hood). The problem is that sometimes we only want the real parts of the complex values inside this array that is, if our array is {z | z € A} with z € C (the complex
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```ocaml
<discocaml> <gabyfle> let real (x : (Complex.t, Bigarray.complex32_elt) Owl.Dense.Ndarray.Generic.t) =
<discocaml> <gabyfle> let ttime = Unix.gettimeofday () in
<discocaml> <gabyfle> let dims = Audio.G.shape x in
<discocaml> <gabyfle> let re = Audio.G.create Bigarray.Float32 dims 0. in
<discocaml> <gabyfle> Audio.G.iteri_nd (fun i z -> Audio.G.set re i Complex.(z.re)) x ;
<discocaml> <gabyfle> Owl.Log.debug "Elapsed time for Complex z -> Re(z) compute: %f"
<discocaml> <gabyfle> (Unix.gettimeofday () -. ttime) ;
<discocaml> <gabyfle> re
<discocaml> <gabyfle> ```
<discocaml> <gabyfle>
<discocaml> <gabyfle> Under the hood, `iteri_nd` is just a `for` loop on the elements of the bigarray. Here comes the bottleneck:
<discocaml> <gabyfle>
<discocaml> <gabyfle>
<discocaml> <gabyfle> This is the elapsed time for the computation of the complex spectrogram and the evaluation of `real c` where `c` is our complex bigarray:
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```ocaml
<discocaml> <gabyfle> 2024-10-28 12:22:16.311 DEBUG : Elapsed time for specgram compute: 0.134960
<discocaml> <gabyfle> 2024-10-28 12:22:16.785 DEBUG : Elapsed time for Complex z -> Re(z) compute: 0.473705
<discocaml> <gabyfle> ```
<discocaml> <gabyfle>
<discocaml> <gabyfle> As you can see, `real c` takes as much as 3 times the time to compute the specgram which is absolutely not wanted. Does anyone have any idea on how could I make this way faster ?
<discocaml> <gabyfle>
<discocaml> <gabyfle> I've tried using `Owl.Dense.Ndarray.re_c2s`, but looks like under the hood it does exactly the same thing:
<discocaml> <gabyfle>
<discocaml> <gabyfle> ```c
<discocaml> <gabyfle> #define FUN14 re_c2s
<discocaml> <gabyfle> #define NUMBER complex_float
<discocaml> <gabyfle> #define NUMBER1 float
omniscient has quit [Ping timeout: 248 seconds]
<companion_cube> Bigarrays are way slower if the compiler doesn't know the exact type
<companion_cube> It's better to always annotate and monomorphize if you can
omniscient has joined #ocaml
omniscient has quit [Remote host closed the connection]
neiluj has quit [Ping timeout: 252 seconds]
YuGiOhJCJ has quit [Quit: YuGiOhJCJ]
neiluj has joined #ocaml
spew has joined #ocaml
<Fardale1> I am looking at Bechamel. I want to use Test.make_with_resource, what is the argument kind for? Looking at the code I don't understand what it is useful for.
mbuf has joined #ocaml
neiluj has quit [Read error: Connection reset by peer]
neiluj has joined #ocaml
neiluj_ has joined #ocaml
neiluj has quit [Ping timeout: 245 seconds]
<discocaml> <softwaresirppi> Guys what do you think about exceptions and the oddly names `exn`?
<discocaml> <softwaresirppi> Why not the ability to raise any value?
<companion_cube> how would you typecheck `try … with e -> …`? what's the type of `e`?
<discocaml> <softwaresirppi> Maybe it has a tagged union inside it?
<discocaml> <softwaresirppi> So that I could pattern match?
<discocaml> <softwaresirppi> Okay that's why exceptions are their own tupe
<discocaml> <softwaresirppi> 😂😂 thanks
<discocaml> <._null._> As for the "oddly named exn", `exception` was already a keyword so it was taken
<discocaml> <softwaresirppi> How was life before exn?!
<discocaml> <softwaresirppi> Also tell me anything cool or nice to know about exceptions
<discocaml> <softwaresirppi> I'm foreign to ocaml's exceptions
<discocaml> <softwaresirppi> You define an exception like `exception OhFuk of string`
<discocaml> <softwaresirppi> And then you raise it like `raise OhFuk "doesn't work brotha"`
<discocaml> <softwaresirppi> Also a thing to be noted is ... Exception declaration doesn't have an = sign
<companion_cube> I don't think there was life before exceptions
<companion_cube> it's a feature that was in the early MLs afaict
<companion_cube> it was there in caml light
<discocaml> <softwaresirppi> I see
<discocaml> <softwaresirppi> Also the signature of raise is `exn -> 'a`
<discocaml> <softwaresirppi> Poor alpha never gets returned 🫠
<companion_cube> yeah `raise` doesn't return
<discocaml> <softwaresirppi> Ohh generational baggage
<discocaml> <softwaresirppi> Such a sad story
<discocaml> <softwaresirppi> I don't know if I'm just being unfamiliar to syntax or this syntax bad lol
<discocaml> <softwaresirppi> I'll have to spend some time
<discocaml> <deepspacejohn> you raise any value as long as you defined an exception to wrap it in: `exception Exn_int of int exception Exn_string of string` etc.
<discocaml> <deepspacejohn> You can't have a polymorphic exception though (without GADTs) because that would not be type safe `exception Bad of 'a`
<discocaml> <lukstafi> I'd prefer if it was `throw` instead of `raise` because the opposite of `raise` is `lower`
<discocaml> <lecondorduplateau> exceptions are in fact an extensible variant
<discocaml> <lecondorduplateau> and `exception Foo of string` is actualy syntaxic sugar for `type exn += Foo of string`
<discocaml> <lecondorduplateau> afaik
<discocaml> <lecondorduplateau> see <https://ocaml.org/manual/5.2/extensiblevariants.html>
<discocaml> <gooby_clown> I just `failwith` to avoid defining exceptions
<companion_cube> well, extensible sum types were added later
<companion_cube> exn was the first iteration of them
<discocaml> <softwaresirppi> Ohh
<discocaml> <softwaresirppi> Bro has more OCD than me
<discocaml> <softwaresirppi> WOW
<discocaml> <softwaresirppi> Thanks a LOT @lecondorduplateau
<discocaml> <softwaresirppi> I need to unsugar my Ocaml first when learning
<discocaml> <softwaresirppi> `type exn += Foo of string` makes an insane lot of sense
<discocaml> <softwaresirppi> You add a new variant to the exn type
<discocaml> <softwaresirppi> Wow
<discocaml> <softwaresirppi> Can I somehow list all the variants of a type?
<discocaml> <lecondorduplateau> it's enlightening hm?
<discocaml> <lecondorduplateau> not really afaik
<discocaml> <softwaresirppi> @lecondorduplateau I'm watching/reading the Ocaml book... Do you have any other resources that get deep into these things?
<discocaml> <lecondorduplateau> maybe it's possible to get the number of constructors with unsafe function of module `Obj`
<discocaml> <softwaresirppi> I see
<discocaml> <gooby_clown> It's okay, can just write a ppx
<discocaml> <lecondorduplateau> not really currently in my mind but I have appreciated this section of real world ocaml <https://dev.realworldocaml.org/runtime-memory-layout.html>
<discocaml> <deepspacejohn> Constructors can be added to an extensible type dynamically. This is also why matching an extensible variant always needs a wildcard `| _ ->` case to be exhaustive.
<discocaml> <lecondorduplateau> oh yes
<discocaml> <softwaresirppi> can i tell you guys something? `failwith` is mumble case but `invalid_arg` is snake case
<discocaml> <gooby_clown> 😱
<discocaml> <softwaresirppi> reasonable
<discocaml> <gooby_clown> OCaml is doomed
<discocaml> <softwaresirppi> why
<discocaml> <gooby_clown> Inconsistent stdlib casing
<discocaml> <gooby_clown> 😔
<discocaml> <lecondorduplateau> 😔
<discocaml> <softwaresirppi> oh youre replying to me 😥
<discocaml> <gooby_clown> oui
<discocaml> <lecondorduplateau> I also like the presentation given by xavier leroy for the birthday of ocaml
<discocaml> <lecondorduplateau> pretty interresting
<discocaml> <softwaresirppi> thanks
<discocaml> <softwaresirppi> i was looking up ocaml talks in youtube
<discocaml> <softwaresirppi> nothing really showed up
<discocaml> <gooby_clown> You must search in French
<discocaml> <softwaresirppi> oh boy
<discocaml> <softwaresirppi> i saw this talk in youtube
<discocaml> <softwaresirppi> haha why
<discocaml> <gooby_clown> OCaml was created in France and most researchers involved are French
<discocaml> <gooby_clown> In fact half the people here you talked with are French
<discocaml> <softwaresirppi> oh mai god
<discocaml> <softwaresirppi> okay guys
<discocaml> <softwaresirppi> itsaa mee maarioo
<discocaml> <gooby_clown> 😢
<discocaml> <softwaresirppi> oh wait hes italian
<discocaml> <softwaresirppi> ugh fk
<discocaml> <softwaresirppi> anyways Gooby, where can i see all the core features and syntax for ocaml?
<discocaml> <softwaresirppi> without the SUGAR
<discocaml> <softwaresirppi> GIMME THE COFFEE RAW
<discocaml> <gooby_clown> Though actually
<discocaml> <gooby_clown> They have some English talks
<discocaml> <gooby_clown> (this one isn't about OCaml but still)
<discocaml> <softwaresirppi> i wish there was more content for me binge about ocaml
Ekho has quit [Quit: CORE ERROR, SYSTEM HALTED.]
<discocaml> <gooby_clown> You want to eventually get into papers
<discocaml> <deepspacejohn> The manual is pretty comprehensive although its organization is kind of weird to me https://ocaml.org/manual/5.2/language.html
<discocaml> <gooby_clown> Yeah, it's often easier to find the entry through Google
alexherbo2 has quit [Remote host closed the connection]
bibi_ has joined #ocaml
<discocaml> <softwaresirppi> Even in that I can't find the `type exn +=` syntax
<discocaml> <deepspacejohn> It's in the "language extensions" part https://ocaml.org/manual/5.2/extensiblevariants.html
Ekho has joined #ocaml
<discocaml> <deepspacejohn> (the fact that some features are in the extensions section is part of why I dislike the manual's organization.)
euphores has joined #ocaml
<neiluj_> hey! I'm using an Lru cache https://opam.ocaml.org/packages/lru/ in a mutable field, but by the first time I access it (through Lru.find), my application becomes stuck
<neiluj_> how would you debug this?
<neiluj_> on an other note, do you know if there are themes for odoc pages?
pi3ce has quit [Ping timeout: 265 seconds]
pi3ce has joined #ocaml
<discocaml> <contificate> Can you elaborate, does your program block indefinitely?
olle__ has joined #ocaml
olle__ has quit [Ping timeout: 265 seconds]
bartholin has joined #ocaml
Anarchos has joined #ocaml
mbuf has quit [Quit: Leaving]
semarie has quit [Ping timeout: 252 seconds]
neiluj_ has quit [Quit: WeeChat 4.2.1]
f[x] has joined #ocaml
Anarchos has quit [Read error: Connection reset by peer]
motherfsck has quit [Ping timeout: 252 seconds]
Tuplanolla has joined #ocaml
motherfsck has joined #ocaml
Everything has joined #ocaml
euphores has quit [Ping timeout: 244 seconds]
euphores has joined #ocaml
Everything has quit [Read error: Connection reset by peer]
Everything has joined #ocaml
Everything has quit [Ping timeout: 246 seconds]
Everything has joined #ocaml
bartholin has quit [Quit: Leaving]
Serpent7776 has quit [Ping timeout: 276 seconds]
f[x] has quit [Remote host closed the connection]
raskol has quit [Ping timeout: 252 seconds]
Everything has quit [Quit: leaving]