Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 14 09:37
    xxdavid commented #551
  • Oct 10 23:17
    evhub labeled #558
  • Oct 10 23:17
    evhub opened #558
  • Oct 07 21:14
    regr4 commented #551
  • Oct 07 20:35
    evhub commented #551
  • Oct 07 20:13
    evhub commented #551
  • Oct 07 17:12
    evhub milestoned #551
  • Oct 07 15:00
    xxdavid commented #551
  • Oct 03 19:56
    evhub commented #557
  • Oct 03 19:55
    evhub closed #557
  • Oct 03 19:55
    evhub commented #557
  • Oct 03 19:55
    evhub labeled #557
  • Oct 03 17:14
    pratibha-22 reopened #557
  • Oct 03 17:14
    pratibha-22 closed #557
  • Oct 03 17:13
    pratibha-22 opened #557
  • Sep 20 20:28
    evhub closed #555
  • Sep 20 20:28
    evhub demilestoned #555
  • Sep 20 20:28
    evhub labeled #555
  • Sep 20 20:08
    evhub milestoned #556
  • Sep 20 20:08
    evhub labeled #556
Evan Hubinger
@evhub
You can also just add an __fmap__ to the base class.
Elliott Indiran
@eindiran
This is an interesting PEP: https://www.python.org/dev/peps/pep-0622/
Evan Hubinger
@evhub
That's pretty exciting!
hsolatges
@hsolatges
Hi there. Enjoying Coconut magic! Thanks. Still I am wondering: what would be the nicest way (Coconut's way) to insert an element in a List? Given that list.insertreturns None. I would like to insert a midle point inbetween two points:[(0,1),(1,0)] -> [(0,1), (.5,.5),(1,0)]. I achieved it with a temp copy but I wondér if there is a pipe way, or a better way... Thanks!
Evan Hubinger
@evhub

@hsolatges You could try something like

def insert(iterable, loc, item) = iterable$[:loc] :: (item,) :: iterable$[loc:]

which is nice because it's more functional and works on any iterable.

If you need it to work on iterators rather than just iterables, though, you might want to do

def insert_iterator(iterator, loc, item) = reit$[:loc] :: (item,) :: reit$[loc:] where: reit = reiterable(iterator)

and if you need the result to be a list you can just call list at the end.

hsolatges
@hsolatges
@evhub Awesome! Thank you! :)
hsolatges
@hsolatges
It is nice to have that reiterable function
Roman Inflianskas
@rominf

