Skip to content

Commit 4f8fb79

Browse files
committed
Rename NonStdCon -> ElementWise
1 parent 686630e commit 4f8fb79

1 file changed

Lines changed: 13 additions & 22 deletions

File tree

src/std.jl

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,17 @@ end
212212

213213
# This type is for tagging contractions that need special treatment before converting to
214214
# standard notation (if at all possible).
215-
struct NonStdCon end
215+
struct ElementWise end
216216

217-
function get_indices(arg::BinaryOperation{NonStdCon})
217+
function get_indices(arg::BinaryOperation{ElementWise})
218218
return [get_indices(arg.arg1); get_indices(arg.arg2)]
219219
end
220220

221-
function to_string(arg::BinaryOperation{NonStdCon})
221+
function to_string(arg::BinaryOperation{ElementWise})
222222
return parenthesize(arg.arg1) * parenthesize(arg.arg2)
223223
end
224224

225-
function evaluate(arg::BinaryOperation{NonStdCon})
225+
function evaluate(arg::BinaryOperation{ElementWise})
226226
return arg
227227
end
228228

@@ -370,7 +370,7 @@ function add_contracting_factor_ordered(factor, ordered_factors)
370370
end
371371

372372
function _to_std_string(arg::BinaryOperation{Mult})
373-
factors = group_non_std_factors(arg)
373+
factors = group_element_wise_products(arg)
374374
factors = Any[f for f factors]
375375

376376
ordered_factors = []
@@ -449,7 +449,7 @@ function _to_std_string(arg::BinaryOperation{Pow})
449449
return parenthesize_std(arg.arg1) * script(Upper(arg.arg2))
450450
end
451451

452-
function _to_std_string(arg::BinaryOperation{NonStdCon})
452+
function _to_std_string(arg::BinaryOperation{ElementWise})
453453
indices = get_indices(arg)
454454
target_indices = unique(eliminate_indices(indices))
455455
terms = collect_factors(arg)
@@ -538,11 +538,11 @@ function parenthesize_std(arg::BinaryOperation{Op}) where {Op<:AdditiveOperation
538538
return "(" * _to_std_string(arg) * ")"
539539
end
540540

541-
function parenthesize_std(arg::BinaryOperation{NonStdCon})
541+
function parenthesize_std(arg::BinaryOperation{ElementWise})
542542
return "(" * _to_std_string(arg) * ")"
543543
end
544544

545-
function collect_factors(arg::BinaryOperation{NonStdCon})
545+
function collect_factors(arg::BinaryOperation{ElementWise})
546546
return [collect_factors(arg.arg1); collect_factors(arg.arg2)]
547547
end
548548

@@ -691,7 +691,7 @@ function was_flipped(index, flips)
691691
return false
692692
end
693693

694-
# TODO: Constrain to Mult and NonStdCon
694+
# TODO: Constrain to Mult and ElementWise
695695
function to_binary_operation(op::Op, terms::AbstractArray) where {Op}
696696
binop = nothing
697697

@@ -832,15 +832,15 @@ function group_factors(factors::AbstractArray)
832832
return chunked_factors
833833
end
834834

835-
function group_non_std_factors(arg::BinaryOperation{Mult})
835+
function group_element_wise_products(arg::BinaryOperation{Mult})
836836
factors = collect_factors(arg)
837837
factors = map(evaluate, factors) # recursion
838838

839839
grouped_factors = group_factors(factors)
840840

841841
for i eachindex(grouped_factors)
842842
if grouped_factors[i] isa AbstractArray
843-
grouped_factors[i] = to_binary_operation(NonStdCon(), grouped_factors[i])
843+
grouped_factors[i] = to_binary_operation(ElementWise(), grouped_factors[i])
844844
end
845845
end
846846

@@ -920,18 +920,9 @@ function to_standard(arg::BinaryOperation{Mult})
920920
throw_not_std()
921921
end
922922

923-
terms = group_non_std_factors(term)
923+
terms = group_element_wise_products(term)
924924

925-
standardized_term = nothing
926-
927-
for t terms
928-
if isnothing(standardized_term)
929-
standardized_term = t
930-
continue
931-
end
932-
933-
standardized_term = BinaryOperation{Mult}(standardized_term, t)
934-
end
925+
standardized_term = to_binary_operation(Mult(), terms)
935926

936927
ordered_expr_ids = get_free_indices(standardized_term)
937928

0 commit comments

Comments
 (0)