Skip to content

Commit 0ae1d56

Browse files
authored
Merge pull request #9 from SpatLyu/dev
prepare first cran release
2 parents c008841 + f548d11 commit 0ae1d56

10 files changed

Lines changed: 151 additions & 9 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
^_pkgdown\.yml$
55
^docs$
66
^pkgdown$
7+
^cran-comments\.md$

.github/workflows/rhub.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
2+
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
3+
# You can update this file to a newer version using the rhub2 package:
4+
#
5+
# rhub::rhub_setup()
6+
#
7+
# It is unlikely that you need to modify this file manually.
8+
9+
name: R-hub
10+
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
config:
16+
description: 'A comma separated list of R-hub platforms to use.'
17+
type: string
18+
default: 'linux,windows,macos'
19+
name:
20+
description: 'Run name. You can leave this empty now.'
21+
type: string
22+
id:
23+
description: 'Unique ID. You can leave this empty now.'
24+
type: string
25+
26+
jobs:
27+
28+
setup:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
containers: ${{ steps.rhub-setup.outputs.containers }}
32+
platforms: ${{ steps.rhub-setup.outputs.platforms }}
33+
34+
steps:
35+
# NO NEED TO CHECKOUT HERE
36+
- uses: r-hub/actions/setup@v1
37+
with:
38+
config: ${{ github.event.inputs.config }}
39+
id: rhub-setup
40+
41+
linux-containers:
42+
needs: setup
43+
if: ${{ needs.setup.outputs.containers != '[]' }}
44+
runs-on: ubuntu-latest
45+
name: ${{ matrix.config.label }}
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
config: ${{ fromJson(needs.setup.outputs.containers) }}
50+
container:
51+
image: ${{ matrix.config.container }}
52+
53+
steps:
54+
- uses: r-hub/actions/checkout@v1
55+
- uses: r-hub/actions/platform-info@v1
56+
with:
57+
token: ${{ secrets.RHUB_TOKEN }}
58+
job-config: ${{ matrix.config.job-config }}
59+
- uses: r-hub/actions/setup-deps@v1
60+
with:
61+
token: ${{ secrets.RHUB_TOKEN }}
62+
job-config: ${{ matrix.config.job-config }}
63+
- uses: r-hub/actions/run-check@v1
64+
with:
65+
token: ${{ secrets.RHUB_TOKEN }}
66+
job-config: ${{ matrix.config.job-config }}
67+
68+
other-platforms:
69+
needs: setup
70+
if: ${{ needs.setup.outputs.platforms != '[]' }}
71+
runs-on: ${{ matrix.config.os }}
72+
name: ${{ matrix.config.label }}
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
config: ${{ fromJson(needs.setup.outputs.platforms) }}
77+
78+
steps:
79+
- uses: r-hub/actions/checkout@v1
80+
- uses: r-hub/actions/setup-r@v1
81+
with:
82+
job-config: ${{ matrix.config.job-config }}
83+
token: ${{ secrets.RHUB_TOKEN }}
84+
- uses: r-hub/actions/platform-info@v1
85+
with:
86+
token: ${{ secrets.RHUB_TOKEN }}
87+
job-config: ${{ matrix.config.job-config }}
88+
- uses: r-hub/actions/setup-deps@v1
89+
with:
90+
job-config: ${{ matrix.config.job-config }}
91+
token: ${{ secrets.RHUB_TOKEN }}
92+
- uses: r-hub/actions/run-check@v1
93+
with:
94+
job-config: ${{ matrix.config.job-config }}
95+
token: ${{ secrets.RHUB_TOKEN }}

DESCRIPTION

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: coupling
2-
Title: Coupling Coordination Analysis
3-
Version: 0.0.0.9000
2+
Title: Analysis of Coupling Coordination Degree
3+
Version: 0.1
44
Authors@R:
55
person(given = "Wenbo", family = "Lyu",
66
email = "lyu.geosocial@gmail.com",
@@ -17,7 +17,10 @@ LinkingTo:
1717
Rcpp,
1818
RcppThread
1919
Suggests:
20+
infoxtr,
21+
pc,
2022
Rcpp,
2123
RcppThread,
24+
spEDM
2225
Config/roxygen2/markdown: TRUE
2326
Config/roxygen2/version: 8.0.0

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# coupling 0.1
2+
3+
* Initial CRAN submission.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<a href="https://stscl.github.io/coupling/"><img src="man/figures/coupling.png" align="right" hspace="5" vspace="0" width="15%" alt="coupling website: https://stscl.github.io/coupling/"/></a>
1818

19-
***Coupling** Coordination Analysis*
19+
*Analysis of Coupling Coordination Degree*
2020

2121
*coupling* is an R package for coupling coordination analysis based on coupling coordination degree (CCD) models. It incorporates metacoupling frameworks to characterize cross-scale linkages, flows, and feedbacks within and among coupled systems.
2222

_pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ navbar:
1818

1919
home:
2020
title: |
21-
ccd | Coupling Coordination Analysis
21+
coupling | Analysis of Coupling Coordination Degree
2222
authors:
2323
Wenbo Lyu:
2424
href: https://spatlyu.github.io/

cran-comments.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## R CMD check results
2+
3+
0 errors | 0 warnings | 1 note
4+
5+
* This is a new release.

inst/CITATION

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
citHeader("To cite package coupling in publications, please use:")
2+
3+
bibentry(
4+
bibtype = "Manual",
5+
title = "{coupling: Analysis of Coupling Coordination Degree}",
6+
author = "Wenbo Lyu",
7+
year = "2026",
8+
note = "R package version 0.1",
9+
doi = "10.32614/CRAN.package.coupling"
10+
)

inst/include/coupling/ccd.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ inline std::vector<double> ccd_c(
295295
if (n_units == 0) return {};
296296

297297
std::vector<double> result(n_units, 0.0);
298+
299+
if (threads == 0) threads = 1;
300+
size_t hw = std::thread::hardware_concurrency();
301+
if (hw > 0) threads = std::min(threads, hw);
298302

299303
if (threads <= 1) {
300304
for (size_t i = 0; i < n_units; ++i) {

inst/include/coupling/metacoupling.hpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ inline std::vector<std::vector<double>> metacoupling_c(
312312
result[1][s] = peri_sum;
313313
result[2][s] = tele_sum;
314314
};
315+
316+
// ============================================================
317+
// Check for available threads
318+
// ============================================================
319+
if (threads == 0) threads = 1;
320+
size_t hw = std::thread::hardware_concurrency();
321+
if (hw > 0) threads = std::min(threads, hw);
315322

316323
// ============================================================
317324
// Parallel or serial execution
@@ -357,6 +364,13 @@ inline std::vector<std::vector<double>> metacoupling(
357364

358365
size_t full_perm = 1ULL << p;
359366

367+
// ============================================================
368+
// Check for available threads
369+
// ============================================================
370+
if (threads == 0) threads = 1;
371+
size_t hw = std::thread::hardware_concurrency();
372+
if (hw > 0) threads = std::min(threads, hw);
373+
360374
// ============================================================
361375
// Step 1: reuse existing C computation
362376
// ============================================================
@@ -399,11 +413,7 @@ inline std::vector<std::vector<double>> metacoupling(
399413
return sum_t / static_cast<double>(count);
400414
};
401415

402-
// ============================================================
403-
// Step 3: assemble results
404-
// ============================================================
405-
for (size_t s = 0; s < n_units; ++s) {
406-
416+
auto worker4D = [&](size_t s) {
407417
// ---- intra ----
408418
double C_intra = C_res[0][s];
409419
double T_intra = compute_T_intra(s);
@@ -442,6 +452,17 @@ inline std::vector<std::vector<double>> metacoupling(
442452

443453
result[4][s] = C_tele;
444454
result[5][s] = std::sqrt(C_tele * tele_T_sum);
455+
};
456+
457+
// ============================================================
458+
// Step 3: assemble results
459+
// ============================================================
460+
if (threads <= 1) {
461+
for (size_t s = 0; s < n_units; ++s) {
462+
worker4D(s);
463+
}
464+
} else {
465+
RcppThread::parallelFor(0, n_units, worker4D, threads);
445466
}
446467

447468
return result;

0 commit comments

Comments
 (0)