View Source Nx.Defn.Composite (Nx v0.2.1)
Functions to deal with composite data types according to Nx.Container
.
The functions in this module can be used both inside and outside defn
.
Link to this section Summary
Functions
Traverses two composite types to see if they are compatible.
Counts the number of non-composite types in the composite type.
Flattens the given list of composite types.
Reduces the given composite types with acc
and fun
.
Traverses the given composite types with fun
.
Traverses the given composite types with acc
and fun
.
Link to this section Functions
Traverses two composite types to see if they are compatible.
For non-composite types, the given fun
will be called to
compare numbers/tensors pairwise.
Counts the number of non-composite types in the composite type.
examples
Examples
iex> Nx.Defn.Composite.count(123)
1
iex> Nx.Defn.Composite.count({1, {2, 3}})
3
iex> Nx.Defn.Composite.count({Complex.new(1), {Nx.tensor(2), 3}})
3
Flattens the given list of composite types.
Elements that are not tensors (i.e. numbers and Complex
numbers) are kept as is
unless a custom function is given.
examples
Examples
iex> Nx.Defn.Composite.flatten_list([1, {2, 3}])
[1, 2, 3]
iex> Nx.Defn.Composite.flatten_list([1, {2, 3}], [Nx.tensor(4)])
[1, 2, 3, Nx.tensor(4)]
iex> Nx.Defn.Composite.flatten_list([1, {2, 3}], [Nx.tensor(4)], &Nx.tensor/1)
[Nx.tensor(1), Nx.tensor(2), Nx.tensor(3), Nx.tensor(4)]
Reduces the given composite types with acc
and fun
.
If composite tensor expressions are given, such as a tuple, the composite type is recursively traversed and returned.
If a non-composite tensor expression is given, the function is invoked for it but not for its arguments.
Traverses the given composite types with fun
.
If composite tensor expressions are given, such as a tuple, the composite type is recursively traversed and returned.
If a non-composite tensor expression is given, the function is invoked for it but not for its arguments.
Traverses the given composite types with acc
and fun
.
If composite tensor expressions are given, such as a tuple, the composite type is recursively traversed and returned.
If a non-composite tensor expression is given, the function is invoked for it but not for its arguments.