@@ -23,22 +23,19 @@ opwalk(opmap, a) = walk(opmap, identity, a)
2323argwalk (argmap, a) = walk (identity, argmap, a)
2424
2525# Generic lazy functionality.
26- using DerivableInterfaces: AbstractArrayInterface, InterfaceFunction
27- struct LazyInterface{N} <: AbstractArrayInterface{N} end
28- LazyInterface () = LazyInterface {Any} ()
29- LazyInterface (:: Val{N} ) where {N} = LazyInterface {N} ()
30- LazyInterface {M} (:: Val{N} ) where {M, N} = LazyInterface {N} ()
31- const lazy_interface = LazyInterface ()
26+ using FunctionImplementations: AbstractArrayStyle
27+ struct LazyStyle <: AbstractArrayStyle end
28+ const lazy_style = LazyStyle ()
3229
33- const maketerm_lazy = lazy_interface (maketerm)
30+ const maketerm_lazy = lazy_style (maketerm)
3431function maketerm_lazy (type:: Type , head, args, metadata)
3532 if head ≡ *
3633 return type (maketerm (Mul, head, args, metadata))
3734 else
3835 return error (" Only mul supported right now." )
3936 end
4037end
41- const getindex_lazy = lazy_interface (getindex)
38+ const getindex_lazy = lazy_style (getindex)
4239function getindex_lazy (a:: AbstractArray , I... )
4340 u = unwrap (a)
4441 if ! iscall (u)
@@ -47,7 +44,7 @@ function getindex_lazy(a::AbstractArray, I...)
4744 return error (" Indexing into expression not supported." )
4845 end
4946end
50- const arguments_lazy = lazy_interface (arguments)
47+ const arguments_lazy = lazy_style (arguments)
5148function arguments_lazy (a)
5249 u = unwrap (a)
5350 if ! iscall (u)
@@ -59,17 +56,17 @@ function arguments_lazy(a)
5956 end
6057end
6158using TermInterface: children
62- const children_lazy = lazy_interface (children)
59+ const children_lazy = lazy_style (children)
6360children_lazy (a) = arguments (a)
6461using TermInterface: head
65- const head_lazy = lazy_interface (head)
62+ const head_lazy = lazy_style (head)
6663head_lazy (a) = operation (a)
67- const iscall_lazy = lazy_interface (iscall)
64+ const iscall_lazy = lazy_style (iscall)
6865iscall_lazy (a) = iscall (unwrap (a))
6966using TermInterface: isexpr
70- const isexpr_lazy = lazy_interface (isexpr)
67+ const isexpr_lazy = lazy_style (isexpr)
7168isexpr_lazy (a) = iscall (a)
72- const operation_lazy = lazy_interface (operation)
69+ const operation_lazy = lazy_style (operation)
7370function operation_lazy (a)
7471 u = unwrap (a)
7572 if ! iscall (u)
@@ -80,7 +77,7 @@ function operation_lazy(a)
8077 return error (" Variant not supported." )
8178 end
8279end
83- const sorted_arguments_lazy = lazy_interface (sorted_arguments)
80+ const sorted_arguments_lazy = lazy_style (sorted_arguments)
8481function sorted_arguments_lazy (a)
8582 u = unwrap (a)
8683 if ! iscall (u)
@@ -92,12 +89,12 @@ function sorted_arguments_lazy(a)
9289 end
9390end
9491using TermInterface: sorted_children
95- const sorted_children_lazy = lazy_interface (sorted_children)
92+ const sorted_children_lazy = lazy_style (sorted_children)
9693sorted_children_lazy (a) = sorted_arguments (a)
97- const ismul_lazy = lazy_interface (ismul)
94+ const ismul_lazy = lazy_style (ismul)
9895ismul_lazy (a) = ismul (unwrap (a))
9996using AbstractTrees: AbstractTrees
100- const abstracttrees_children_lazy = lazy_interface (AbstractTrees. children)
97+ const abstracttrees_children_lazy = lazy_style (AbstractTrees. children)
10198function abstracttrees_children_lazy (a)
10299 if ! iscall (a)
103100 return ()
@@ -106,7 +103,7 @@ function abstracttrees_children_lazy(a)
106103 end
107104end
108105using AbstractTrees: nodevalue
109- const nodevalue_lazy = lazy_interface (nodevalue)
106+ const nodevalue_lazy = lazy_style (nodevalue)
110107function nodevalue_lazy (a)
111108 if ! iscall (a)
112109 return unwrap (a)
@@ -115,11 +112,11 @@ function nodevalue_lazy(a)
115112 end
116113end
117114using Base. Broadcast: materialize
118- const materialize_lazy = lazy_interface (materialize)
115+ const materialize_lazy = lazy_style (materialize)
119116materialize_lazy (a) = argwalk (unwrap, a)
120- const copy_lazy = lazy_interface (copy)
117+ const copy_lazy = lazy_style (copy)
121118copy_lazy (a) = materialize (a)
122- const equals_lazy = lazy_interface (== )
119+ const equals_lazy = lazy_style (== )
123120function equals_lazy (a1, a2)
124121 u1, u2 = unwrap .((a1, a2))
125122 if ! iscall (u1) && ! iscall (u2)
@@ -130,7 +127,7 @@ function equals_lazy(a1, a2)
130127 return false
131128 end
132129end
133- const isequal_lazy = lazy_interface (isequal)
130+ const isequal_lazy = lazy_style (isequal)
134131function isequal_lazy (a1, a2)
135132 u1, u2 = unwrap .((a1, a2))
136133 if ! iscall (u1) && ! iscall (u2)
@@ -141,13 +138,13 @@ function isequal_lazy(a1, a2)
141138 return false
142139 end
143140end
144- const hash_lazy = lazy_interface (hash)
141+ const hash_lazy = lazy_style (hash)
145142function hash_lazy (a, h:: UInt64 )
146143 h = hash (Symbol (unspecify_type_parameters (typeof (a))), h)
147144 # Use `_hash`, which defines a custom hash for NamedDimsArray.
148145 return _hash (unwrap (a), h)
149146end
150- const map_arguments_lazy = lazy_interface (map_arguments)
147+ const map_arguments_lazy = lazy_style (map_arguments)
151148function map_arguments_lazy (f, a)
152149 u = unwrap (a)
153150 if ! iscall (u)
@@ -159,21 +156,21 @@ function map_arguments_lazy(f, a)
159156 end
160157end
161158function substitute end
162- const substitute_lazy = lazy_interface (substitute)
159+ const substitute_lazy = lazy_style (substitute)
163160function substitute_lazy (a, substitutions:: AbstractDict )
164161 haskey (substitutions, a) && return substitutions[a]
165162 ! iscall (a) && return a
166163 return map_arguments (arg -> substitute (arg, substitutions), a)
167164end
168165substitute_lazy (a, substitutions) = substitute (a, Dict (substitutions))
169166using AbstractTrees: printnode
170- const printnode_lazy = lazy_interface (printnode)
167+ const printnode_lazy = lazy_style (printnode)
171168function printnode_lazy (io, a)
172169 # Use `printnode_nameddims` to avoid type piracy,
173170 # since it overloads on `AbstractNamedDimsArray`.
174171 return printnode_nameddims (io, unwrap (a))
175172end
176- const show_lazy = lazy_interface (show)
173+ const show_lazy = lazy_style (show)
177174function show_lazy (io:: IO , a)
178175 if ! iscall (a)
179176 return show (io, unwrap (a))
@@ -187,12 +184,12 @@ function show_lazy(io::IO, mime::MIME"text/plain", a)
187184 ! iscall (a) ? show (io, mime, unwrap (a)) : show (io, a)
188185 return nothing
189186end
190- const add_lazy = lazy_interface (+ )
187+ const add_lazy = lazy_style (+ )
191188add_lazy (a1, a2) = error (" Not implemented." )
192- const sub_lazy = lazy_interface (- )
189+ const sub_lazy = lazy_style (- )
193190sub_lazy (a) = error (" Not implemented." )
194191sub_lazy (a1, a2) = error (" Not implemented." )
195- const mul_lazy = lazy_interface (* )
192+ const mul_lazy = lazy_style (* )
196193function mul_lazy (a)
197194 u = unwrap (a)
198195 if ! iscall (u)
@@ -216,7 +213,7 @@ mul_lazy(a1::Number, a2::Number) = a1 * a2
216213div_lazy (a1, a2:: Number ) = error (" Not implemented." )
217214
218215# NamedDimsArrays.jl interface.
219- const inds_lazy = lazy_interface (inds)
216+ const inds_lazy = lazy_style (inds)
220217function inds_lazy (a)
221218 u = unwrap (a)
222219 if ! iscall (u)
@@ -227,7 +224,7 @@ function inds_lazy(a)
227224 return error (" Variant not supported." )
228225 end
229226end
230- const dename_lazy = lazy_interface (dename)
227+ const dename_lazy = lazy_style (dename)
231228function dename_lazy (a)
232229 u = unwrap (a)
233230 if ! iscall (u)
0 commit comments