Skip to content

Commit

Permalink
implement the parallel doc macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed May 22, 2024
1 parent 5700ad8 commit 12c7fed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
18 changes: 18 additions & 0 deletions src/doc_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ macro_rules! generate_mut_doc_comment {
)
};
}

/// A macro for generating the doc-comments for parallel versions of various
/// image processing functions. It takes the name of then non-parallel function as an
/// argument as a string literal.
///
/// It uses concat! to generate doc-links to the provided original function name
/// in string literal form.
macro_rules! generate_parallel_doc_comment {
($name:literal) => {
concat!(
"An parallel version of [`",
$name,
"()`].\n\nThis function does the same operation as [`",
$name,
"()`] but using multi-threading via [`rayon`](https://docs.rs/rayon) iterators.\nRead the top-level crate documentation on parallelism for some of the tradeoffs involved with multi-threaded vs single-threaded image processing functions."
)
};
}
26 changes: 2 additions & 24 deletions src/template_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,7 @@ pub fn match_template(
}

#[cfg(feature = "rayon")]
/// Slides a `template` over an `image` and scores the match at each point using
/// the requested `method`. This version uses rayon to parallelize the computation.
///
/// The returned image has dimensions `image.width() - template.width() + 1` by
/// `image.height() - template.height() + 1`.
///
/// See [`MatchTemplateMethod`] for details of the matching methods.
///
/// # Panics
///
/// If either dimension of `template` is not strictly less than the corresponding dimension
/// of `image`.
#[doc = generate_parallel_doc_comment!("match_template")]
pub fn match_template_parallel(
image: &GrayImage,
template: &GrayImage,
Expand Down Expand Up @@ -151,18 +140,7 @@ pub fn match_template_with_mask(
}

#[cfg(feature = "rayon")]
/// Slides a `template` and a `mask` over an `image` and scores the match at each point using
/// the requested `method`. This version uses rayon to parallelize the computation.
///
/// The returned image has dimensions `image.width() - template.width() + 1` by
/// `image.height() - template.height() + 1`.
///
/// See [`MatchTemplateMethod`] for details of the matching methods.
///
/// # Panics
/// - If either dimension of `template` is not strictly less than the corresponding dimension
/// of `image`.
/// - If `template.dimensions() != mask.dimensions()`.
#[doc = generate_parallel_doc_comment!("match_template_with_mask")]
pub fn match_template_with_mask_parallel(
image: &GrayImage,
template: &GrayImage,
Expand Down

0 comments on commit 12c7fed

Please sign in to comment.