Flow control: after, cond, while_loop
cond
@tc.get_op
def to_feet(txn, meters: tc.Number) -> tc.Number:
# IMPORTANT! don't use Python's if statement! use tc.cond!
return tc.cond(
meters >= 0,
meters * 3.28,
tc.error.BadRequest("negative distance is not supported"))after
@tc.post_op
def num_rows(txn):
max_len = 100
schema = tc.table.Schema(
[tc.Column("user_id", tc.Number)],
[tc.Column("name", tc.String, max_len), tc.Column("email", tc.String, max_len)])
txn.table = tc.table.Table(schema)
txn.table.insert((123,), ("Bob", "bob.roberts@example.com"))
return txn.table.count()while_loop
Nested conditionals
Examples: updating a Tensor conditionally
Last updated
Was this helpful?