Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Muninn
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
Model registry
Operate
Environments
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
Sarah Renkhoff
Muninn
Commits
1b92f901
Commit
1b92f901
authored
3 years ago
by
Sarah Renkhoff
Browse files
Options
Downloads
Patches
Plain Diff
Added some low-level parallelization using rayon
parent
9b53b77e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plotting.rs
+16
-22
16 additions, 22 deletions
src/plotting.rs
with
16 additions
and
22 deletions
src/plotting.rs
+
16
−
22
View file @
1b92f901
use
crate
::
data
::{
DataSlice
,
Point
};
use
plotters
::
prelude
::
*
;
use
rayon
::
prelude
::
*
;
pub
type
Range
=
(
f64
,
f64
);
...
...
@@ -180,18 +181,18 @@ pub fn plot_data_slice_to_svg(data_slice: &DataSlice, plot_settings: &PlotSettin
let
mut
xmins
=
Vec
::
new
();
for
series
in
data
{
if
!
series
.is_empty
()
{
xmaxs
.push
(
series
.iter
()
.max_by
(|(
x1
,
_
),(
x2
,
_
)|
x1
.partial_cmp
(
x2
)
.unwrap
())
.unwrap
()
.0
);
xmins
.push
(
series
.iter
()
.min_by
(|(
x1
,
_
),(
x2
,
_
)|
x1
.partial_cmp
(
x2
)
.unwrap
())
.unwrap
()
.0
);
xmaxs
.push
(
series
.
par_
iter
()
.max_by
(|(
x1
,
_
),(
x2
,
_
)|
x1
.partial_cmp
(
x2
)
.unwrap
())
.unwrap
()
.0
);
xmins
.push
(
series
.
par_
iter
()
.min_by
(|(
x1
,
_
),(
x2
,
_
)|
x1
.partial_cmp
(
x2
)
.unwrap
())
.unwrap
()
.0
);
}
}
let
mut
xmin
=
if
!
xmins
.is_empty
()
{
*
xmins
.iter
()
.min_by
(|
x
,
y
|
x
.partial_cmp
(
y
)
.unwrap
())
.unwrap
()
*
xmins
.
par_
iter
()
.min_by
(|
x
,
y
|
x
.partial_cmp
(
y
)
.unwrap
())
.unwrap
()
}
else
{
0.0
};
let
mut
xmax
=
if
!
xmaxs
.is_empty
()
{
*
xmaxs
.iter
()
.max_by
(|
x
,
y
|
x
.partial_cmp
(
y
)
.unwrap
())
.unwrap
()
*
xmaxs
.
par_
iter
()
.max_by
(|
x
,
y
|
x
.partial_cmp
(
y
)
.unwrap
())
.unwrap
()
}
else
{
0.0
};
...
...
@@ -226,12 +227,12 @@ pub fn plot_data_slice_to_svg(data_slice: &DataSlice, plot_settings: &PlotSettin
}
let
mut
ymin
=
if
!
points
.is_empty
()
{
points
.iter
()
.min_by
(|(
_
,
y1
),(
_
,
y2
)|
y1
.partial_cmp
(
y2
)
.unwrap
())
.unwrap
()
.1
points
.
par_
iter
()
.min_by
(|(
_
,
y1
),(
_
,
y2
)|
y1
.partial_cmp
(
y2
)
.unwrap
())
.unwrap
()
.1
}
else
{
0.0
};
let
mut
ymax
=
if
!
points
.is_empty
()
{
points
.iter
()
.max_by
(|(
_
,
y1
),(
_
,
y2
)|
y1
.partial_cmp
(
y2
)
.unwrap
())
.unwrap
()
.1
points
.
par_
iter
()
.max_by
(|(
_
,
y1
),(
_
,
y2
)|
y1
.partial_cmp
(
y2
)
.unwrap
())
.unwrap
()
.1
}
else
{
0.0
};
...
...
@@ -273,23 +274,16 @@ pub fn plot_data_slice_to_svg(data_slice: &DataSlice, plot_settings: &PlotSettin
// For line series: Move last and first points along connecting lines
// to coincide with plotting area border
let
mut
point_data
:
Vec
<
Vec
<
Point
>>
=
Vec
::
new
();
if
plot_settings
.draw_points
{
for
line
in
data
{
let
filtered_line
:
Vec
<
Point
>
=
line
.iter
()
.filter
(|(
x
,
y
)|
{
*
x
>=
xmin
&&
*
x
<=
xmax
&&
*
y
>=
ymin
&&
*
y
<=
ymax
})
.copied
()
.collect
();
point_data
.push
(
filtered_line
);
}
}
let
point_data
:
Vec
<
Vec
<
Point
>>
=
data
.par_iter
()
.map
(|
line
|
{
line
.par_iter
()
.filter
(|(
x
,
y
)|
{
*
x
>=
xmin
&&
*
x
<=
xmax
&&
*
y
>=
ymin
&&
*
y
<=
ymax
})
.copied
()
.collect
()
})
.collect
();
let
mut
line_data
:
Vec
<
Vec
<
Vec
<
Point
>>>
=
Vec
::
new
();
if
plot_settings
.draw_lines
{
for
line
in
data
.iter
()
{
let
filtered_line
=
truncate_line
(
&
line
,
&
(
xmin
,
xmax
),
&
(
ymin
,
ymax
));
line_data
.push
(
filtered_line
);
}
}
// Line data is another vec deeper because the filtering may turn one dataline into several, all of which should have the same color
let
line_data
:
Vec
<
Vec
<
Vec
<
Point
>>>
=
data
.par_iter
()
.map
(|
line
|
{
truncate_line
(
&
line
,
&
(
xmin
,
xmax
),
&
(
ymin
,
ymax
))
})
.collect
();
let
x_range
=
xmin
..
xmax
;
let
y_range
=
ymin
..
ymax
;
...
...
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