@@ -53,13 +53,13 @@ function safe_get_units(term, info)
53
53
side
54
54
end
55
55
56
- function _validate (terms:: Vector ,labels:: Vector ; info:: String = " " )
57
- equnits = safe_get_units .(terms,info.* labels)
58
- allthere = all (map (x-> x!= = nothing ,equnits))
56
+ function _validate (terms:: Vector , labels:: Vector ; info:: String = " " )
57
+ equnits = safe_get_units .(terms, info* " , " .* labels)
58
+ allthere = all (map (x -> x!= = nothing , equnits))
59
59
allmatching = true
60
60
if allthere
61
61
for idx in 2 : length (equnits)
62
- if ! isequal (equnits[1 ],equnits[idx])
62
+ if ! isequal (equnits[1 ], equnits[idx])
63
63
allmatching = false
64
64
@warn (" $info : units $(equnits[1 ]) for $(labels[1 ]) and $(equnits[idx]) for $(labels[idx]) do not match." )
65
65
end
70
70
71
71
function validate (eq:: ModelingToolkit.Equation ; info:: String = " " )
72
72
labels = [" left-hand side" , " right-hand side" ]
73
- terms = [eq. lhs,eq. rhs]
74
- _validate (terms,labels,info = info)
73
+ terms = [eq. lhs, eq. rhs]
74
+ _validate (terms, labels, info = info)
75
75
end
76
76
77
- function validate (eq:: ModelingToolkit.Equation ,noiseterm; info:: String = " " )
78
- labels = [" left-hand side" , " right-hand side" ," noise term" ]
79
- terms = [eq. lhs,eq. rhs,noiseterm]
80
- _validate (terms,labels,info = info)
77
+ function validate (eq:: ModelingToolkit.Equation , noiseterm; info:: String = " " )
78
+ labels = [" left-hand side" , " right-hand side" , " noise term" ]
79
+ terms = [eq. lhs, eq. rhs, noiseterm]
80
+ _validate (terms, labels, info = info)
81
81
end
82
82
83
- function validate (eq:: ModelingToolkit.Equation ,noisevec:: Vector ; info:: String = " " )
84
- labels = vcat ([" left-hand side" , " right-hand side" ]," noise term #" .* string .(1 : length (noisevec)))
85
- terms = vcat ([eq. lhs,eq. rhs],noisevec)
86
- _validate (terms,labels,info = info)
83
+ function validate (eq:: ModelingToolkit.Equation , noisevec:: Vector ; info:: String = " " )
84
+ labels = vcat ([" left-hand side" , " right-hand side" ], " noise term #" .* string .(1 : length (noisevec)))
85
+ terms = vcat ([eq. lhs, eq. rhs], noisevec)
86
+ _validate (terms, labels, info = info)
87
87
end
88
88
89
89
function validate (eqs:: Vector{ModelingToolkit.Equation} )
90
- all ([validate (eqs[idx],info = " In eq. #$idx " ) for idx in 1 : length (eqs)])
90
+ all ([validate (eqs[idx], info = " In eq. #$idx " ) for idx in 1 : length (eqs)])
91
91
end
92
92
93
- function validate (eqs:: Vector{ModelingToolkit.Equation} ,noise:: Vector )
94
- all ([validate (eqs[idx],noise[idx],info = " In eq. #$idx " ) for idx in 1 : length (eqs)])
93
+ function validate (eqs:: Vector{ModelingToolkit.Equation} , noise:: Vector )
94
+ all ([validate (eqs[idx], noise[idx], info = " In eq. #$idx " ) for idx in 1 : length (eqs)])
95
95
end
96
96
97
- function validate (eqs:: Vector{ModelingToolkit.Equation} ,noise:: Matrix )
98
- all ([validate (eqs[idx],noise[idx,:],info = " In eq. #$idx " ) for idx in 1 : length (eqs)])
97
+ function validate (eqs:: Vector{ModelingToolkit.Equation} , noise:: Matrix )
98
+ all ([validate (eqs[idx], noise[idx, :], info = " In eq. #$idx " ) for idx in 1 : length (eqs)])
99
99
end
100
100
101
101
" Returns true iff units of equations are valid."
102
- validate (eqs:: Vector ) = validate (convert .(ModelingToolkit. Equation,eqs))
102
+ validate (eqs:: Vector ) = validate (convert .(ModelingToolkit. Equation, eqs))
103
103
104
104
" Throws error if units of equations are invalid."
105
105
check_units (eqs... ) = validate (eqs... ) || throw (ArgumentError (" Some equations had invalid units. See warnings for details." ))
0 commit comments