Skip to content

Commit

Permalink
some test classes/objects
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsingh91 committed Jan 1, 2024
1 parent e83f0c6 commit 2bc3b5e
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 0 deletions.
106 changes: 106 additions & 0 deletions benchmark/sandbox/test1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <iostream>
#include <stdio.h>
#include "pinocchio/parsers/sample-models.hpp"
#include "pinocchio/algorithm/joint-configuration.hpp"
#include "pinocchio/algorithm/rnea.hpp"
#include <Eigen/Dense>


using namespace std;
using namespace pinocchio;

class fun: serialization::Serializable<fun>{

private:
int num1;

public:
fun(int n):num1{n}{cout << "calling fun constructor!" << endl;};
void print_num1(){cout << "num1 = " << num1 << endl;}
void set_num1(int n){num1=n;};

~fun(){cout << "calling fun destructor!" << endl;};

};

int main(){


pinocchio::Model model;
buildModels::humanoidRandom(model,true);
Data data(model);

Eigen::VectorXd q = pinocchio::neutral(model);
Eigen::VectorXd v = Eigen::VectorXd::Random(model.nv);
Eigen::VectorXd a = Eigen::VectorXd::Zero(model.nv);

const Eigen::VectorXd & tau = pinocchio::rnea(model,data,q,v,a);
std::cout << "tau = " << tau.transpose() << std::endl;

// ...Testing some data structures...

// cout << "model njoints = " << model.njoints << endl;


// Testng serializable derived objects
fun f1{56};
f1.set_num1(12);
f1.print_num1();

serialization::Serializable<fun> f2;

// testing JointCollectionDefaultTpl

JointCollectionDefaultTpl<float,0> ::JointModelRX j1;
auto data1 = j1.createData();
Eigen::VectorXd v1(3);

j1.calc(data1,v1);
cout << j1.classname() << endl;

// testing SE3 class objects

cout << "---------------------------------" << endl;

SE3Tpl<double,0> s1;

Eigen::Quaterniond quat(1.0,1.0,1.0,0.0);
Eigen::Vector3d trans(1.0,2.0,3.0);

SE3Tpl<double> s2(quat, trans);

cout << "s2 rot = " << s2.rotation() << endl;
cout << "s2 trans = " << s2.translation() << endl;

cout << "s2 homo = " << s2.toHomogeneousMatrix() << endl;

pinocchio::traits< SE3Tpl<double,0>>::ActionMatrixType action_matrix = s2;
cout << "action_matrix-1 = " << action_matrix << endl;

cout << "to action matrix-2 =" << s2.toActionMatrix() << endl;
cout << "to action matrix-3 =" << s2.toActionMatrix_impl() << endl;

Eigen::Vector3d vec1{1.0,2.0,1.0};
cout << "action on vec1 = \n" << s2.actOnEigenObject(vec1) << endl;


cout << "------------------------- Testing ForceTpl------------------------" << endl;

// pinocchio::ForceBase<ForceDense<ForceTpl<double,0>>> f3; // causing error
pinocchio::ForceDense<ForceTpl<double,0>> f3;
f3.setRandom();
cout << "f3 linear part = \n" << f3.linear() << endl;
// cout << "f3 angular part =" << f3.angular() << endl;









return 0;


}
Binary file added benchmark/sandbox/test1_c
Binary file not shown.
64 changes: 64 additions & 0 deletions benchmark/sandbox/test2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdio.h>
#include <iostream>

using namespace std;

template <typename T>
class Ability{

public:
T strength, hit;
Ability(T n, T m):strength{n}, hit{m}{};
void get_ability(){
cout << "strength , hit =" << strength << ", " << hit << endl;
}


};

template <typename T>
class Warrior{

public:
T power, health;
Warrior(T n,T m):power{n},health{m}{};
void print_stat(){
cout << "power, health = " << power << ", " << health << endl;
}
static void fun1(){
cout << "this is inside the fun1" << endl;
}
~Warrior(){};

typedef Ability<T> ability;

};



int main(){

typedef Warrior<float> Saint;
typedef Warrior<int> Archer;
typedef Warrior<double> Sepoy;

Saint s{12.4,5.4};
Archer a{34,67};
Sepoy b{12.3,54.1};

s.print_stat();
a.print_stat();
b.print_stat();

s.fun1();
Warrior<float>::fun1();

Saint::ability s_ab(23.1,45.1);
s_ab.get_ability();





return 0;
}
Binary file added benchmark/sandbox/test2_c
Binary file not shown.
Binary file added benchmark/sandbox/test3
Binary file not shown.
44 changes: 44 additions & 0 deletions benchmark/sandbox/test3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// template specialization

#include <iostream>
#include <stdio.h>
using namespace std;

template <typename T>
class Nums{

public:
T num1, num2;
Nums(){};
void print_nums(){
cout << "type of num1 and num2 = " << typeid(num1).name() << endl;
}

};

// class template specialization for int
template <>
class Nums<int>{
public:
int num1, num2;
Nums(int n, int m):num1{n},num2{m}{};
void print_nums(){
cout << "type of num1 and num2 is integer " << endl;
}

};

int main(){

Nums<double> n;
n.print_nums();

Nums<float> m;
m.print_nums();

Nums<int> p(12,4);
p.print_nums();


return 0;
}
Binary file added benchmark/sandbox/test4
Binary file not shown.
40 changes: 40 additions & 0 deletions benchmark/sandbox/test4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <iostream>
using namespace std;

template <typename T>
class test{

public:
template <typename U>
void myfun(U var)
{
std::cout << "value of var is = " << var << endl;
}



};

// template specialization
template<>
template<> // need 2 template keywords since specialized for the class and function
void test<int>::myfun<double>(double var){
std::cout << "Value of var for double now is " << var << endl;
}


int main(){


test<int> intstance;
test<double> doubstance;

intstance.myfun(12);
intstance.myfun(34.1);

intstance.template myfun(56.1);



}

0 comments on commit 2bc3b5e

Please sign in to comment.