Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Rui Vieira
mentat
Commits
a32794fd
Commit
a32794fd
authored
Mar 29, 2019
by
Rui Vieira
🍵
Browse files
Move function currying to Spline class
parent
34a912a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
src/lib.rs
src/lib.rs
+15
-7
No files found.
src/lib.rs
View file @
a32794fd
...
...
@@ -82,13 +82,13 @@ impl MonotonicCubicSpline {
slopes
[
i
]
=
0.0
;
slopes
[
i
+
1
]
=
0.0
;
}
else
{
let
a
=
slopes
[
i
]
/
secants
[
i
];
let
b
=
slopes
[
i
+
1
]
/
secants
[
i
];
let
h
=
a
.hypot
(
b
);
let
a
lpha
=
slopes
[
i
]
/
secants
[
i
];
let
b
eta
=
slopes
[
i
+
1
]
/
secants
[
i
];
let
h
=
alph
a
.hypot
(
b
eta
);
if
h
>
9.0
{
let
t
=
3.0
/
h
;
slopes
[
i
]
=
t
*
a
*
secants
[
i
];
slopes
[
i
+
1
]
=
t
*
b
*
secants
[
i
];
slopes
[
i
]
=
t
*
a
lpha
*
secants
[
i
];
slopes
[
i
+
1
]
=
t
*
b
eta
*
secants
[
i
];
}
}
}
...
...
@@ -132,6 +132,13 @@ impl MonotonicCubicSpline {
(
*
self
.m_m
.get
(
i
)
.unwrap
(),
*
self
.m_m
.get
(
i
+
1
)
.unwrap
()));
}
fn
curry
(
x
:
Vec
<
f64
>
,
y
:
Vec
<
f64
>
)
->
impl
Fn
(
f64
)
->
f64
{
move
|
p
|
{
let
mut
spline
=
MonotonicCubicSpline
::
new
(
&
x
,
&
y
);
spline
.interpolate
(
p
)
}
}
}
#[cfg(test)]
...
...
@@ -163,6 +170,7 @@ mod test_normal {
assert_delta!
(
0.3989423
,
_
pdf
,
1e-5
);
}
#[test]
fn
interpolation
()
{
use
matplotrust
::
*
;
...
...
@@ -170,14 +178,14 @@ mod test_normal {
let
x
=
vec!
[
0.0
,
2.0
,
3.0
,
10.0
];
let
y
=
vec!
[
1.0
,
4.0
,
8.0
,
10.5
];
let
mut
spline
=
MonotonicCubicSpline
::
new
(
&
x
,
&
y
);
let
smooth
=
MonotonicCubicSpline
::
curry
(
x
.clone
(),
y
.clone
()
);
let
mut
x_interp
=
Vec
::
new
();
let
mut
y_interp
=
Vec
::
new
();
for
i
in
0
..
100
{
let
p
=
i
as
f64
/
10.0
;
x_interp
.push
(
p
);
y_interp
.push
(
s
pline
.interpolate
(
p
));
y_interp
.push
(
s
mooth
(
p
));
}
let
mut
figure
=
Figure
::
new
();
let
points
=
scatter_plot
::
<
f64
,
f64
>
(
x
,
y
,
None
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment