// file: tr_st_cstr_3.cc
//

// isip include files
//
#include "train_state.h"
#include "train_state_constants.h"
 
// method: constructor
//
// arguments:
//  const Train_State& state: (input) copy state
//
// return: none
//
// this is the copy constructor for the class
//
Train_State::Train_State(const Train_State& state_a) {
  
  // set the number of mixtures
  //
  num_mixtures_d = state_a.num_mixtures_d;

  // allocate memory for mixture weights and copy data
  //
  if (weights_d != (float_4*)NULL) {
    delete [] weights_d;
    weights_d = (float_4*)NULL;
  }
  weights_d = new float_4[num_mixtures_d];
  memcpy(weights_d, state_a.weights_d, num_mixtures_d * sizeof(float_4));
  
  // allocate memory for scale factors and copy data
  //
  if (scale_d != (float_4*)NULL) {
    delete [] scale_d;
    scale_d = (float_4*)NULL;
  }
  scale_d = new float_4[num_mixtures_d];
  memcpy(scale_d, state_a.scale_d, num_mixtures_d * sizeof(float_4));
  
  // free memory in mean
  //
  if (mean_d != (float_4**)NULL) {
    for (int_4 i = 0; i < num_mixtures_d; i++) {
      if (mean_d[i] != (float_4*)NULL) {
        delete [] mean_d[i];
        mean_d[i] = (float_4*)NULL;
      }
    }
    delete [] mean_d;
    mean_d = (float_4**)NULL;
  }
  
  mean_d = new float_4*[num_mixtures_d];
  for (int_4 i = 0; i < num_mixtures_d; i++) {
    mean_d[i] = new float_4[num_features_d];
  }
  memcpy(mean_d, state_a.mean_d, num_mixtures_d * num_features_d *
	 sizeof(float_4));
  
  // free memory in covar
  //
  if (covar_d != (float_4**)NULL) {
    for (int_4 i = 0; i < num_mixtures_d; i++) {
      if (covar_d[i] != (float_4*)NULL) {
        delete [] covar_d[i];
        covar_d[i] = (float_4*)NULL;
      }
    }
    delete [] covar_d;
    covar_d = (float_4**)NULL;
  }
  
  covar_d = new float_4*[num_mixtures_d];
  for (int_4 i = 0; i < num_mixtures_d; i++) {
    covar_d[i] = new float_4[num_features_d];
  }
  memcpy(covar_d, state_a.covar_d, num_mixtures_d * num_features_d *
	 sizeof(float_4));
  
  // initialize the frame and score
  //
  frame_d = state_a.frame_d;
  score_d = state_a.score_d;
  state_index_d = state_a.state_index_d;
    
  // exit gracefully
  //
}
