Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MRIBuilder.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
MRIBuilder.jl
Commits
4e90a823
Verified
Commit
4e90a823
authored
1 year ago
by
Michiel Cottaar
Browse files
Options
Downloads
Patches
Plain Diff
pretty print numeric values
parent
2056639f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/building_blocks.jl
+20
-7
20 additions, 7 deletions
src/building_blocks.jl
with
20 additions
and
7 deletions
src/building_blocks.jl
+
20
−
7
View file @
4e90a823
...
...
@@ -2,7 +2,7 @@ module BuildingBlocks
import
JuMP
:
has_values
,
value
,
Model
,
@constraint
,
@objective
,
owner_model
,
objective_function
,
optimize!
,
AbstractJuMPScalar
import
Printf
:
@sprintf
import
..
Scanners
:
Scanner
import
..
Variables
:
variables
,
start_time
,
duration
,
end_time
,
gradient_strength
,
slew_rate
,
effective_time
import
..
Variables
:
variables
,
start_time
,
duration
,
end_time
,
gradient_strength
,
slew_rate
,
effective_time
,
VariableType
"""
Parent type for all individual components out of which a sequence can be built.
...
...
@@ -151,7 +151,7 @@ end
Base
.
show
(
io
::
IO
,
block
::
BuildingBlock
)
=
print
(
io
,
BuildingBlockPrinter
(
block
,
nothing
,
0
))
function
_robust_value
(
possible_number
)
function
_robust_value
(
possible_number
::
VariableType
)
try
return
value
(
possible_number
)
catch
...
...
@@ -159,6 +159,8 @@ function _robust_value(possible_number)
end
end
_robust_value
(
possible_vector
::
AbstractVector
)
=
_robust_value
.
(
possible_vector
)
function
Base.show
(
io
::
IO
,
printer
::
BuildingBlockPrinter
)
block
=
printer
.
bb
print
(
io
,
string
(
typeof
(
block
)),
"("
)
...
...
@@ -168,6 +170,7 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
print
(
io
,
"t="
,
@sprintf
(
"%.3g"
,
printer
.
start_time
))
dur
=
_robust_value
(
duration
(
block
))
@assert
!
(
dur
isa
AbstractVector
)
if
!
isnothing
(
dur
)
&&
!
iszero
(
dur
)
print
(
io
,
"-"
,
@sprintf
(
"%.3g"
,
printer
.
start_time
+
dur
))
printed_duration
=
true
...
...
@@ -176,7 +179,14 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
end
for
name
in
propertynames
(
block
)
value
=
getproperty
(
block
,
name
)
if
name
in
variable_names
||
value
isa
Model
||
value
isa
BuildingBlock
||
string
(
name
)[
1
]
==
'_'
if
(
name
in
variable_names
||
value
isa
AbstractJuMPScalar
||
(
value
isa
AbstractVector
&&
eltype
(
value
)
isa
AbstractJuMPScalar
)
||
value
isa
Model
||
value
isa
BuildingBlock
||
string
(
name
)[
1
]
==
'_'
)
continue
end
print
(
io
,
name
,
"="
,
repr
(
value
),
", "
)
...
...
@@ -190,7 +200,11 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
if
isnothing
(
numeric_value
)
continue
end
printed_value
=
@sprintf
(
"%.3g"
,
numeric_value
)
if
numeric_value
isa
AbstractVector
printed_value
=
"["
*
join
(
map
(
v
->
@sprintf
(
"%.3g"
,
v
),
numeric_value
),
", "
)
*
"]"
else
printed_value
=
@sprintf
(
"%.3g"
,
numeric_value
)
end
print
(
io
,
"
$
(nameof(fn))=
$(printed_value)
, "
)
end
print
(
io
,
")"
)
...
...
@@ -199,13 +213,12 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
use_start_time
=
isnothing
(
printer
.
start_time
)
?
0.
:
printer
.
start_time
print
(
io
,
":"
)
for
(
child_index
,
child_block
)
in
get_children_blocks
(
block
)
print
(
io
,
child_index
,
": "
)
child_printer
=
BuildingBlockPrinter
(
child_block
,
child_index
,
child_block
,
_robust_value
(
start_time
(
block
,
child_index
)
+
use_start_time
),
printer
.
spaces
+
2
)
print
(
io
,
"
\n
"
,
repeat
(
' '
,
printer
.
spaces
)
,
child_printer
)
print
(
io
,
"
\n
"
,
repeat
(
' '
,
printer
.
spaces
+
2
),
"- "
,
child_index
,
": "
,
child_printer
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment