@@ -594,7 +594,18 @@ void lstm_forward_propagate(lstm_model_t* model, double * input, lstm_values_cac
594594 F = model -> F ;
595595 S = model -> S ;
596596
597- double tmp [N ]; // VLA must be supported.. May cause portability problems.. If so use init_zeros_vector (will be slower).
597+ #ifdef WINDOWS
598+ // MSVC is not a C99 compiler, and does not support variable length arrays
599+ // MSVC is documented as conforming to C90
600+ double * tmp ;
601+ if ( init_zero_vector (& tmp , N ) ) {
602+ fprintf (stderr , "%s.%s.%d init_zero_vector(.., %d) failed\r\n" ,
603+ __FILE__ , __func__ , __LINE__ , N );
604+ exit (1 );
605+ }
606+ #else
607+ double tmp [N ]; // VLA must be supported.. May cause portability problems.. If so use init_zero_vector (will be slower).
608+ #endif
598609
599610 copy_vector (cache_out -> h_old , h_old , N );
600611 copy_vector (cache_out -> c_old , c_old , N );
@@ -650,6 +661,10 @@ void lstm_forward_propagate(lstm_model_t* model, double * input, lstm_values_cac
650661
651662 copy_vector (cache_out -> X , X_one_hot , S );
652663
664+ #ifdef WINDOWS
665+ free_vector (& tmp );
666+ #endif
667+
653668}
654669// model, y_probabilities, y_correct, the next deltas, state and cache values, &gradients, &the next deltas
655670void lstm_backward_propagate (lstm_model_t * model , double * y_probabilities , int y_correct , lstm_values_next_cache_t * d_next , lstm_values_cache_t * cache_in , lstm_model_t * gradients , lstm_values_next_cache_t * cache_out )
@@ -925,14 +940,28 @@ void lstm_output_string_layers_to_file(FILE * fp,lstm_model_t ** model_layers, s
925940{
926941 lstm_values_cache_t * * * caches_layer ;
927942 int i = 0 , count , index , p = 0 , b = 0 ;
928- char input = set_char_to_indx (char_index_mapping , first );
943+ int input = set_indx_to_char (char_index_mapping , first );
929944 int F = model_layers [0 ]-> F ;
930945 int N = model_layers [0 ]-> N ;
946+ #ifdef WINDOWS
947+ double * first_layer_input ;
948+ #else
931949 double first_layer_input [F ];
950+ #endif
932951
933952 if ( fp == NULL )
934953 return ;
935954
955+ #ifdef WINDOWS
956+ first_layer_input = malloc (F * sizeof (double ));
957+
958+ if ( first_layer_input == NULL ) {
959+ fprintf (stderr , "%s.%s.%d malloc(%zu) failed\r\n" ,
960+ __FILE__ , __func__ , __LINE__ , F * sizeof (double ));
961+ exit (1 );
962+ }
963+ #endif
964+
936965 caches_layer = calloc (layers , sizeof (lstm_values_cache_t * * ));
937966
938967 if ( caches_layer == NULL )
@@ -996,17 +1025,35 @@ void lstm_output_string_layers_to_file(FILE * fp,lstm_model_t ** model_layers, s
9961025 }
9971026
9981027 free (caches_layer );
1028+ #ifdef WINDOWS
1029+ free (first_layer_input );
1030+ #endif
1031+
9991032}
10001033
10011034
10021035void lstm_output_string_layers (lstm_model_t * * model_layers , set_T * char_index_mapping , int first , int numbers_to_display , int layers )
10031036{
10041037 lstm_values_cache_t * * * caches_layer ;
10051038 int i = 0 , count , index , p = 0 , b = 0 ;
1006- char input = set_char_to_indx (char_index_mapping , first );
1039+ int input = set_indx_to_char (char_index_mapping , first );
10071040 int F = model_layers [0 ]-> F ;
10081041 int N = model_layers [0 ]-> N ;
1009- double first_layer_input [F ];
1042+ #ifdef WINDOWS
1043+ double * first_layer_input ;
1044+ #else
1045+ double first_layer_input [F ];
1046+ #endif
1047+
1048+ #ifdef WINDOWS
1049+ first_layer_input = malloc (F * sizeof (double ));
1050+
1051+ if ( first_layer_input == NULL ) {
1052+ fprintf (stderr , "%s.%s.%d malloc(%zu) failed\r\n" ,
1053+ __FILE__ , __func__ , __LINE__ , F * sizeof (double ));
1054+ exit (1 );
1055+ }
1056+ #endif
10101057
10111058 caches_layer = calloc (layers , sizeof (lstm_values_cache_t * * ));
10121059
@@ -1037,6 +1084,11 @@ void lstm_output_string_layers(lstm_model_t ** model_layers, set_T* char_index_m
10371084 ++ count ;
10381085 }
10391086
1087+ if ( index < 0 ) {
1088+ index = 0 ;
1089+ printf ("%s.%s unexpected input char: '%c', (%d)\r\n" , __FILE__ , __func__ , input , input );
1090+ }
1091+
10401092 first_layer_input [index ] = 1.0 ;
10411093
10421094 p = layers - 1 ;
@@ -1071,6 +1123,9 @@ void lstm_output_string_layers(lstm_model_t ** model_layers, set_T* char_index_m
10711123 }
10721124
10731125 free (caches_layer );
1126+ #ifdef WINDOWS
1127+ free (first_layer_input );
1128+ #endif
10741129}
10751130
10761131void lstm_output_string_from_string_layers (lstm_model_t * * model_layers , set_T * char_index_mapping , char * input_string , int layers , int out_length )
@@ -1082,6 +1137,18 @@ void lstm_output_string_from_string_layers(lstm_model_t **model_layers, set_T* c
10821137
10831138 int p = 0 ;
10841139
1140+ #ifdef WINDOWS
1141+ double * first_layer_input = malloc (F * sizeof (double ));
1142+
1143+ if ( first_layer_input == NULL ) {
1144+ fprintf (stderr , "%s.%s.%d malloc(%zu) failed\r\n" ,
1145+ __FILE__ , __func__ , __LINE__ , F * sizeof (double ));
1146+ exit (1 );
1147+ }
1148+ #else
1149+ double first_layer_input [F ];
1150+ #endif
1151+
10851152 caches_layers = calloc (layers , sizeof (lstm_values_cache_t * * ));
10861153
10871154 if ( caches_layers == NULL ) {
@@ -1101,8 +1168,6 @@ void lstm_output_string_from_string_layers(lstm_model_t **model_layers, set_T* c
11011168 ++ p ;
11021169 }
11031170
1104- double first_layer_input [F ];
1105-
11061171 in_len = strlen (input_string );
11071172 i = 0 ;
11081173
@@ -1180,6 +1245,9 @@ void lstm_output_string_from_string_layers(lstm_model_t **model_layers, set_T* c
11801245 }
11811246
11821247 free (caches_layers );
1248+ #ifdef WINDOWS
1249+ free (first_layer_input );
1250+ #endif
11831251}
11841252
11851253void lstm_store_progress (const char * filename , unsigned int n , double loss )
@@ -1245,7 +1313,17 @@ void lstm_train(lstm_model_t** model_layers, lstm_model_parameters_t *params, se
12451313 F = model_layers [0 ]-> F ;
12461314 S = model_layers [0 ]-> S ;
12471315
1248- double first_layer_input [F ];
1316+ #ifdef WINDOWS
1317+ double * first_layer_input = malloc (F * sizeof (double ));
1318+
1319+ if ( first_layer_input == NULL ) {
1320+ fprintf (stderr , "%s.%s.%d malloc(%zu) failed\r\n" ,
1321+ __FILE__ , __func__ , __LINE__ , F * sizeof (double ));
1322+ exit (1 );
1323+ }
1324+ #else
1325+ double first_layer_input [F ];
1326+ #endif
12491327
12501328 if ( stateful ) {
12511329 stateful_d_next = calloc (layers , sizeof (lstm_values_state_t * ));
@@ -1580,17 +1658,7 @@ to continue refining the weights.\n", params->store_network_name_raw);
15801658 free (gradient_layers );
15811659 free (M_layers );
15821660 free (R_layers );
1583-
1661+ #ifdef WINDOWS
1662+ free (first_layer_input );
1663+ #endif
15841664}
1585-
1586-
1587-
1588-
1589-
1590-
1591-
1592-
1593-
1594-
1595-
1596-
0 commit comments