Return to Snippet

Revision: 24835
at March 12, 2010 05:00 by somada141


Initial Code
#include <iostream>

/*
 Here we use the TNT library which contains headers for 1D,2D & 3D arrays supporting both C and FORTRAN 
 style arrays. The classes are templated allowing any array types. Moreover the classes support overloaded
 operators for common operations
*/
#include "tnt.h" //this is the only necessary header to use the entire library. However it is possible to only use the
 				 //needed headers depending on the desired functionality.

int main (int argc, char * const argv[]) {
	/* TNT::Stopwatch */
	TNT::Stopwatch timer1; //using TNT's 'Stopwatch' class to create a timer
	timer1.start();	//using the 'start' function of the timer to start counting time
	
	
	//use TNT's 'Array2D' class to create 3 30x30 arrays of which the first two are filled with the
	//value '2.0' while the 3rd is full of zeros
	TNT::Array2D<int> num(5,5,2.0); 
	TNT::Array2D<int> num2(5,5,2.0);
	TNT::Array2D<int> num3(5,5,0.0);
	
	std::cout<<num[0][0]<<"n"; //access a specific value in the matrix
	
	num3=num2*num; //element-wise multiplication of the two arrays using the overloaded '*' operator
	
	std::cout << num3 <<"n"; //using the overloaded operator '<<' to print the dimensions and contents of the array

	//using the 'matmult' function to multiply two matrices and then we print the result
	std::cout << TNT::matmult(num,num2) <<"n"; 
	
	std::cout<< num.subarray(1, 3, 1, 3); //using the 'subarray' function we print a part of the 'num' array
	
	/* TNT::Stopwatch */	
	//using the 'stop' function of the timer to stop counting. This function returns the time
	//elapsed from the call of the 'start' function in seconds.
	std::cout << timer1.stop()<<"n"; 
	
	
	
	
	return 0;
}

Initial URL


Initial Description


Initial Title
Basic usage of TNT library #1

Initial Tags
class

Initial Language
C++