Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^cran-comments\.md$
95 changes: 95 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

name: R-hub
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"

on:
workflow_dispatch:
inputs:
config:
description: 'A comma separated list of R-hub platforms to use.'
type: string
default: 'linux,windows,macos'
name:
description: 'Run name. You can leave this empty now.'
type: string
id:
description: 'Unique ID. You can leave this empty now.'
type: string

jobs:

setup:
runs-on: ubuntu-latest
outputs:
containers: ${{ steps.rhub-setup.outputs.containers }}
platforms: ${{ steps.rhub-setup.outputs.platforms }}

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/actions/setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup

linux-containers:
needs: setup
if: ${{ needs.setup.outputs.containers != '[]' }}
runs-on: ubuntu-latest
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.containers) }}
container:
image: ${{ matrix.config.container }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/run-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/run-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: coupling
Title: Coupling Coordination Analysis
Version: 0.0.0.9000
Title: Analysis of Coupling Coordination Degree
Version: 0.1
Authors@R:
person(given = "Wenbo", family = "Lyu",
email = "lyu.geosocial@gmail.com",
Expand All @@ -17,7 +17,10 @@ LinkingTo:
Rcpp,
RcppThread
Suggests:
infoxtr,
pc,
Rcpp,
RcppThread,
spEDM
Config/roxygen2/markdown: TRUE
Config/roxygen2/version: 8.0.0
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# coupling 0.1

* Initial CRAN submission.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<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>

***Coupling** Coordination Analysis*
*Analysis of Coupling Coordination Degree*

*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.

Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ navbar:

home:
title: |
ccd | Coupling Coordination Analysis
coupling | Analysis of Coupling Coordination Degree
authors:
Wenbo Lyu:
href: https://spatlyu.github.io/
Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
10 changes: 10 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
citHeader("To cite package coupling in publications, please use:")

bibentry(
bibtype = "Manual",
title = "{coupling: Analysis of Coupling Coordination Degree}",
author = "Wenbo Lyu",
year = "2026",
note = "R package version 0.1",
doi = "10.32614/CRAN.package.coupling"
)
4 changes: 4 additions & 0 deletions inst/include/coupling/ccd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ inline std::vector<double> ccd_c(
if (n_units == 0) return {};

std::vector<double> result(n_units, 0.0);

if (threads == 0) threads = 1;
size_t hw = std::thread::hardware_concurrency();
if (hw > 0) threads = std::min(threads, hw);

if (threads <= 1) {
for (size_t i = 0; i < n_units; ++i) {
Expand Down
31 changes: 26 additions & 5 deletions inst/include/coupling/metacoupling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ inline std::vector<std::vector<double>> metacoupling_c(
result[1][s] = peri_sum;
result[2][s] = tele_sum;
};

// ============================================================
// Check for available threads
// ============================================================
if (threads == 0) threads = 1;
size_t hw = std::thread::hardware_concurrency();
if (hw > 0) threads = std::min(threads, hw);

// ============================================================
// Parallel or serial execution
Expand Down Expand Up @@ -357,6 +364,13 @@ inline std::vector<std::vector<double>> metacoupling(

size_t full_perm = 1ULL << p;

// ============================================================
// Check for available threads
// ============================================================
if (threads == 0) threads = 1;
size_t hw = std::thread::hardware_concurrency();
if (hw > 0) threads = std::min(threads, hw);

// ============================================================
// Step 1: reuse existing C computation
// ============================================================
Expand Down Expand Up @@ -399,11 +413,7 @@ inline std::vector<std::vector<double>> metacoupling(
return sum_t / static_cast<double>(count);
};

// ============================================================
// Step 3: assemble results
// ============================================================
for (size_t s = 0; s < n_units; ++s) {

auto worker4D = [&](size_t s) {
// ---- intra ----
double C_intra = C_res[0][s];
double T_intra = compute_T_intra(s);
Expand Down Expand Up @@ -442,6 +452,17 @@ inline std::vector<std::vector<double>> metacoupling(

result[4][s] = C_tele;
result[5][s] = std::sqrt(C_tele * tele_T_sum);
};

// ============================================================
// Step 3: assemble results
// ============================================================
if (threads <= 1) {
for (size_t s = 0; s < n_units; ++s) {
worker4D(s);
}
} else {
RcppThread::parallelFor(0, n_units, worker4D, threads);
}

return result;
Expand Down
Loading