Hi!
I'm building a high-performance library for ConceptNet access. I'm already close (the performance on queries with a big number of results is up to 2 times faster than in ConceptNet5, which uses PostgreSQL; on queries with small number of results it's slower ~15%). I'm using Coconut for "compiling" queries like this:

lcn.concept.has(language="lt").edge_all(relation="Synonym")

into a list of step objects (I use pattern matching using addpattern). The problem is that for 10K queries like this my program spends 11 s on compiling steps (23% total time). I looked closely and discovered that 6.5 s (13.5%) is spent on repr function. But I don't use repr in my code. As I understand, it's used for easier debugging (throwing exceptions). Could I strip these calls to repr for better performance (using special flag on compiling for example)?

Evan Hubinger
@evhub
@rominf I'd have to see your pattern-matching code to take a look at where Coconut is compiling to a bunch of repr calls—can you send a link or put it in a gist?
Evan Hubinger
@evhub
@rominf Should be fixed per #548 in coconut-develop now. Just pip install -U coconut-develop>=1.4.3-post_dev34 to get the fix.
Roman Inflianskas
@rominf
@evhub Thank you for a fast fix! Will try it soon.
Roman Inflianskas
@rominf
Yes, it became much faster!
Mason DeMelo
@MasonDeMelo
Hi all!
I'm interested in contributing to coconut and I'm trying to get a development environment set up, but unfortunately I'm running into some trouble with running "make dev". It looks like it's failing when trying to install cPyparsing, is this something that people have run into before?
Evan Hubinger
@evhub
@MasonDeMelo What's the error that you're getting?
Mason DeMelo
@MasonDeMelo
This is the log:
https://pastebin.com/96hVdJDY
I'm trying to install it in a Python 3.8 Virtualenv on Ubuntu 20.04 LTS
Evan Hubinger
@evhub
@MasonDeMelo It looks like your error is being caused by the C compilation failing. This is often caused by a mismatch in the Python version you're running and the Python libraries used by your C compiler by default. Things you can do: try installing outside of a virtualenv, explicitly set your PATH and/or other environment variables (like LIBRARY_PATH) to point to the right version of the Python libraries, or just don't use cPyparsing and use python pyparsing instead—Coconut functions fine with either.
ShalokShalom
@ShalokShalom
Coco can compile to Python 3 code, yes?
Or only to bytecode?
Evan Hubinger
@evhub
@ShalokShalom Coconut always compiles to Python source code not bytecode. By default, Coconut will compile to universal code which will run the same on any Python version. To specifically target Python 3, just pass --target 3.
ShalokShalom
@ShalokShalom
Fine ^^
What is the most readable?
Evan Hubinger
@evhub
You'll probably get the most readable code with --target sys, but compiled Coconut isn't really meant to be readable. You can also try passing --keep-lines to put the Coconut source as comments on the compiled Python, which might help readability in terms of helping you understand what Coconut line generated that Python line.
ShalokShalom
@ShalokShalom
Thanks a lot
Brian Parma
@bj0
i see #174 is still open, is there a workaround for prompting for input?
Evan Hubinger
@evhub
@bj0 #174 is closed—did you link the wrong issue accidentally?
Brian Parma
@bj0
oh sorry, I was in the wrong gitter channel ><
Thurston Sexton
@tbsexton
@evhub do you have any experience with google JAX?
I actually got into "functional" style after its requirement in things like jax, autograd, etc.
and ended up loving it, obviously finding the existing python tooling lacking...how I found toolz, pampy (https://github.com/santinic/pampy), and then of course coconut
the reason I ask is, i think jax could really seriously benefit from the syntax/features of coconut
BUT, while the basic syntax is all fine (just python, after all), it seems the jax jit-compile is incompatible with coconut, somehow.
I would love to have them work together (Ive had a working/testing notebook called cuckoo for cocojax for a long time now haha). But I'm not sure if this incompatibility is happening at the coconut level or something to do with the depths of jax.
Evan Hubinger
@evhub
@tbsexton I've only ever used tensorflow and pytorch, but I've heard good things about JAX. If you could raise an issue with the error you're getting when you try to run JAX on compiled Coconut, I'd be happy to take a look.
Thurston Sexton
@tbsexton
actually, i pulled fresh versions of both to make sure and.....it seems to be working just fine now ಠ_ಠ
And it's glorious, the workflow is fantastic with jax's vmap and coconut's partials/piping. I'm going to be running through a bunch of old/new code to refactor to coconut just to find edge-cases.
This may be worth mentioning on the website or docs or something....jax and autograd both repeatedly call out the need for functional coding style, so this is a huge QoL upgrade for those workflows. See https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#%F0%9F%94%AA-Pure-functions
Evan Hubinger
@evhub
great—glad to hear it!
ShalokShalom
@ShalokShalom
@evhub Please, I do like to see the integration of the pipe operator in Coconut? Do you do that with map? Can I see it?
Evan Hubinger
@evhub
@ShalokShalom I don't understand your question. Are you asking for Coconut's internal implementation of the pipe operator? The bulk of that can be found here, if that's what you're looking for.
Honestly, though, if you just want to understand how pipe works, it'd probably be easier to just use coconut --display to look at what various different uses of the pipe operator compile to.
ShalokShalom
@ShalokShalom
No, this is exactly what I was looking for
Why is this so imperative? Wouldnt it be far more easy, to use map?
I consider to implement a pipe in another language, that is very similar to Python, and try to look for inspiration. Is that for performance reasons so imperative?
Evan Hubinger
@evhub
@ShalokShalom How else would you compile x |> f other than to f(x)? There's nothing map-like going on with pipe, it's just function calls. And function calls are obviously very functional.
Genesis
@TheExGenesis

Hey Evan, thanks for your amazing work!

I was wondering what the right way to configure vscode to use coconut inside the interactive python REPL thing/ embedded notebooks. Already installed coconut --jupyter

Evan Hubinger
@evhub
@TheExGenesis Thanks! I don't use VSCode very much myself so I have no idea, but you're welcome to raise an issue for it. Certainly if VSCode has Jupyter support you can try to configure it to use the coconut kernel, but I don't know enough about VSCode to know how to do that.
Russ Abbott
@RussAbbott
Hi, I'm trying to install Coconut on Google colab. It seems to install, but it doesn't run. Please see my StackOverflow question. https://stackoverflow.com/questions/63965737/is-it-possible-to-run-coconut-on-colab. Thanks.
Russ Abbott
@RussAbbott
When I tried the iterator version of quick_sort in the online interpreter, I got a syntax error on the yield from line.
Evan Hubinger
@evhub
@RussAbbott It looks to me like you successfully installed Coconut, but didn't actually switch to the Coconut kernel rather than the Python kernel.