File tree Expand file tree Collapse file tree 3 files changed +33
-26
lines changed
Expand file tree Collapse file tree 3 files changed +33
-26
lines changed Original file line number Diff line number Diff line change 11name = " IntervalLinearAlgebra"
22uuid = " 92cbe1ac-9c24-436b-b0c9-5f7317aedcd5"
33authors = [" Luca Ferranti" ]
4- version = " 0.1.4 "
4+ version = " 0.1.5 "
55
66[deps ]
77CommonSolve = " 38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
Original file line number Diff line number Diff line change 8888
8989(ae:: AffineExpression )(p:: Vector{<:Number} ) = dot (ae. coeffs[1 : end - 1 ], p) + ae. coeffs[end ]
9090
91- # # printing
92- function _tostring (ae:: AffineExpression )
93- iszero (ae. coeffs) && return " 0"
94- str = " "
95- @inbounds for (i, x) in enumerate (_vars_dict[:vars ])
96- c = ae. coeffs[i]
97- iszero (c) && continue
98- sgn = c > 0 ? " +" : " -"
99- c = abs (c) == 1 ? " " : " $(abs (c)) "
100- str *= sgn * c * " $(x) "
101- end
102-
103- c = last (ae. coeffs)
104- if ! iszero (c)
105- sgn = c > 0 ? " +" : " "
106- str *= sgn * " $(c) "
91+ function show (io:: IO , ae:: AffineExpression )
92+ first_printed = false
93+ if iszero (ae. coeffs)
94+ print (io, 0 )
95+ else
96+ @inbounds for (i, x) in enumerate (_vars_dict[:vars ])
97+ c = ae. coeffs[i]
98+ iszero (c) && continue
99+ if c > 0
100+ if first_printed
101+ print (io, " +" )
102+ end
103+ else
104+ print (io, " -" )
105+ end
106+ if abs (c) != 1
107+ print (io, abs (c))
108+ end
109+ print (io, x)
110+ first_printed = true
111+ end
112+
113+ c = last (ae. coeffs)
114+ if ! iszero (c)
115+ if c > 0 && first_printed
116+ print (io, " +" )
117+ end
118+ print (io, c)
119+ end
107120 end
108- str = (str[1 ] == ' +' ? str[2 : end ] : str)
109- return str
110121end
111122
112- show (io:: IO , ae:: AffineExpression ) = print (io, _tostring (ae))
113-
114-
115123# ########################
116124# BASIC FUNCTIONS #
117125# ########################
Original file line number Diff line number Diff line change 2525 @affinevars x y z
2626
2727 p1 = x - y + 3 z
28- @test IntervalLinearAlgebra . _tostring (p1) == " x-y+3z"
28+ @test string (p1) == " x-y+3z"
2929 p2 = y + x - z - 2
30- @test IntervalLinearAlgebra. _tostring (p2) == " x+y-z-2"
31- @test IntervalLinearAlgebra. _tostring (p1 - p1) == " 0"
32-
30+ @test string (p2) == " x+y-z-2"
31+ @test string (p1 - p1) == " 0"
3332 @test + p1 == p1
3433 @test - p1 == - x + y - 3 z
3534 @test p2 ([1 , 1 , 1 ]) == - 1
You can’t perform that action at this time.
0 commit comments