Skip to content

Commit 91a1e9b

Browse files
committed
added missing file
1 parent 2674d2a commit 91a1e9b

13 files changed

+450
-2
lines changed

.circleci/config.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@ jobs:
66
- image: circleci/python:2.7.14
77
steps:
88
- checkout
9+
- restore_cache:
10+
key: reqs-{{ checksum "requirements.txt" }}
911
- run:
1012
name: "Install Python requirements"
11-
command: pip install --user -Ur requirements.txt
13+
command: |
14+
virtualenv venv
15+
. venv/bin/activate
16+
pip install -Ur requirements.txt
17+
pip install -e .
18+
- save_cache:
19+
key: reqs-{{ checksum "requirements.txt" }}
20+
paths:
21+
- venv
1222
- run:
1323
name: "Run tests"
14-
command: python setup.py test
24+
command: |
25+
. venv/bin/activate
26+
python setup.py test
27+

conftest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Global configuration."""
2+
import os
3+
import inspect
4+
import shutil
5+
6+
import pytest
7+
import matlab2cpp
8+
from matlab2cpp import collection
9+
10+
11+
@pytest.fixture(scope="session")
12+
def workspace_folder(tmpdir_factory):
13+
"""Create a temporary folder to perform tests from."""
14+
return str(tmpdir_factory.mktemp("workspace"))
15+
16+
17+
@pytest.fixture(scope="function", autouse=True)
18+
def workspace(workspace_folder, doctest_namespace):
19+
"""Fill temporary folder for each test."""
20+
# move data to workspace:
21+
source = os.path.join(os.path.dirname(inspect.stack()[0][1]), "test", "data")
22+
if os.path.isdir(workspace_folder):
23+
shutil.rmtree(workspace_folder)
24+
shutil.copytree(source, workspace_folder)
25+
26+
# add content to doctest namespace:
27+
doctest_namespace["workspace"] = workspace_folder
28+
doctest_namespace["matlab2cpp"] = matlab2cpp
29+
doctest_namespace["collection"] = collection
30+
31+
# change to workspace:
32+
curdir = os.path.abspath(os.path.curdir)
33+
os.chdir(workspace_folder)
34+
35+
yield workspace_folder
36+
37+
# clean up:
38+
os.chdir(curdir)
39+
shutil.rmtree(workspace_folder)

src/matlab2cpp/configure/frontend.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
3+
def configure(root, suggest=True, **kws):
4+
"""
5+
configure backend
6+
7+
See also:
8+
:py:func:`matlab2cpp.Builder.configure <Builder.configure>`
9+
"""
10+
from .. import tree
11+
12+
if isinstance(root, tree.Builder):
13+
root = root.project
14+
15+
loop(root, suggest)
16+
loop(root, suggest)
17+
18+
def loop(root, suggest):
19+
from . import datatypes, backends, reserved
20+
21+
nodes = root.flatten(False, True, True)
22+
23+
while True:
24+
25+
# loop and configure
26+
for node in nodes:
27+
28+
# reserved stuff
29+
if node.cls + "_" + node.name in reserved.__dict__:
30+
rule = reserved.__dict__[node.cls+"_"+node.name]
31+
if isinstance(rule, str):
32+
node.type = rule
33+
else:
34+
rule(node)
35+
36+
# Datatype stuff
37+
if node.prop["type"] != "TYPE":
38+
pass
39+
40+
elif node.cls in datatypes.__dict__:
41+
datatype = datatypes.__dict__[node.cls]
42+
if isinstance(datatype, str):
43+
node.type = datatype
44+
else:
45+
datatype(node)
46+
47+
# Backend stuff
48+
if node.backend != "unknown":
49+
pass
50+
51+
elif node.cls in backends.__dict__:
52+
backend = backends.__dict__[node.cls]
53+
if isinstance(backend, str):
54+
node.backend = backend
55+
else:
56+
backend(node)
57+
58+
# determine if done
59+
if suggest:
60+
61+
complete = True
62+
63+
for program in root.project:
64+
65+
suggests = program.suggest
66+
program.stypes = suggests
67+
program.ftypes = suggests
68+
complete = complete and not any([any(v) for v in suggests.values()])
69+
70+
if complete:
71+
break
72+
73+
else:
74+
break
75+
76+
# delete log, if any (create on translate)
77+
for program in root.project:
78+
program[-1].children = []

test/data/function_reference.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef F_M_HPP
2+
#define F_M_HPP
3+
4+
#include <armadillo>
5+
using namespace arma ;
6+
7+
irowvec f(irowvec x) ;
8+
void g() ;
9+
10+
irowvec f(irowvec x)
11+
{
12+
irowvec y ;
13+
y = x+2 ;
14+
return y ;
15+
}
16+
17+
void g()
18+
{
19+
irowvec x, y ;
20+
sword _x [] = {1, 2, 3} ;
21+
x = irowvec(_x, 3, false) ;
22+
y = f(x) ;
23+
}
24+
#endif

test/data/function_reference.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function y=f(x)
2+
y = x+2
3+
end
4+
function g()
5+
x = [1,2,3]
6+
y = f(x)
7+
end

test/data/function_reference_2.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef F_M_HPP
2+
#define F_M_HPP
3+
4+
#include <armadillo>
5+
using namespace arma ;
6+
7+
void f(irowvec a, ivec b, irowvec& y, ivec& z) ;
8+
void g() ;
9+
10+
void f(irowvec a, ivec b, irowvec& y, ivec& z)
11+
{
12+
y = a+2 ;
13+
z = b-3 ;
14+
}
15+
16+
void g()
17+
{
18+
irowvec a, y ;
19+
ivec b, z ;
20+
sword _a [] = {1, 2, 3} ;
21+
a = irowvec(_a, 3, false) ;
22+
sword _b [] = {4, 5, 6} ;
23+
b = ivec(_b, 3, false) ;
24+
f(a, b, y, z) ;
25+
}
26+
#endif

test/data/function_reference_2.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function [y,z]=f(a,b)
2+
y = a+2
3+
z = b-3
4+
end
5+
function g()
6+
a = [1,2,3]
7+
b = [4;5;6]
8+
[y,z] = f(a,b)
9+
end

test/data/fx_decon.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#ifndef FX_DECON_M_HPP
2+
#define FX_DECON_M_HPP
3+
4+
#include <armadillo>
5+
#include "mconvert.h"
6+
#include <cmath>
7+
using namespace arma ;
8+
9+
mat fx_decon(mat DATA, double dt, int lf, double mu, double flow, int fhigh) ;
10+
void ar_modeling(cx_vec x, int lf, double mu, cx_vec& yf, cx_vec& yb) ;
11+
12+
mat fx_decon(mat DATA, double dt, int lf, double mu, double flow, int fhigh)
13+
{
14+
cx_mat DATA_FX, DATA_FX_b, DATA_FX_f ;
15+
cx_vec aux_in, aux_out_b, aux_out_f ;
16+
int ihigh, ilow, k, nf, nt, ntraces ;
17+
mat DATA_b, DATA_f ;
18+
nt = DATA.n_rows;
19+
ntraces = DATA.n_cols;
20+
21+
nf = pow(2, m2cpp::nextpow2(nt)) ;
22+
DATA_FX_f = arma::zeros<cx_mat>(nf, ntraces) ;
23+
DATA_FX_b = arma::zeros<cx_mat>(nf, ntraces) ;
24+
ilow = std::floor(flow*dt*nf)+1 ;
25+
if (ilow<1)
26+
{
27+
ilow = 1 ;
28+
}
29+
ihigh = std::floor(fhigh*dt*nf)+1 ;
30+
if (ihigh>std::floor(nf/2.0)+1)
31+
{
32+
ihigh = std::floor(nf/2.0)+1 ;
33+
}
34+
DATA_FX = m2cpp::fft<mat>(DATA, nf, 1) ;
35+
for (k=ilow; k<=ihigh; k++)
36+
{
37+
aux_in = arma::trans(DATA_FX.row(k-1)) ;
38+
ar_modeling(aux_in, lf, mu, aux_out_f, aux_out_b) ;
39+
DATA_FX_f.row(k-1) = arma::trans(aux_out_f) ;
40+
DATA_FX_b.row(k-1) = arma::trans(aux_out_b) ;
41+
}
42+
for (k=nf/2.0+2; k<=nf; k++)
43+
{
44+
DATA_FX_f.row(k-1) = arma::conj(DATA_FX_f.row(nf-k+1)) ;
45+
DATA_FX_b.row(k-1) = arma::conj(DATA_FX_b.row(nf-k+1)) ;
46+
}
47+
DATA_f = arma::real(m2cpp::ifft<cx_mat>(DATA_FX_f, 1)) ;
48+
DATA_f = DATA_f.rows(arma::span(0, nt-1)) ;
49+
DATA_b = arma::real(m2cpp::ifft<cx_mat>(DATA_FX_b, 1)) ;
50+
DATA_b = DATA_b.rows(arma::span(0, nt-1)) ;
51+
DATA_f = (DATA_f+DATA_b) ;
52+
DATA_f.cols(arma::span(lf, ntraces-lf-1)) = DATA_f.cols(arma::span(lf, ntraces-lf-1))/2.0 ;
53+
return DATA_f ;
54+
}
55+
56+
void ar_modeling(cx_vec x, int lf, double mu, cx_vec& yf, cx_vec& yb)
57+
{
58+
cx_double beta ;
59+
cx_mat B, M, temp ;
60+
cx_vec C, R, ab, af, y ;
61+
uword nx ;
62+
nx = m2cpp::length(x) ;
63+
y = x(arma::span(0, nx-lf-1)) ;
64+
C = x(arma::span(1, nx-lf)) ;
65+
R = x(arma::span(nx-lf, nx-1)) ;
66+
M = m2cpp::hankel(C, R) ;
67+
B = arma::trans(M)*M ;
68+
beta = B(0, 0)*(cx_double) mu/100.0 ;
69+
ab = arma::solve((B+beta*arma::eye<cx_mat>(lf, lf)), arma::trans(M), solve_opts::fast)*y ;
70+
temp = M*ab ;
71+
temp = arma::join_cols(temp, arma::zeros<cx_mat>(lf, 1)) ;
72+
yb = temp ;
73+
y = x(arma::span(lf, nx-1)) ;
74+
C = x(arma::span(lf-1, nx-2)) ;
75+
R = arma::flipud(x(arma::span(0, lf-1))) ;
76+
M = toeplitz(C, R) ;
77+
B = arma::trans(M)*M ;
78+
beta = B(0, 0)*(cx_double) mu/100.0 ;
79+
af = arma::solve((B+beta*arma::eye<cx_mat>(lf, lf)), arma::trans(M), solve_opts::fast)*y ;
80+
temp = M*af ;
81+
temp = arma::join_cols(arma::zeros<cx_mat>(lf, 1), temp) ;
82+
yf = temp ;
83+
return ;
84+
}
85+
#endif

test/data/fx_decon.m

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
function [DATA_f] = fx_decon(DATA,dt,lf,mu,flow,fhigh);
2+
[nt,ntraces] = size(DATA);
3+
nf = 2^nextpow2(nt);
4+
DATA_FX_f = zeros(nf,ntraces);
5+
DATA_FX_b = zeros(nf,ntraces);
6+
ilow = floor(flow*dt*nf)+1;
7+
if ilow<1;
8+
ilow=1;
9+
end;
10+
ihigh = floor(fhigh*dt*nf)+1;
11+
if ihigh > floor(nf/2)+1;
12+
ihigh=floor(nf/2)+1;
13+
end
14+
DATA_FX = fft(DATA,nf,1);
15+
for k = ilow:ihigh;
16+
aux_in = DATA_FX(k,:)';
17+
[aux_out_f,aux_out_b] = ar_modeling(aux_in,lf,mu);
18+
DATA_FX_f(k,:) = aux_out_f';
19+
DATA_FX_b(k,:) = aux_out_b';
20+
end;
21+
for k=nf/2+2:nf
22+
DATA_FX_f(k,:) = conj(DATA_FX_f(nf-k+2,:));
23+
DATA_FX_b(k,:) = conj(DATA_FX_b(nf-k+2,:));
24+
end
25+
DATA_f = real(ifft(DATA_FX_f,[],1));
26+
DATA_f = DATA_f(1:nt,:);
27+
DATA_b = real(ifft(DATA_FX_b,[],1));
28+
DATA_b = DATA_b(1:nt,:);
29+
DATA_f = (DATA_f + DATA_b);
30+
DATA_f(:,lf+1:ntraces-lf)= DATA_f(:,lf+1:ntraces-lf)/2;
31+
return
32+
function [yf,yb] = ar_modeling(x,lf,mu);
33+
nx = length(x);
34+
y = x(1:nx-lf,1);
35+
C = x(2:nx-lf+1,1);
36+
R = x(nx-lf+1:nx,1);
37+
M = hankel(C,R);
38+
B = M'*M; beta = B(1,1)*mu/100;
39+
ab = (B + beta*eye(lf))\M'*y;
40+
temp = M*ab;
41+
temp = [temp;zeros(lf,1)];
42+
yb = temp;
43+
y = x(lf+1:nx,1);
44+
C = x(lf:nx-1,1);
45+
R = flipud(x(1:lf,1));
46+
M = toeplitz(C,R);
47+
B = M'*M; beta = B(1,1)*mu/100;
48+
af = (B + beta*eye(lf))\M'*y;
49+
temp = M*af;
50+
temp = [zeros(lf,1);temp];
51+
yf = temp;
52+
return

test/data/fx_decon.m.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
functions = {
2+
"ar_modeling" : {
3+
"B" : "cx_mat",
4+
"C" : "cx_vec",
5+
"M" : "cx_mat",
6+
"R" : "cx_vec",
7+
"ab" : "cx_vec",
8+
"af" : "cx_vec",
9+
"beta" : "cx_double",
10+
"lf" : "int",
11+
"mu" : "double",
12+
"nx" : "uword",
13+
"temp" : "cx_mat",
14+
"x" : "cx_vec",
15+
"y" : "cx_vec",
16+
"yb" : "cx_vec",
17+
"yf" : "cx_vec",
18+
},
19+
"fx_decon" : {
20+
"DATA" : "mat",
21+
"DATA_FX" : "cx_mat",
22+
"DATA_FX_b" : "cx_mat",
23+
"DATA_FX_f" : "cx_mat",
24+
"DATA_b" : "mat",
25+
"DATA_f" : "mat",
26+
"aux_in" : "cx_vec",
27+
"aux_out_b" : "cx_vec",
28+
"aux_out_f" : "cx_vec",
29+
"dt" : "double",
30+
"fhigh" : "int",
31+
"flow" : "double",
32+
"ihigh" : "int",
33+
"ilow" : "int",
34+
"k" : "int",
35+
"lf" : "int",
36+
"mu" : "double",
37+
"nf" : "int",
38+
"nt" : "int",
39+
"ntraces" : "int",
40+
},
41+
}
42+
includes = [
43+
'#include <armadillo>',
44+
'using namespace arma ;',
45+
]

0 commit comments

Comments
 (0)