@@ -54,6 +54,11 @@ Base.isequal(::Variable , ::Operation) = false
54
54
Base. isequal (:: Operation , :: Constant ) = false
55
55
Base. isequal (:: Constant , :: Operation ) = false
56
56
57
+ # provide iszero for Operations to help sparse addition and multiplication
58
+ Base. iszero (O:: Operation ) = ((O. op == identity) && iszero (O. args[1 ])) ||
59
+ ((O. op == + ) && all (iszero (arg) for arg in O. args)) ||
60
+ ((O. op == * ) && any (iszero (arg) for arg in O. args))
61
+
57
62
Base. show (io:: IO , O:: Operation ) = print (io, convert (Expr, O))
58
63
59
64
# For inv
@@ -73,12 +78,4 @@ Base.convert(::Type{Expr},x::Operation) = Expr(x)
73
78
Base. promote_rule (:: Type{<:Constant} , :: Type{<:Operation} ) = Operation
74
79
Base. promote_rule (:: Type{<:Operation} , :: Type{<:Constant} ) = Operation
75
80
76
- # Fix Sparse MatMul
77
- Base.:* (A:: SparseMatrixCSC{Operation,S} , x:: StridedVector{Operation} ) where {S} =
78
- (T = Operation; mul! (similar (x, T, A. m), A, x, true , false ))
79
- Base.:* (A:: SparseMatrixCSC{Tx,S} , x:: StridedVector{Operation} ) where {Tx,S} =
80
- (T = LinearAlgebra. promote_op (LinearAlgebra. matprod, Operation, Tx); mul! (similar (x, T, A. m), A, x, true , false ))
81
- Base.:* (A:: SparseMatrixCSC{Operation,S} , x:: StridedVector{Tx} ) where {Tx,S} =
82
- (T = LinearAlgebra. promote_op (LinearAlgebra. matprod, Operation, Tx); mul! (similar (x, T, A. m), A, x, true , false ))
83
-
84
81
LinearAlgebra. lu (O:: AbstractMatrix{<:Operation} ;kwargs... ) = lu (O,Val (false );kwargs... )
0 commit comments