Skip to content

Commit 640d25b

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents e83ac0b + 1f58fea commit 640d25b

File tree

4 files changed

+157
-19
lines changed

4 files changed

+157
-19
lines changed

lib/node_modules/@stdlib/_tools/scripts/create_ordered_pkg_list.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
/* eslint-disable no-sync, no-console */
19+
/* eslint-disable no-console, stdlib/no-internal-require */
2020

2121
'use strict';
2222

@@ -26,13 +26,15 @@ var join = require( 'path' ).join;
2626
var writeFileSync = require( '@stdlib/fs/write-file' ).sync;
2727
var ls = require( '@stdlib/_tools/pkgs/names' ).sync;
2828
var namespaceDeps = require( '@stdlib/_tools/pkgs/namespace-deps' );
29+
var standalonePackage = require( '@stdlib/_tools/pkgs/namespace-deps/lib/standalone_package.js' ); // FIXME: avoid requiring package internals
2930
var CompactAdjacencyMatrix = require( '@stdlib/utils/compact-adjacency-matrix/lib/main.js' );
3031
var indexOf = require( '@stdlib/utils/index-of' );
3132
var contains = require( '@stdlib/assert/contains' );
3233

3334

3435
// VARIABLES //
3536

37+
var standalonePkgs;
3638
var sorted;
3739
var pkgs;
3840
var deps;
@@ -46,15 +48,31 @@ var j;
4648

4749
pkgs = ls();
4850
console.log( 'Number of stdlib packages: '+pkgs.length );
51+
52+
standalonePkgs = new Array( pkgs.length );
53+
for ( i = 0; i < pkgs.length; i++ ) {
54+
standalonePkgs[ i ] = standalonePackage( pkgs[ i ] );
55+
}
4956
mat = new CompactAdjacencyMatrix( pkgs.length );
5057

5158
for ( i = 0; i < pkgs.length; i++ ) {
5259
console.log( 'Processing package: '+pkgs[ i ]+' (index: '+i+')' );
60+
if (
61+
pkgs[ i ] === '@stdlib/process/cwd' ||
62+
pkgs[ i ] === '@stdlib/process/node-version'
63+
) {
64+
continue;
65+
}
5366
try {
54-
deps = namespaceDeps( pkgs[ i ] );
67+
deps = namespaceDeps( pkgs[ i ], {
68+
'dev': false,
69+
'level': 999
70+
});
5571
for ( j = 0; j < deps.length; j++ ) {
56-
idx = indexOf( pkgs, deps[ j ] );
57-
if ( idx !== -1 && !contains( deps[ j ], '_tools' ) ) {
72+
idx = indexOf( standalonePkgs, deps[ j ] );
73+
if (
74+
idx !== -1 && !contains( deps[ j ], '_tools' )
75+
) {
5876
mat.addEdge( i, idx );
5977
}
6078
}
@@ -63,11 +81,22 @@ for ( i = 0; i < pkgs.length; i++ ) {
6381
}
6482
}
6583

84+
for ( let i = 0; i < pkgs.length; i++ ) {
85+
for ( let j = 0; j < pkgs.length; j++ ) {
86+
if (
87+
mat.hasEdge( i, j ) === mat.hasEdge( j, i ) &&
88+
mat.hasEdge( j, i ) === true
89+
) {
90+
console.log( 'Encountered cycle: ( '+pkgs[ i ]+', '+pkgs[ j ]+')' );
91+
}
92+
}
93+
}
94+
6695
console.log( 'Starting topological search...' );
6796
sorted = mat.toposort();
97+
6898
for ( i = 0; i < sorted.length; i++ ) {
6999
sorted[ i ] = pkgs[ sorted[ i ] ];
70100
}
71101

72102
writeFileSync( join( __dirname, './ordered.json' ), JSON.stringify( sorted, null, ' ' ).concat( '\n' ) );
73-

lib/node_modules/@stdlib/math/base/special/falling-factorial/lib/falling_factorial.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ var floor = require( '@stdlib/math/base/special/floor' );
4040
var abs = require( '@stdlib/math/base/special/abs' );
4141
var FLOAT64_MAX = require( '@stdlib/constants/math/float64-max' );
4242
var PINF = require( '@stdlib/constants/math/float64-pinf' );
43+
var risingFactorial = require( './rising_factorial.js' );
4344

4445

4546
// VARIABLES //
4647

4748
var MAX_FACTORIAL = 170; // TODO: consider packaging as constant
48-
var risingFactorial;
4949

5050

5151
// MAIN //
@@ -88,10 +88,6 @@ function fallingFactorial( x, n ) {
8888
var t1;
8989
var t2;
9090

91-
// Lazy-load to avoid undefined reference due to circular dependency...
92-
if ( !risingFactorial ) {
93-
risingFactorial = require( '@stdlib/math/base/special/rising-factorial' );
94-
}
9591
if ( isnan( x ) || !isNonNegativeInteger( n ) ) {
9692
return NaN;
9793
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*
19+
* ## Notice
20+
*
21+
* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_64_0/boost/math/special_functions/factorials.hpp}. The implementation has been modified for JavaScript.
22+
*
23+
* ```text
24+
* (C) Copyright John Maddock 2006, 2010.
25+
*
26+
* Use, modification and distribution are subject to the
27+
* Boost Software License, Version 1.0. (See accompanying file
28+
* LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
29+
* ```
30+
*/
31+
32+
'use strict';
33+
34+
// MODULES //
35+
36+
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
37+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
38+
var gammaDeltaRatio = require( '@stdlib/math/base/special/gamma-delta-ratio' );
39+
var fallingFactorial = require( './falling_factorial.js' );
40+
41+
42+
// MAIN //
43+
44+
/**
45+
* Computes the rising factorial of `x` and `n`.
46+
*
47+
* ## Notes
48+
*
49+
* - The rising factorial is defined as
50+
*
51+
* ```tex
52+
* \operatorname{risingFactorial}(x, n) = x (x-1) (x-2) (x-3) \ldots (x-n+1)
53+
* ```
54+
*
55+
* or equivalently
56+
*
57+
* ```tex
58+
* \operatorname{risingFactorial}(x, n) = \frac{ \Gamma(x + n) }{ \Gamma(x) };
59+
* ```
60+
*
61+
* @param {number} x - first function parameter
62+
* @param {integer} n - second function parameter
63+
* @returns {number} function value
64+
*
65+
* @example
66+
* var v = risingFactorial( 0.9, 5 );
67+
* // returns ~94.766
68+
*
69+
* @example
70+
* var v = risingFactorial( -9.0, 3 );
71+
* // returns -504.0
72+
*
73+
* @example
74+
* var v = risingFactorial( 0.0, 2 );
75+
* // returns 0.0
76+
*
77+
* @example
78+
* var v = risingFactorial( 3.0, -2 );
79+
* // returns 0.5
80+
*/
81+
function risingFactorial( x, n ) {
82+
var result;
83+
var inv;
84+
85+
if ( isnan( x ) || !isInteger( n ) ) {
86+
return NaN;
87+
}
88+
if ( x < 0.0 ) {
89+
// For `x < 0`, we really have a falling factorial, modulo a possible change of sign. Note that the falling factorial isn't defined for negative `n`, so we'll get rid of that case first:
90+
if ( n < 0.0 ) {
91+
x += n;
92+
n = -n;
93+
inv = true;
94+
}
95+
result = ( (n&1) ? -1.0 : 1.0 ) * fallingFactorial( -x, n );
96+
if ( inv ) {
97+
result = 1.0 / result;
98+
}
99+
return result;
100+
}
101+
if ( n === 0 ) {
102+
return 1.0;
103+
}
104+
if ( x === 0.0 ) {
105+
if ( n < 0 ) {
106+
return -gammaDeltaRatio( x+1.0, -n );
107+
}
108+
return 0.0;
109+
}
110+
if ( x < 1.0 && x+n < 0.0 ) {
111+
result = gammaDeltaRatio( 1.0-x, -n );
112+
return ( n&1 ) ? -result : result;
113+
}
114+
// We don't optimize this for small `n`, because `gammaDeltaRatio` is already optimized for that use case:
115+
return 1.0 / gammaDeltaRatio( x, n );
116+
}
117+
118+
119+
// EXPORTS //
120+
121+
module.exports = risingFactorial;

lib/node_modules/@stdlib/math/base/special/rising-factorial/lib/rising_factorial.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@
3636
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
3737
var isnan = require( '@stdlib/math/base/assert/is-nan' );
3838
var gammaDeltaRatio = require( '@stdlib/math/base/special/gamma-delta-ratio' );
39-
40-
41-
// VARIABLES //
42-
43-
var fallingFactorial;
39+
var fallingFactorial = require( '@stdlib/math/base/special/falling-factorial' );
4440

4541

4642
// MAIN //
@@ -86,10 +82,6 @@ function risingFactorial( x, n ) {
8682
var result;
8783
var inv;
8884

89-
// Lazy-load to avoid undefined reference due to circular dependency...
90-
if ( !fallingFactorial ) {
91-
fallingFactorial = require( '@stdlib/math/base/special/falling-factorial' );
92-
}
9385
if ( isnan( x ) || !isInteger( n ) ) {
9486
return NaN;
9587
}

0 commit comments

Comments
 (0)