Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor 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
mpim-sw
cdo
Commits
6b76d9ad
Commit
6b76d9ad
authored
5 months ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
limit maxNeighbors to knnWeights.maxNeighbors()
parent
c0615c8c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!281
M214003/develop
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/knn_weights.h
+8
-2
8 additions, 2 deletions
src/knn_weights.h
src/pointsearch_healpix.h
+7
-7
7 additions, 7 deletions
src/pointsearch_healpix.h
src/pointsearch_reg2d.cc
+12
-20
12 additions, 20 deletions
src/pointsearch_reg2d.cc
src/pointsearch_reg2d.h
+2
-0
2 additions, 0 deletions
src/pointsearch_reg2d.h
with
29 additions
and
29 deletions
src/knn_weights.h
+
8
−
2
View file @
6b76d9ad
...
...
@@ -89,9 +89,9 @@ public:
inline
bool
distance_is_less
(
double
distance
,
double
distx
,
size_t
index
,
size_t
index2
)
{
constexpr
double
cmp
_tol
=
1.e-12
;
constexpr
double
cmp
Tolerance
=
1.e-12
;
// return (distance < distx || (distance <= distx && index < index2));
return
(
distance
+
cmp
_tol
)
<
distx
||
(
index
<
index2
&&
std
::
fabs
(
distance
-
distx
)
<
cmp
_tol
);
return
(
distance
+
cmp
Tolerance
)
<
distx
||
(
index
<
index2
&&
std
::
fabs
(
distance
-
distx
)
<
cmp
Tolerance
);
}
inline
void
...
...
@@ -126,6 +126,12 @@ public:
}
}
}
inline
void
store_distance
(
size_t
index
,
double
distance
)
{
store_distance
(
index
,
distance
,
m_maxNeighbors
);
}
/*
inline void
set_distance(const size_t *indices, const double *distance, size_t numNeighbors)
...
...
This diff is collapsed.
Click to expand it.
src/pointsearch_healpix.h
+
7
−
7
View file @
6b76d9ad
...
...
@@ -53,24 +53,24 @@ private:
auto
sqrSearchRadius
=
cdo
::
sqr
(
searchRadius
);
double
xyz
[
3
];
double
searchPoint
[
3
];
size_t
numWeights
=
0
;
for
(
size_t
i
=
0
;
i
<
numIndices
;
++
i
)
{
gcLLtoXYZ
(
lons
[
i
],
lats
[
i
],
xyz
);
gcLLtoXYZ
(
lons
[
i
],
lats
[
i
],
searchPoint
);
// Find distance to this point
double
sqrDist
=
(
float
)
cdo
::
sqr_distance
(
queryPoint
,
xyz
);
double
sqrDist
ance
=
(
float
)
cdo
::
sqr_distance
(
queryPoint
,
searchPoint
);
// Store the index and distance if this is one of the smallest so far
if
(
sqrDist
<=
sqrSearchRadius
)
if
(
sqrDist
ance
<=
sqrSearchRadius
)
{
indices
[
numWeights
]
=
indices
[
i
];
distances
[
numWeights
]
=
std
::
sqrt
(
sqrDist
);
distances
[
numWeights
]
=
std
::
sqrt
(
sqrDist
ance
);
numWeights
++
;
}
}
numW
eigh
t
s
=
std
::
min
(
numWeights
,
knnWeights
.
maxNeighbors
());
for
(
size_t
i
=
0
;
i
<
numWeights
;
++
i
)
{
knnWeights
.
store_distance
(
indices
[
i
],
distances
[
i
],
numW
eigh
t
s
);
}
auto
maxN
eigh
bor
s
=
std
::
min
(
numWeights
,
knnWeights
.
maxNeighbors
());
for
(
size_t
i
=
0
;
i
<
numWeights
;
++
i
)
{
knnWeights
.
store_distance
(
indices
[
i
],
distances
[
i
],
maxN
eigh
bor
s
);
}
knnWeights
.
check_distance
();
}
...
...
This diff is collapsed.
Click to expand it.
src/pointsearch_reg2d.cc
+
12
−
20
View file @
6b76d9ad
...
...
@@ -39,18 +39,16 @@ fill_src_indices(bool isCyclic, long nx, long ny, long ii, long jj, long k, size
return
numIndices
;
}
/*
void
PointsearchReg2d::compute
(
)
PointsearchReg2d
::
compute
_point
(
size_t
index
,
double
(
&
xyz
)[
3
]
)
{
auto iy = index / nx;
auto ix = index - iy * nx;
auto
iy
=
index
/
m_nx
;
auto
ix
=
index
-
iy
*
m_nx
;
xyz
[
0
]
=
m_cosLats
[
iy
]
*
m_cosLons
[
ix
];
xyz
[
1
]
=
m_cosLats
[
iy
]
*
m_sinLons
[
ix
];
xyz
[
2
]
=
m_sinLats
[
iy
];
}
*/
void
PointsearchReg2d
::
store_distance_reg2d
(
double
plon
,
double
plat
,
knnWeightsType
&
knnWeights
,
size_t
nx
,
size_t
numIndices
,
size_t
*
indices
,
double
*
distances
,
double
searchRadius
)
...
...
@@ -59,30 +57,24 @@ PointsearchReg2d::store_distance_reg2d(double plon, double plat, knnWeightsType
gcLLtoXYZ
(
plon
,
plat
,
queryPoint
);
auto
sqrSearchRadius
=
cdo
::
sqr
(
searchRadius
);
double
xyz
[
3
];
double
searchPoint
[
3
];
size_t
numWeights
=
0
;
for
(
size_t
i
=
0
;
i
<
numIndices
;
++
i
)
{
auto
index
=
indices
[
i
];
auto
iy
=
index
/
nx
;
auto
ix
=
index
-
iy
*
nx
;
xyz
[
0
]
=
m_cosLats
[
iy
]
*
m_cosLons
[
ix
];
xyz
[
1
]
=
m_cosLats
[
iy
]
*
m_sinLons
[
ix
];
xyz
[
2
]
=
m_sinLats
[
iy
];
compute_point
(
indices
[
i
],
searchPoint
);
// Find distance to this point
double
sqrDist
=
(
float
)
cdo
::
sqr_distance
(
queryPoint
,
xyz
);
double
sqrDist
ance
=
(
float
)
cdo
::
sqr_distance
(
queryPoint
,
searchPoint
);
// Store the index and distance if this is one of the smallest so far
if
(
sqrDist
<=
sqrSearchRadius
)
if
(
sqrDist
ance
<=
sqrSearchRadius
)
// knnWeights.store_distance(index, std::sqrt(sqrDist));
{
indices
[
numWeights
]
=
ind
ex
;
distances
[
numWeights
]
=
std
::
sqrt
(
sqrDist
);
indices
[
numWeights
]
=
ind
ices
[
i
]
;
distances
[
numWeights
]
=
std
::
sqrt
(
sqrDist
ance
);
numWeights
++
;
}
}
numW
eigh
t
s
=
std
::
min
(
numWeights
,
knnWeights
.
maxNeighbors
());
for
(
size_t
i
=
0
;
i
<
numWeights
;
++
i
)
{
knnWeights
.
store_distance
(
indices
[
i
],
distances
[
i
],
numW
eigh
t
s
);
}
auto
maxN
eigh
bor
s
=
std
::
min
(
numWeights
,
knnWeights
.
maxNeighbors
());
for
(
size_t
i
=
0
;
i
<
numWeights
;
++
i
)
{
knnWeights
.
store_distance
(
indices
[
i
],
distances
[
i
],
maxN
eigh
bor
s
);
}
knnWeights
.
check_distance
();
}
...
...
This diff is collapsed.
Click to expand it.
src/pointsearch_reg2d.h
+
2
−
0
View file @
6b76d9ad
...
...
@@ -75,6 +75,8 @@ private:
size_t
m_ny
{
0
};
Varray
<
double
>
m_cosLats
,
m_sinLats
;
// cosine, sine of grid lats (for distance)
Varray
<
double
>
m_cosLons
,
m_sinLons
;
// cosine, sine of grid lons (for distance)
void
compute_point
(
size_t
index
,
double
(
&
xyz
)[
3
]);
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment