Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pacs-course/pacs-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lformaggia committed Sep 20, 2024
2 parents c9a7f93 + 7d45130 commit 98e516c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 18 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
51 changes: 51 additions & 0 deletions .github/workflows/jekyll-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll with GitHub Pages dependencies preinstalled

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./
destination: ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion Examples/src/LinearAlgebra/spectra
29 changes: 15 additions & 14 deletions Examples/src/STL/RangesAndViews/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# C++ Ranges, Views, and Range Adaptors
# C++ Ranges, Views, and Range Adaptors #

## Ranges
## Ranges ##
A **Range** is a concept that refers to anything you can iterate over with a beginning and an end. In C++, ranges provide a more modern and powerful abstraction for dealing with sequences of values. The range library, introduced in C++20, offers several utilities to work with ranges conveniently.
In modern c++ a range is any object that can be used in a range-based for loop. This includes containers, as well as views, and in general any class that implements the `begin()` and `end()` functions, returning valid iterators, or that returns valid iterators when called with `std::begin()` and `std::end()`.
The `end()` function should return what is normally indicated as a `sentinel`, i.e. a value that identify the end of the range. For instance for a container `end()` returns an iterator that is one past the last element of the container. Having generalised the concept of `sentinel` allow to introduce ranges defined by the start and the number of elements, as that returned by `std::ranges::subrange` or `std::ranges::views::take`.

### Key Features:
### Key Features: ###
- **Composable:** Ranges can be combined with other ranges or operations to create new ranges.
- **Lazy Evaluation:** Operations on ranges are often lazy, meaning they are evaluated only when needed.
- **Readable and Writeable:** Ranges can be designed for reading, writing, or both.

## Views
**Views** are a classes that represent special kind of ranges that do not own the data they operate on. Instead, they provide a view into a range given in the constructor by applying some transformation or filtering.
## Views ##
**Views** are classes that represent special kinds of ranges that do not own the data they operate on. Instead, they provide a view into a range given in the constructor by applying some transformation or filtering.

### Characteristics:
- **Non-Owning:** Views reference data that is owned elsewhere, meaning they are cheap to copy.
### Characteristics: ###
- **Non-Owning:** Views reference data owned elsewhere, meaning they are cheap to copy.
- **Lazy Computation:** They compute their elements on-the-fly as you iterate through them.
- **Composable:** Multiple views can be composed together to form complex data processing pipelines.
- **Composable:** Multiple views can be composed to form complex data processing pipelines.

An example of a view is `std::ranges::filter_view`, which takes a range and a predicate and returns a view that only includes elements for which the predicate returns `true`:

Expand All @@ -30,8 +30,8 @@ An example of a view is `std::ranges::filter_view`, which takes a range and a pr
for (int n : even_nums) std::cout << n << ' '; // prints 2 4
```

## Range Adaptors
Range **Adaptors** are functions that take one or more ranges as input and produce a new view. They adapt a range by transforming it in some way, such as filtering elements or transforming them.
## Range Adaptors ##
Range **Adaptors** are functions that take one or more ranges as input and produce a new view. They adapt a range by transforming it, such as filtering elements or transforming them.
They can be piped, i.e. chained together, to create complex data processing pipelines. Practically for every view there is a corresponding range adaptor. For instance, the `std::ranges::filter_view` view has a corresponding `std::ranges::views::filter` range adaptor. The previous example may be rewritten as:

```c++
Expand Down Expand Up @@ -62,7 +62,7 @@ But you can do more complex stuff:
### Common Range Adaptors:
- `views::filter`: Creates a view that includes only elements for which a predicate returns `true`.
- `views::transform`: Applies a function to each element of a range and returns a view of the results.
- `views::transform`: Applies a function to each range element and returns a view of the results.
- `views::take`: Produces a view consisting of the first `n` elements of the input range.
- `views::drop`: Creates a view that skips the first `n` elements of the input range.
- `views::reverse`: Produces a view with the elements of the range in reverse order.
Expand Down Expand Up @@ -101,12 +101,13 @@ Yet, they can still work with an iterator-sentinel pair if needed, offering flex
// Constrained algorithm with a projection (comparison operator is still required, but here we use the default less-than)
std::ranges::sort(range, {}, [](int a) { return std::abs(a); });// the projector is the third argument
```
Projection can also be adopted to specify the element to be used in the algorithm. For instance, in the following example we sort a vector of pairs by the second element of the pair:
Projection can also be adopted to specify the element used in the algorithm. For instance, in the following example, we sort a vector of pairs by the second element of the pair:

```cpp
std::vector<std::pair<int, int>> v = {{1, 2}, {2, 1}, {3, 3}};
std::ranges::sort(v, {}, [](auto p) { return p.second; });
```
- **Pointer-to-Member Callables**: These algorithms support pointer-to-member callables, which can be used to specify operations on member variables of class objects within a range.
- **Pointer-to-Member Callables**: These algorithms support pointer-to-member callables, which can specify operations on member variables of class objects within a range.
An example:
```cpp
struct Person {
Expand Down Expand Up @@ -185,7 +186,7 @@ auto even_nums_vec = range_to_vector(even_nums);// use the view to build a vecto
...
```

# What do I learn here ?
# What do I learn here ? #
- The use of a very recent addition to the C++ language
- A new way of handling containers and algorithm. Cleaner and more effective. It will probably rapidly become the normal way of programming with the containers of the standard library in modern C++;

2 changes: 1 addition & 1 deletion Extras/json
Submodule json updated 251 files
2 changes: 1 addition & 1 deletion Extras/muparser
2 changes: 1 addition & 1 deletion Extras/pybind11
Submodule pybind11 updated 170 files

0 comments on commit 98e516c

Please sign in to comment.