18
18
import * as seedrandom from 'seedrandom' ;
19
19
20
20
import { ENGINE } from '../../engine' ;
21
- import { ENV } from '../../environment' ;
21
+ import { env } from '../../environment' ;
22
+
22
23
import { warn } from '../../log' ;
23
24
import * as array_ops_util from '../../ops/array_ops_util' ;
24
25
import * as axis_util from '../../ops/axis_util' ;
@@ -92,7 +93,7 @@ export class MathBackendCPU implements KernelBackend {
92
93
private firstUse = true ;
93
94
94
95
constructor ( ) {
95
- if ( ENV . get ( 'IS_BROWSER' ) ) {
96
+ if ( env ( ) . get ( 'IS_BROWSER' ) ) {
96
97
const canvas = createCanvas ( ) ;
97
98
if ( canvas !== null ) {
98
99
this . fromPixels2DContext =
@@ -105,7 +106,7 @@ export class MathBackendCPU implements KernelBackend {
105
106
register ( dataId : DataId , shape : number [ ] , dtype : DataType ) : void {
106
107
if ( this . firstUse ) {
107
108
this . firstUse = false ;
108
- if ( ENV . get ( 'IS_NODE' ) ) {
109
+ if ( env ( ) . get ( 'IS_NODE' ) ) {
109
110
warn (
110
111
'\n============================\n' +
111
112
'Hi there 👋. Looks like you are running TensorFlow.js in ' +
@@ -154,7 +155,7 @@ export class MathBackendCPU implements KernelBackend {
154
155
[ pixels . width , pixels . height ] ;
155
156
let vals : Uint8ClampedArray | Uint8Array ;
156
157
// tslint:disable-next-line:no-any
157
- if ( ENV . get ( 'IS_NODE' ) && ( pixels as any ) . getContext == null ) {
158
+ if ( env ( ) . get ( 'IS_NODE' ) && ( pixels as any ) . getContext == null ) {
158
159
throw new Error (
159
160
'When running in node, pixels must be an HTMLCanvasElement ' +
160
161
'like the one returned by the `canvas` npm package' ) ;
@@ -828,7 +829,8 @@ export class MathBackendCPU implements KernelBackend {
828
829
const newValues = this . readSync ( result . dataId ) as TypedArray ;
829
830
let index = 0 ;
830
831
const offset = condition . rank === 0 || condition . rank > 1 || a . rank === 1 ?
831
- 1 : util . sizeFromShape ( a . shape . slice ( 1 ) ) ;
832
+ 1 :
833
+ util . sizeFromShape ( a . shape . slice ( 1 ) ) ;
832
834
833
835
for ( let i = 0 ; i < values . length ; i ++ ) {
834
836
for ( let j = 0 ; j < offset ; j ++ ) {
@@ -1522,9 +1524,10 @@ export class MathBackendCPU implements KernelBackend {
1522
1524
const sign = Math . sign ( values [ i ] ) ;
1523
1525
const v = Math . abs ( values [ i ] ) ;
1524
1526
const t = 1.0 / ( 1.0 + p * v ) ;
1525
- resultValues [ i ] = sign * ( 1.0 -
1526
- ( ( ( ( ( a5 * t + a4 ) * t ) + a3 ) * t + a2 ) * t + a1 ) * t *
1527
- Math . exp ( - v * v ) ) ;
1527
+ resultValues [ i ] = sign *
1528
+ ( 1.0 -
1529
+ ( ( ( ( ( a5 * t + a4 ) * t ) + a3 ) * t + a2 ) * t + a1 ) * t *
1530
+ Math . exp ( - v * v ) ) ;
1528
1531
}
1529
1532
return Tensor . make ( x . shape , { values : resultValues } ) ;
1530
1533
}
0 commit comments