pypto.SymbolicScalar.max

Applicable Products

  • Ascend 950PR/Ascend 950DT: Supported
  • Atlas A3 training products/Atlas A3 inference products: Supported
  • Atlas A2 training products/Atlas A2 inference products: Supported

Description

Computes the maximum of two symbolic scalars.

Use Cases

Use this method when you need to compare SymbolicScalar values, such as dynamic dimension values obtained from tensor.shape.

Difference from pypto.maximum:

  • pypto.maximum: Used for element-wise maximum computation on tensors.
  • SymbolicScalar.max: Used for maximum computation on symbolic scalars.

Python ternary expressions are not supported:

# ❌ Incorrect: Ternary expressions are not supported.
cur_seq = kv_act_seqs[b_idx]
tmp = cur_seq - s2_idx * s2_tile
actual = tmp if tmp > threshold else threshold

# ✅ Correct: Use the .max() method.
actual = (cur_seq - s2_idx * s2_tile).max(threshold)

Prototype

max(self, other: 'SymbolicScalar | int') -> 'SymbolicScalar'

Parameters

Parameter NameInput/OutputDescription
otherInputSymbolic scalar or integer to be compared.

Return Value

Returns the maximum of the two values. If both are concrete values, a constant is returned; otherwise, a symbolic expression of the SymbolicScalar type is returned.

Constraints

  • If both values are concrete, a concrete constant value is returned.
  • If at least one value is not concrete, a symbolic expression is returned.

Example

s1 = pypto.SymbolicScalar(10)
s2 = pypto.SymbolicScalar(5)
out1 = s1.max(s2)
out2 = s1.max(13)
s3 = pypto.SymbolicScalar("x")
out3 = s3.max(2)

The results are as follows:

Output data out1: 10
Output data out2: 13
Output data out3: RUNTIME_Max(x, 2)