Skip to content

Commit

Permalink
Merge pull request #226 from pik-copan/225-cython-complex-I
Browse files Browse the repository at this point in the history
Avoid using variable name `I` in C code
  • Loading branch information
fkuehlein authored Jun 21, 2024
2 parents 5e03951 + 8943340 commit 3079fda
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ classifiers =

[options]
install_requires =
numpy >= 1.24
numpy >= 1.24, < 2.0
scipy >= 1.10
igraph >= 0.11
h5netcdf >= 1.1 ; python_version >= "3.9"
Expand Down
16 changes: 8 additions & 8 deletions src/pyunicorn/core/_ext/src_numerics.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ double _vertex_current_flow_betweenness_fast(int N, double Is, double It,
int t=0;
int s=0;
int j=0;
double I=0;
double J=0;

for(t=0;t<N;t++){
for(s=0; s<t; s++){
I = 0.0;
J = 0.0;
if(i == t || i == s){
continue;
}
else{
for(j=0;j<N;j++){
I += admittance[i*N+j]*
J += admittance[i*N+j]*
fabs( Is*(R[i*N+s]-R[j*N+s])+
It*(R[j*N+t]-R[i*N+t])
) / 2.0;
} // for j
}
VCFB += 2.0*I/(N*(N-1));
VCFB += 2.0*J/(N*(N-1));
} // for s
} // for t

Expand All @@ -149,19 +149,19 @@ void _edge_current_flow_betweenness_fast(int N, double Is, double It,
int j=0;
int t=0;
int s=0;
double I = 0.0;
double J = 0.0;

for(i=0; i<N; i++){
for(j=0;j<N;j++){
I = 0.0;
J = 0.0;
for(t=0;t<N;t++){
for(s=0; s<t; s++){
I += admittance[i*N+j]*\
J += admittance[i*N+j]*\
fabs(Is*(R[i*N+s]-R[j*N+s])+
It*(R[j*N+t]-R[i*N+t]));
} //for s
} // for t
ECFB[i*N+j] += (float) (2.* I/(N*(N-1)));
ECFB[i*N+j] += (float) (2.* J/(N*(N-1)));
} // for j
} // for i
}
46 changes: 45 additions & 1 deletion tests/test_timeseries/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from numpy.testing import assert_array_almost_equal

from pyunicorn.timeseries import CrossRecurrencePlot, \
InterSystemRecurrenceNetwork, Surrogates, VisibilityGraph
RecurrenceNetwork, InterSystemRecurrenceNetwork, \
Surrogates, VisibilityGraph
from pyunicorn.core.data import Data
from pyunicorn.core._ext.types import DFIELD

Expand Down Expand Up @@ -69,6 +70,49 @@ def testCrossRecurrencePlot(thresh, rr, metric: str):
assert CR1.dtype == np.int8


# -----------------------------------------------------------------------------
# recurrence_network
# -----------------------------------------------------------------------------

@pytest.mark.parametrize("thresh, rr",
[(.2, None), (None, .2)], ids=str)
def testRecurrenceNetwork(thresh, rr, metric: str):
# create two instances of the same test dataset
tdata1 = create_test_data()
tdata2 = create_test_data()
# create RecurrenceNetwork for both
rn1 = RecurrenceNetwork(
tdata1, threshold=thresh, recurrence_rate=rr, metric=metric)
rn2 = RecurrenceNetwork(
tdata2, threshold=thresh, recurrence_rate=rr, metric=metric)
# get respective adjacency matrices
A1 = rn1.adjacency
A2 = rn2.adjacency

assert np.array_equal(A1, A2)
assert A1.shape == A2.shape
assert A1.shape == (len(tdata1), len(tdata1))
assert A1.dtype == A2.dtype
assert A1.dtype == np.int16


def testRecurrenceNetwork_setters():
tdata = create_test_data()
rn = RecurrenceNetwork(tdata, threshold=.2)
# recalculate with different fixed threshold
rn.set_fixed_threshold(.3)
assert rn.adjacency.shape == (len(tdata), len(tdata))
# recalculate with fixed threshold in units of the ts' std
rn.set_fixed_threshold_std(.3)
assert rn.adjacency.shape == (len(tdata), len(tdata))
# recalculate with fixed recurrence rate
rn.set_fixed_recurrence_rate(.2)
assert rn.adjacency.shape == (len(tdata), len(tdata))
# recalculate with fixed local recurrence rate
rn.set_fixed_local_recurrence_rate(.2)
assert rn.adjacency.shape == (len(tdata), len(tdata))


# -----------------------------------------------------------------------------
# inter_system_recurrence_network
# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 3079fda

Please sign in to comment.