Skip to content

Commit

Permalink
Merge branch 'markrogoyski:master' into moore-penrose
Browse files Browse the repository at this point in the history
  • Loading branch information
Aweptimum authored Aug 24, 2023
2 parents 01f8817 + ea4f212 commit a610dfa
Show file tree
Hide file tree
Showing 85 changed files with 450 additions and 342 deletions.
46 changes: 39 additions & 7 deletions .github/workflows/test_develop_and_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
test-and-static-analysis:
name: Test and Static Analysis
name: Test and Lint
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -23,12 +23,12 @@ jobs:
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -54,10 +54,42 @@ jobs:
./vendor/bin/phpunit --configuration tests/phpunit.xml --testsuite=LinearAlgebra
- name: PHP Code Sniffer
run: ./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
run: |
./vendor/bin/phpcs --version
./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2']

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run Composer
run: composer install --no-interaction

- name: Static analysis
run: ./vendor/bin/phpstan analyze --level max src/
run: |
./vendor/bin/phpstan --version
./vendor/bin/phpstan analyze -c tests/phpstan.neon
code-coverage:
name: Code coverage
Expand All @@ -75,12 +107,12 @@ jobs:
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down
44 changes: 38 additions & 6 deletions .github/workflows/test_other_branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- master

jobs:
test-and-static-analysis:
name: Test and Static Analysis
test-and-lint:
name: Test and Lint
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -22,12 +22,12 @@ jobs:
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -53,7 +53,39 @@ jobs:
./vendor/bin/phpunit --configuration tests/phpunit.xml --testsuite=LinearAlgebra
- name: PHP Code Sniffer
run: ./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
run: |
./vendor/bin/phpcs --version
./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2']

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run Composer
run: composer install --no-interaction

- name: Static analysis
run: ./vendor/bin/phpstan analyze --level max src/
run: |
./vendor/bin/phpstan --version
./vendor/bin/phpstan analyze -c tests/phpstan.neon
46 changes: 39 additions & 7 deletions .github/workflows/test_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: pull_request

jobs:
test-and-static-analysis:
name: Test and Static Analysis
name: Test and Lint
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -19,12 +19,12 @@ jobs:
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -50,10 +50,42 @@ jobs:
./vendor/bin/phpunit --configuration tests/phpunit.xml --testsuite=LinearAlgebra
- name: PHP Code Sniffer
run: ./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
run: |
./vendor/bin/phpcs --version
./vendor/bin/phpcs --ignore=vendor --standard=tests/coding_standard.xml -s .
static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2']

steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run Composer
run: composer install --no-interaction

- name: Static analysis
run: ./vendor/bin/phpstan analyze --level max src/
run: |
./vendor/bin/phpstan --version
./vendor/bin/phpstan analyze -c tests/phpstan.neon
code-coverage:
name: Code coverage
Expand All @@ -71,12 +103,12 @@ jobs:
tools: composer:v2

- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# MathPHP Change Log

## v2.8.0 - TBD
## v2.8.1 - 2023-05-18

### Improvements
* Internal improvements to improve conformance with static analysis tools

## v2.8.0 - 2023-05-07

### New Features
* Matrix `rowAddVector`
* Matrix `columnAddVector`

### Improvements
* Better error handling and exception message in `Sequence\NonIntenger::hyperharmonic`
* Internal code improvements to conform to static analysis checks

### Improvements
### Backwards Incompatible Changes
* Helper method names changed (public abstract methods but not part of published interface)
* `NumericalDifferentiation::isTargetInPoints` changed to `assertTargetInPoints`
* `NumericalDifferentiation::isSpacingConstant` changed to `assertSpacingConstant`

## v2.7.0 - 2022-12-31

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ style :
vendor/bin/phpcs --standard=tests/coding_standard.xml --ignore=vendor -s .

phpstan :
vendor/bin/phpstan analyze --level max src/
vendor/bin/phpstan analyze -c tests/phpstan.neon

phpmd :
vendor/bin/phpmd src/ ansi cleancode,codesize,design,unusedcode,naming
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ $f’⟮x⟯ = function ($x) {
};
[$start, $end, $n] = [0, 3, 4];

$p = Interpolation\ClampedCubicSpline::interpolate($points); // input as a set of points
$p = Interpolation\ClampedCubicSpline::interpolate($points); // input as a set of points
$p = Interpolation\ClampedCubicSpline::interpolate($f⟮x⟯, $f’⟮x⟯, $start, $end, $n); // input as a callback function

