Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 5553330

Browse files
committed
Merge pull request #336 from swift-nav/peddie-rtklib-fortran-order
RTKLIB routines use Fortran storage order.
2 parents 7159b25 + 0c96289 commit 5553330

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

python/swiftnav/lambda_.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def lambda_reduction_(Q):
2828
"""
2929
assert len(Q.shape) == 2 and Q.shape[0] == Q.shape[1], "Q matrix must have shape (n, n)"
3030
n = Q.shape[0]
31-
cdef np.ndarray[np.double_t, ndim=2, mode="c"] Q_ = np.array(Q, dtype=np.double)
32-
cdef np.ndarray[np.double_t, ndim=2, mode="c"] Z = np.empty((n, n), dtype=np.double)
31+
cdef np.ndarray[np.double_t, ndim=2, mode="fortran"] Q_ = np.array(Q, dtype=np.double)
32+
cdef np.ndarray[np.double_t, ndim=2, mode="fortran"] Z = np.empty((n, n), dtype=np.double)
3333
assert lambda_reduction(n, &Q_[0,0], &Z[0,0]) == 0, "lambda error!"
3434
return Z
3535

@@ -51,9 +51,9 @@ def lambda_solution_(x, sigma, m):
5151
assert len(sigma.shape) == 2 and sigma.shape[0] == sigma.shape[1], "Q matrix must have shape (n, n)"
5252
assert len(x.shape) == 1 and x.shape[0] == sigma.shape[1], "x vector must have length to match sigma matrix"
5353
num_dds = x.shape[0]
54-
cdef np.ndarray[np.double_t, ndim=1, mode="c"] x_ = np.array(x, dtype=np.double)
55-
cdef np.ndarray[np.double_t, ndim=2, mode="c"] sigma_ = np.array(sigma, dtype=np.double)
56-
cdef np.ndarray[np.double_t, ndim=2, mode="c"] F_ = np.empty((num_dds,m), dtype=np.double)
57-
cdef np.ndarray[np.double_t, ndim=1, mode="c"] s_ = np.empty((m), dtype=np.double)
54+
cdef np.ndarray[np.double_t, ndim=1, mode="fortran"] x_ = np.array(x, dtype=np.double)
55+
cdef np.ndarray[np.double_t, ndim=2, mode="fortran"] sigma_ = np.array(sigma, dtype=np.double)
56+
cdef np.ndarray[np.double_t, ndim=2, mode="fortran"] F_ = np.empty((num_dds,m), dtype=np.double, order='F')
57+
cdef np.ndarray[np.double_t, ndim=1, mode="fortran"] s_ = np.empty((m), dtype=np.double, order='F')
5858
assert lambda_solution(num_dds, m, &x_[0], &sigma_[0,0], &F_[0,0], &s_[0]) == 0,"lambda error!"
5959
return (F_.T, s_.T)

python/tests/test_lambda.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ def test_lambda1():
2929
[0.112202, 0.112202, 0.112202, 0.227134, 0.112202, 0.103473],
3030
[0.112202, 0.112202, 0.112202, 0.112202, 0.227134, 0.103473],
3131
[0.103473, 0.103473, 0.103473, 0.103473, 0.103473, 0.434339]])
32-
F, s = l.lambda_solution_(x, sigma, m)
32+
F, s = l.lambda_solution_(x, np.asfortranarray(sigma), m)
3333
assert np.allclose(F,
34-
np.array([[ 1.58518400e+06, 3.91574300e+06, 9.56599100e+06,
35-
1.58518400e+06, 3.91574300e+06, 9.56599100e+06],
36-
[ -6.71659900e+06, 7.62723400e+06, 9.89457273e+08,
37-
-6.71660000e+06, 7.62723300e+06, 9.89457273e+08]]))
34+
np.array([[1.58518400e+06, -6.71659900e+06, 3.91574300e+06,
35+
7.62723400e+06, 9.56599100e+06, 9.89457273e+08],
36+
[1.58518400e+06, -6.71660000e+06, 3.91574300e+06,
37+
7.62723300e+06, 9.56599100e+06, 9.89457273e+08]]))
3838
assert np.allclose(s, np.array([ 3.50798444, 3.70845619]))
3939

4040
def test_lambda2():
@@ -59,13 +59,37 @@ def test_lambda2():
5959
[0.286388, 0.286388, 0.572775, 0.286388, 0.286388, 0.367531, 0.367531, 0.735063, 0.367531, 0.367531],
6060
[0.286388, 0.286388, 0.286388, 0.572775, 0.286388, 0.367531, 0.367531, 0.367531, 0.735063, 0.367531],
6161
[0.286388, 0.286388, 0.286388, 0.286388, 0.572775, 0.367531, 0.367531, 0.367531, 0.367531, 0.735063]])
62-
F, s = l.lambda_solution_(x, sigma, m)
62+
F, s = l.lambda_solution_(x, np.asfortranarray(sigma), m)
6363
assert np.allclose(F,
64-
[[-13324188., -7157236.00000014, -7454143.00000017,
65-
8336726.00000008, -17549108.00000054, -13324187.99999997,
66-
-7157236.00000013, -7454143.00000013, 8336717.00000021,
67-
-17549108.00000053],
68-
[-10668900.99999994, -6149379.00000041, -5969220., 6186959.99999982,
69-
-13970171.00000022, -10668907.99999984, -6149379.00000041,
70-
-5969219.99999996, 6186959.99999983, -13970171.00000017]])
64+
np.array([[-13324188., -10668900.99999994, -7157236.00000014,
65+
-6149379.00000041, -7454143.00000017, -5969220.,
66+
8336726.00000008, 6186959.99999982, -17549108.00000054,
67+
-13970171.00000022],
68+
[-13324187.99999997, -10668907.99999984, -7157236.00000013,
69+
-6149379.00000041, -7454143.00000013, -5969219.99999996,
70+
8336717.00000021, 6186959.99999983, -17549108.00000053,
71+
-13970171.00000017]]))
72+
7173
assert np.allclose(s, np.array([ 1506.43579559, 1612.81177168]))
74+
75+
def test_lambda3():
76+
"""
77+
Verify that passing in perfectly decorrelated integers results in the
78+
same integers being identified.
79+
"""
80+
m = 1
81+
x = np.array([-22, 22, -55, 55, -33, 33, -66, 66, -44, 44, -77, 77])
82+
sigma = np.eye(x.size)
83+
F, s = l.lambda_solution_(x, np.asfortranarray(sigma), m)
84+
assert np.allclose(F[0], x)
85+
86+
def test_lambda4():
87+
"""
88+
Verify that the relative scale of the covariance matrix doesn't affect
89+
the solution.
90+
"""
91+
m = 1
92+
x = np.array([-22, 22, -55, 55, -33, 33, -66, 66, -44, 44, -77, 77])
93+
sigma = np.eye(x.size) * 1000
94+
F, s = l.lambda_solution_(x, np.asfortranarray(sigma), m)
95+
assert np.allclose(F[0], x)

0 commit comments

Comments
 (0)