return

return (each block), keyword

At the end of an each block, the return statement specifies the value to return.

table T = extend.range(5)

factorial = 1
T.Factorial = each T scan auto
  keep factorial
  factorial = factorial * T.N
  return factorial

show table "Factorials" with
  T.N
  T.Factorial

This outputs the following table:

N Factorial
1 1
2 2
3 6
4 24
5 120

The return statement supports tuple values.

table T = extend.range(5)

sum = 0
factorial = 1
T.Sum, T.Factorial = each T scan auto
  keep sum
  keep factorial
  sum = sum + T.N
  factorial = factorial * T.N
  return (sum, factorial)

show table "Sum and factorial" with
  T.N
  T.Sum
  T.Factorial

This outputs the following table:

N Sum Factorial
1 1 1
2 3 2
3 6 6
4 10 24
5 15 120

return (autodiff block), keyword

At the end of an autodiff block, the return statement specifies the loss. The loss must be a number.

a = 2

autodiff Scalar epochs:1 learningRate:0 with
  params a
  s = a * a
  return s

show scalar "a" with a

This outputs the following scalar:

a
2

Tuple returns are allowed in autodiff, but only the first value is used as the loss; the other values are reported as metrics.

return (user-defined function), keyword

At the end of a def block, the return statement specifies the value returned by the function or process.

def pure square(x: number) with
  return x * x

show scalar "3^2" with square(3)

This outputs the following scalar:

3^2
9
User Contributed Notes
0 notes + add a note