Skip to content

support for coroutine #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dreem-Devices opened this issue Jan 20, 2016 · 10 comments · Fixed by #145
Closed

support for coroutine #47

Dreem-Devices opened this issue Jan 20, 2016 · 10 comments · Fixed by #145

Comments

@Dreem-Devices
Copy link

I have a lot of coroutine to comment but i have not seen any suppport for this python feature.

The yield allows to comment what goes out of the coroutine but it would be nice to be able to specify what goes in in a specific manner.

@stefanv
Copy link
Contributor

stefanv commented Jan 27, 2016 via email

@jnothman
Copy link
Member

A "Receives" heading and parameter listing perhaps??

@stefanv
Copy link
Contributor

stefanv commented Sep 11, 2017

Does it make sense to bundle this under the yield description?

@jnothman
Copy link
Member

Does it make sense to bundle this under the yield description?

In the sense that the signature should describe one or a tuple of arguments to be passed to a function, it does not belong in yield. It is another parameter listing, with type specs and descriptions.

@stefanv
Copy link
Contributor

stefanv commented Sep 12, 2017

I guess I'd need a concrete code snippet example to wrap my head around this.

@jnothman
Copy link
Member

A bit artificial, but perhaps:

def optimize(n_params):
    """Supplies candidates to search in response to error signal

    Parameters
    ----------
    n_params : int

    Yields
    ------
    candidate : array of shape (n_params,)

    Given
    -----
    error : float
    """

    candidate = np.random.rand(n_params)
    error = yield candidate
    while not_converged():
        candidate = generate_new_candidate(candidate, error)
        results = yield candidate




optimizer = optimize(10)
candidate = next(optimizer)
while True:
    try:
        candidate = optimizer.send(evaluate(candidate))
    except StopIteration:
        break

@stefanv
Copy link
Contributor

stefanv commented Sep 13, 2017

I can't find any language around this in the documentation, so Receives works for me.

@jnothman
Copy link
Member

Yes, receives makes some sense. @Dreem-Devices, any opinion?

@jnothman
Copy link
Member

jnothman commented Nov 1, 2017

@tacaswell, you +1ed the issue. Do you have an opinion on the section naming? "Receives" okay?

@tacaswell
Copy link
Contributor

I like Receives, Sent could also make sense (as you .send the values in).

co-routines also need to support Return, I assume that is ok, but was not included in the example above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants