question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce decorator-style API

See original GitHub issue

Decorators are pretty?

For example (name is undecided), we can simply define a decorated “op builder” function:

@tfplot.op(batch=True)
def plot_heatmap(heatmap, cmap='jet')
    # heatmap: a [16x16] numpy array here
    fig, ax = tfplot.subplots(figsize=(4, 3))
    im = ax.imshow(heatmap, cmap=cmap)
    fig.colorbar(im)
    return fig

# heatmap_tensor : a float32 Tensor of shape [4, 16, 16], for example
>>> plot_heatmap(heatmap_tensor)
Tensor("PlotHeatmap:0", shape=(4, ?, ?, 3), dtype=uint8)

Instead of:

# heatmap_tensor : a float32 Tensor of shape [4, 16, 16], for example
>>> PlotOp = tfplot.wrap(figure_heatmap, batch=True, name='PlotHeatmap')
>>> PlotOp(heatmap_tensor)
Tensor("PlotHeatmap:0", shape=(4, ?, ?, 3), dtype=uint8)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
wookayincommented, Oct 22, 2018

I have been working on this these days, please see #7 (in progress).

  • tfplot.wrap: The existing tfplot.wrap() can be used as a decorator as well, as suggested by @ferrine.
  • tfplot.autowrap: Similar to wrap, but supports automatic injection of fig, ax. This will replace wrap_axesplot soon. Batch supports, etc. will be added soon.

/cc @ferrine Do you want to take a look or review it?

0reactions
wookayincommented, Feb 15, 2019

If you want to kindly give some suggestions, it would be greatly appreciated of course.

Read more comments on GitHub >

github_iconTop Results From Across the Web

introduction-decorators-decorator-class-decorator-set-api ...
Instantly share code, notes, and snippets. @omarkdev · omarkdev/introduction-decorators-decorator-class-decorator- ...
Read more >
Decorator pattern - Wikipedia
In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, ...
Read more >
Documentation - Decorators - TypeScript
Introduction. Further Reading: A Complete Guide to TypeScript Decorators. With the introduction of Classes in TypeScript and ES6, there now exist certain ...
Read more >
Quickstart — RESTArt 0.1.3 documentation - Read the Docs
This page gives you a good introduction to RESTArt. ... from restart.api import RESTArt from restart.resource import Resource api = RESTArt() ...
Read more >
tff.tf_computation - Federated - TensorFlow
Decorates/wraps Python functions and defuns as TFF TensorFlow computations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found