$p(0); // 1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"phpunit/phpunit": "^8.5",
"php-coveralls/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "3.*",
"phpstan/phpstan": "*",
"phpstan/phpstan": "^1.10",
"phpmd/phpmd": "^2.6",
"phploc/phploc": "*",
"php-parallel-lint/php-parallel-lint": "^1.2"
Expand Down
9 changes: 5 additions & 4 deletions src/Algebra.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static function extendedGcd(int $a, int $b): array
* @param int $b
*
* @return int
* @psalm-suppress InvalidReturnType (Change to intdiv for PHP 8.0)
*/
public static function lcm(int $a, int $b): int
{
Expand Down Expand Up @@ -236,7 +237,7 @@ public static function linear(float $a, float $b): ?float
* @param float $c constant coefficient
* @param bool $return_complex Whether to return complex numbers or NANs if imaginary roots
*
* @return array{0: float|Complex, 1?: float|Complex}
* @return float[]|Complex[]
* [x₁, x₂] roots of the equation, or
* [NAN, NAN] if discriminant is negative, or
* [Complex, Complex] if discriminant is negative and complex option is on or
Expand Down Expand Up @@ -367,7 +368,7 @@ public static function discriminant(float $a, float $b, float $c): float
* @param float $a₀ constant coefficient
* @param bool $return_complex whether to return complex numbers
*
* @return array{0: float|Complex, 1?: float|Complex, 2?: float|Complex}
* @return float[]|Complex[]
* array of roots (three real roots, or one real root and two NANs because complex numbers not yet supported)
* (If $a₃ = 0, then only two roots of quadratic equation)
*
Expand Down Expand Up @@ -532,8 +533,8 @@ public static function quartic(float $a₄, float $a₃, float $a₂, float $a
// The roots for this polynomial are the roots of the depressed polynomial minus a₃/4.
if (!$return_complex) {
/**
* FIXME: are the roots real? Single::subtract() works with real numbers only.
* @phpstan-ignore-next-line
* @phpstan-ignore-next-line (Single::subtract() works with real numbers only, must be real roots)
* @psalm-suppress InvalidArgument
*/
return Single::subtract($depressed_quartic_roots, $a₃ / 4);
}
Expand Down
1 change: 0 additions & 1 deletion src/Expression/Piecewise.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function __construct(array $intervals, array $functions)
$lastB = $b ?? -\INF;
$lastBOpen = $bOpen ?? false;

// @phpstan-ignore-next-line (Strict comparison using !== between 2 and 2 will always evaluate to false.)
if (\count(\array_filter($interval, '\is_numeric')) !== 2) {
throw new Exception\BadDataException('Each interval must contain two numbers.');
}
Expand Down
8 changes: 4 additions & 4 deletions src/Expression/Polynomial.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Polynomial implements ObjectArithmetic
/** @var int */
private $degree;

/** @var array<number> */
/** @var array<int|float> */
private $coefficients;

/** @var string */
Expand All @@ -71,7 +71,7 @@ class Polynomial implements ObjectArithmetic
* When a polynomial is instantiated, set the coefficients and degree of
* that polynomial as its object parameters.
*
* @param array<number> $coefficients An array of coefficients in decreasing powers
* @param array<int|float> $coefficients An array of coefficients in decreasing powers
* Example: new Polynomial([1, 2, 3]) will create
* a polynomial that looks like x² + 2x + 3.
* @param string $variable
Expand Down Expand Up @@ -215,7 +215,7 @@ private function checkNumericOrPolynomial($input): Polynomial
if ($input instanceof Polynomial) {
return $input;
} elseif (\is_numeric($input)) {
/** @var number $input */
/** @var int|float $input */
return new Polynomial([$input]);
} else {
throw new Exception\IncorrectTypeException('Input must be a Polynomial or a number');
Expand All @@ -235,7 +235,7 @@ public function getDegree(): int
/**
* Getter method for the coefficients of a polynomial
*
* @return array<number> The coefficients array of a polynomial object
* @return array<int|float> The coefficients array of a polynomial object
*/
public function getCoefficients(): array
{
Expand Down
Loading

0 comments on commit a610dfa

Please sign in to comment.