Where¶
A masked array assignment.
Declaration¶
Syntax¶
Where(expr test, stmt* body, stmt* orelse)
Arguments¶
Argument |
Description |
|---|---|
|
the logical array mask. |
|
the assignments performed where the mask is true. |
|
the assignments performed where it is false, from |
Return values¶
None.
Description¶
where applies its assignments element by element under a mask. It is not a
conditional statement: the mask is an array, and both branches are array
assignments over the same shape.
The mask is evaluated once, before any assignment, so an assignment in the
body cannot change which elements the elsewhere applies to.
Examples¶
(Where
:test (Var
:v (SymbolRef 1 "mask")
)
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "a")
)
:value (IntegerConstant
:n 0
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
:orelse [
(Assignment
:target (Var
:v (SymbolRef 1 "a")
)
:value (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"a" (Variable
:parent_symtab 1
:name "a"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Array
:type (Integer
:kind 4
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 3
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:physical_type :FixedSizeArray
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"mask" (Variable
:parent_symtab 1
:name "mask"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Array
:type (Logical
:kind 4
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 3
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:physical_type :FixedSizeArray
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
}
)
:name "main"
:dependencies []
:body [
(Where
:test (Var
:v (SymbolRef 1 "mask")
)
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "a")
)
:value (IntegerConstant
:n 0
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
:orelse [
(Assignment
:target (Var
:v (SymbolRef 1 "a")
)
:value (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
)
]
)
}
)
:items []
)