Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goertzel-nostd
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
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
Stephen D
goertzel-nostd
Merge requests
!1
use iterator for input
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
use iterator for input
iterator
into
master
Overview
0
Commits
2
Pipelines
3
Changes
2
Merged
Stephen D
requested to merge
iterator
into
master
1 year ago
Overview
0
Commits
2
Pipelines
3
Changes
2
Expand
0
0
Merge request reports
Compare
master
version 2
fe41702f
1 year ago
version 1
03169200
1 year ago
master (base)
and
latest version
latest version
31dec325
2 commits,
1 year ago
version 2
fe41702f
1 commit,
1 year ago
version 1
03169200
1 commit,
1 year ago
2 files
+
14
−
13
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/lib.rs
+
13
−
12
Options
@@ -4,7 +4,7 @@
// allow std in tests
#![cfg_attr(not(test),
no_std)]
use
core
::
f32
::
consts
::
PI
;
use
core
::
{
borrow
::
Borrow
,
f32
::
consts
::
PI
}
;
/// Set up parameters (and some precomputed values for those).
#[derive(Clone,
Copy)]
@@ -46,23 +46,24 @@ impl Parameters {
}
}
pub
fn
mag
(
self
,
samples
:
&
[
f32
]
)
->
f32
{
pub
fn
mag
<
V
:
Borrow
<
f32
>
,
I
:
Iterator
<
Item
=
V
>>
(
self
,
samples
:
I
)
->
f32
{
self
.start
()
.add_samples
(
samples
)
.finish_mag
()
}
pub
fn
mag_squared
(
self
,
samples
:
&
[
f32
]
)
->
f32
{
pub
fn
mag_squared
<
V
:
Borrow
<
f32
>
,
I
:
Iterator
<
Item
=
V
>>
(
self
,
samples
:
I
)
->
f32
{
self
.start
()
.add_samples
(
samples
)
.finish_mag_squared
()
}
}
impl
Partial
{
pub
fn
add_samples
(
mut
self
,
samples
:
&
[
f32
]
)
->
Self
{
for
&
sample
in
samples
{
let
this
=
self
.params.term_coefficient
*
self
.prev
-
self
.prevprev
+
sample
;
pub
fn
add_samples
<
V
:
Borrow
<
f32
>
,
I
:
Iterator
<
Item
=
V
>>
(
mut
self
,
samples
:
I
)
->
Self
{
for
sample
in
samples
{
let
this
=
self
.params.term_coefficient
*
self
.prev
-
self
.prevprev
+
sample
.borrow
()
;
self
.prevprev
=
self
.prev
;
self
.prev
=
this
;
self
.count
+=
1
;
}
self
.count
+=
samples
.len
();
self
}
pub
fn
finish
(
self
)
->
(
f32
,
f32
)
{
@@ -85,11 +86,11 @@ impl Partial {
#[test]
fn
zero_data
()
{
let
p
=
Parameters
::
new
(
1800.
,
8000
,
256
);
assert!
(
p
.start
()
.add_samples
(
&
[
0.0
;
256
])
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add_samples
([
0.0
;
256
]
.iter
()
)
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add_samples
(
&
[
0.0
;
128
])
.add_samples
(
&
[
0.0
;
128
])
.add_samples
([
0.0
;
128
]
.iter
()
)
.add_samples
([
0.0
;
128
]
.iter
()
)
.finish_mag
()
==
0.
);
@@ -107,10 +108,10 @@ fn sine() {
}
let
p
=
Parameters
::
new
(
freq
,
8000
,
8000
);
let
mag
=
p
.start
()
.add_samples
(
&
buf
[
..
])
.finish_mag
();
let
mag
=
p
.start
()
.add_samples
(
buf
[
..
]
.iter
()
)
.finish_mag
();
for
testfreq
in
(
0
..
30
)
.map
(|
x
|
(
x
*
100
)
as
f32
)
{
let
p
=
Parameters
::
new
(
testfreq
,
8000
,
8000
);
let
testmag
=
p
.mag
(
&
buf
[
..
]);
let
testmag
=
p
.mag
(
buf
[
..
]
.iter
()
);
println!
(
"{testfreq:4}: {testmag:12.3}"
);
if
(
freq
-
testfreq
)
.abs
()
>
100.
{
println!
(
"{mag} > 10*{testmag}"
);
Loading