template<typename Scalar, int Dim, int Options> void transform_products()
{
  typedef Matrix<Scalar,Dim+1,Dim+1> Mat;
  typedef Transform<Scalar,Dim,Projective,Options> Proj;
  typedef Transform<Scalar,Dim,Affine,Options> Aff;
  typedef Transform<Scalar,Dim,AffineCompact,Options> AffC;

  Proj p; p.matrix().setRandom();
  Aff a; a.linear().setRandom(); a.translation().setRandom();
  AffC ac = a;

  Mat p_m(p.matrix()), a_m(a.matrix());

  VERIFY_IS_APPROX((p*p).matrix(), p_m*p_m);
  VERIFY_IS_APPROX((a*a).matrix(), a_m*a_m);
  VERIFY_IS_APPROX((p*a).matrix(), p_m*a_m);
  VERIFY_IS_APPROX((a*p).matrix(), a_m*p_m);
  VERIFY_IS_APPROX((ac*a).matrix(), a_m*a_m);
  VERIFY_IS_APPROX((a*ac).matrix(), a_m*a_m);
  VERIFY_IS_APPROX((p*ac).matrix(), p_m*a_m);
  VERIFY_IS_APPROX((ac*p).matrix(), a_m*p_m);
}
Exemplo n.º 2
0
/*!
 * This function does the processing for the c_elegans class.
 *
 * It initializes the various matrices and reads values from the input files
 */
void c_elegans::postprocess(input& in){
    rhs_type::postprocess(in);
    if(dimension != num_neur*2){
        err("Dimension must be 558, which is double the number of neurons",
                "", "", FATAL_ERROR);
    }
    in.retrieve(beta, "beta", this);
    in.retrieve(tau, "tau", this);
    in.retrieve(gelec, "gelec", this);
    in.retrieve(gchem, "gchem", this);
    in.retrieve(memV, "memV", this);
    in.retrieve(memG, "memG", this);
    in.retrieve(EchemEx, "EchemEx", this);
    in.retrieve(EchemInh, "EchemInh", this);
    in.retrieve(ar, "ar", this);
    in.retrieve(ad, "ad", this);
    std::string ag_fname, a_fname;
    in.retrieve(ag_fname, "ag_mat", this);
    in.retrieve(a_fname, "a_mat", this);
    sparse_type a_m(num_neur, num_neur);
    ag_full.resize(num_neur, num_neur);
    laplacian.resize(num_neur, num_neur);
    read_mat(ag_fname, ag_full);
    read_mat(a_fname, a_m);
    //create transposed sparse matrix AEchem
    AEchem_trans_full.resize(num_neur, num_neur);
    AEchem_trans_full = a_m.transpose();
    AEchem_trans.resize(num_neur, num_neur);
    //do any needed fake iterations, must make more general at some point
    size_t num_comb;
    int iterations;
    in.retrieve(num_comb, "num_comb", this);
    in.retrieve(iterations, "iterations", this);
    in.retrieve(cur_ind, "!start_ind", this);
    abl_neur.resize(num_comb);
    for(auto& val : abl_neur){
        val = 0;
    } 
    if(abl_neur.size() != 1){
        next_comb(abl_neur, num_neur);
    }
    for(int i = 0; i < cur_ind; i++){
        for(int j = 0; j < iterations; j++){
            if(next_comb(abl_neur, num_neur)){
                char ind_str[20];//won't ever have a 20 digit index
                //handy buffer to overflow for those hacking this.
                sprintf(ind_str, "%d", (int)cur_ind);
                err(std::string("Combinations exhausted in index ") + ind_str,
                        "c_elegans::postprocess","rhs/c_elegans.cpp", FATAL_ERROR);
            }
        }
    }
    auto dat_inds =
        std::shared_ptr<writer>(new writer(true));
    dat_inds->add_data(data::create("Ablations", abl_neur.data(), abl_neur.size()), writer::OTHER);
    holder->add_writer(dat_inds);

    //write first ablation data

    //set up dummy connection to toroidal controller for now
    controller* cont;
    in.retrieve(cont, "controller", this);
    auto val = std::make_shared<variable>();
    val->setname("c_elegans_quickfix");
    val->holder = holder;
    val->parse("0.1");
    in.insert_item(val);
    cont->addvar(val);
    in.retrieve(dummy, val->name(), this);
    has_gone=true; //is true at first to allow update of zero index to occur
    first_round=true;
    update();
}