@@ -615,11 +615,12 @@ export default class RNN {
615615 }
616616 }
617617
618- return new Function ( 'input' , 'maxPredictionLength' , 'isSampleI' , 'temperature' , `
618+ const src = `
619619 if (typeof input === 'undefined') input = [];
620620 if (typeof maxPredictionLength === 'undefined') maxPredictionLength = 100;
621621 if (typeof isSampleI === 'undefined') isSampleI = false;
622622 if (typeof temperature === 'undefined') temperature = 1;
623+ ${ ( this . dataFormatter !== null ) ? this . dataFormatter . toFunctionString ( ) : '' }
623624
624625 ${
625626 ( this . dataFormatter !== null && typeof this . formatDataIn === 'function' )
@@ -677,24 +678,31 @@ ${ innerFunctionsSwitch.join('\n') }
677678 ${ ( this . dataFormatter !== null && typeof this . formatDataOut === 'function' )
678679 ? 'return formatDataOut(output.slice(input.length).map(function(value) { return value - 1; }))'
679680 : 'return output.slice(input.length).map(function(value) { return value - 1; })' } ;
680-
681681 function Matrix(rows, columns) {
682682 this.rows = rows;
683683 this.columns = columns;
684684 this.weights = zeros(rows * columns);
685685 }
686686 ${ this . dataFormatter !== null && typeof this . formatDataIn === 'function'
687- ? `function formatDataIn(input, output) { ${ toInner ( this . formatDataIn . toString ( ) ) . replace ( 'this.dataFormatter' , 'json.options.dataFormatter' ) } }`
687+ ? `function formatDataIn(input, output) { ${
688+ toInner ( this . formatDataIn . toString ( ) )
689+ . replace ( / t h i s [ . ] d a t a F o r m a t t e r [ . ] / g, '' )
690+ . replace ( / t h i s [ . ] d a t a F o r m a t t e r / g, 'true' )
691+ } }`
688692 : '' }
689693 ${ this . dataFormatter !== null && typeof this . formatDataOut === 'function'
690- ? `function formatDataOut(output) { ${ toInner ( this . formatDataIn . toString ( ) ) . replace ( 'this.dataFormatter' , 'json.options.dataFormatter' ) } }`
694+ ? `function formatDataOut(output) { ${
695+ toInner ( this . formatDataIn . toString ( ) )
696+ . replace ( / t h i s [ . ] d a t a F o r m a t t e r [ . ] / g, '' )
697+ . replace ( / t h i s [ . ] d a t a F o r m a t t e r / g, 'true' )
698+ } }`
691699 : '' }
692- ${ ( this . dataFormatter !== null ) ? this . dataFormatter . toFunctionString ( 'json.options.dataFormatter' ) : '' }
693700 ${ zeros . toString ( ) }
694701 ${ softmax . toString ( ) . replace ( '_2.default' , 'Matrix' ) }
695702 ${ randomF . toString ( ) }
696703 ${ sampleI . toString ( ) }
697- ${ maxI . toString ( ) } ` )
704+ ${ maxI . toString ( ) } ` ;
705+ return new Function ( 'rawInput' , 'maxPredictionLength' , 'isSampleI' , 'temperature' , src ) ;
698706 }
699707}
700708
0 commit comments