Skip to content

Much easier way to write control flows #184

Closed
@chaoming0625

Description

@chaoming0625

Please:

  • Check for duplicate requests.
  • Describe your goal, and if possible provide a code snippet with a motivating example.

Control flow is not easy in BrainPy because it relies on JAX. I think maybe there is a more conveninet way to write control flows. Like,

import brainpy as bp
import brainpy.math as bm

def f(a)
  return bm.ifelse(a > 10., lambda x: 10., 
                   a > 5 and a <= 10, lambda x: x*2,
                   lambda x: x+2, x)

Or,

def f(b)
  return bm.ifelse(conditions=[a > 10.,  a > 5 and a <= 10], 
                   functions=[lambda x: 10., lambda x: x*2, lambda x: x+2], 
                   operands=x,
                   dyn_vars=...)

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions