Skip to content

Commit 6cdb43e

Browse files
fix: update according to code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 0f64adc commit 6cdb43e

11 files changed

Lines changed: 20 additions & 25 deletions

File tree

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bench( pkg, function benchmark( b ) {
3838
var i;
3939

4040
len = 100;
41-
y = sample( [ -1, 1 ], {
41+
y = sample( [ -1.0, 1.0 ], {
4242
'size': len
4343
});
4444
p = uniform( len, -2.0, 2.0 );

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/benchmark/benchmark.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
4848
var i;
4949

5050
len = 100;
51-
y = sample( [ -1, 1 ], {
51+
y = sample( [ -1.0, 1.0 ], {
5252
'size': len
5353
});
5454
p = uniform( len, -2.0, 2.0 );

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/benchmark/c/native/benchmark.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ static double random_uniform( const double min, const double max ) {
9494
static double random_sample( void ) {
9595
double v = (double)rand() / ( (double)RAND_MAX );
9696
if ( v >= 0.5 ) {
97-
return 1;
97+
return 1.0;
9898
}
99-
return -1;
99+
return -1.0;
100100
}
101101

102102
/**

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/docs/repl.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Computes the hinge loss between two double-precision floating-point number.
44

55
If either argument is `NaN`, the function returns `NaN`.
6+
67
If `y` is not +1 or -1, the function returns `NaN`.
78

89
Parameters

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/docs/types/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import hinge = require( './index' );
5050
hinge( 1.0, ( x: number ): number => x ); // $ExpectError
5151
}
5252

53-
// The compiler throws an error if the function is provided insufficient arguments...
53+
// The compiler throws an error if the function is provided an unsupported number of arguments...
5454
{
5555
hinge(); // $ExpectError
5656
hinge( 1.0 ); // $ExpectError

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/include/stdlib/ml/base/loss/float64/hinge.h

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

19-
#ifndef STDLIB_ML_BASE_FLOAT64_HINGE_H
20-
#define STDLIB_ML_BASE_FLOAT64_HINGE_H
19+
#ifndef STDLIB_ML_BASE_LOSS_FLOAT64_HINGE_H
20+
#define STDLIB_ML_BASE_LOSS_FLOAT64_HINGE_H
2121

2222
/*
2323
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
@@ -35,4 +35,4 @@ double stdlib_base_float64_hinge( const double y, const double p );
3535
}
3636
#endif
3737

38-
#endif // !STDLIB_ML_BASE_FLOAT64_HINGE_H
38+
#endif // !STDLIB_ML_BASE_LOSS_FLOAT64_HINGE_H

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Compute the hinge loss between two double-precision floating-point number.
22+
* Compute the hinge loss between two double-precision floating-point numbers.
2323
*
2424
* @module @stdlib/ml/base/loss/float64/hinge
2525
*

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/lib/main.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
5959
* // returns 1.9
6060
*/
6161
function hinge( y, p ) {
62-
if ( isnan( y ) || isnan( p ) ) {
62+
if ( isnan( y ) || isnan( p ) || ( y !== -1.0 && y !== 1.0 ) ) {
6363
return NaN;
6464
}
65-
if ( y !== -1.0 && y !== 1.0 ) {
66-
return NaN;
67-
}
68-
return max( 0, 1 - ( y*p ) );
65+
return max( 0.0, 1.0 - ( y*p ) );
6966
}
7067

7168

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/ml/base/loss/float64/hinge",
33
"version": "0.0.0",
4-
"description": "Compute the hinge loss between two double-precision floating-point numbers.",
4+
"description": "Compute the hinge loss between two double-precision floating-point numberss.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

lib/node_modules/@stdlib/ml/base/loss/float64/hinge/src/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333
* // returns 0.798
3434
*/
3535
double stdlib_base_float64_hinge( const double y, const double p ) {
36-
if ( stdlib_base_is_nan( y ) || stdlib_base_is_nan( p ) ) {
36+
if ( stdlib_base_is_nan( y ) || stdlib_base_is_nan( p ) || ( y != -1.0 && y != 1.0 ) ) {
3737
return STDLIB_CONSTANT_FLOAT64_NAN;
3838
}
39-
if ( y != -1.0 && y != 1.0 ) {
40-
return STDLIB_CONSTANT_FLOAT64_NAN;
41-
}
42-
return stdlib_base_max( 0, 1 - ( y*p ) );
39+
return stdlib_base_max( 0.0, 1.0 - ( y*p ) );
4340
}

0 commit comments

Comments
 (0)