CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Static Public Member Functions
TensorIndex< d1, d2, d3, d4 > Class Template Reference

#include <TensorIndex.h>

Public Types

enum  { SIZE = d1*d2*d3*d4 }
 
enum  { LEN1 = d1 }
 
enum  { LEN2 = d2 }
 
enum  { LEN3 = d3 }
 
enum  { LEN4 = d4 }
 

Static Public Member Functions

static int indexOf (const int i)
 
static int indexOf (const int i, const int j)
 
static int indexOf (const int i, const int j, const int k)
 
static int indexOf (const int i, const int j, const int k, const int l)
 

Detailed Description

template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
class TensorIndex< d1, d2, d3, d4 >

Credit: Utility class from

http://www.sitmo.com/doc/A_Simple_and_Extremely_Fast_CPP_Template_for_Matrices_and_Tensors

Usage:

The template below offers a simple and efficient solution for handling matrices and tensors in C++. The idea is to store the matrix (or tensor) in a standard vector by translating the multidimensional index to a one dimensional index.

The only thing we need to do is to convert two dimensional indices (r,c) into a one dimensional index. Using template we can do this very efficiently compile time, minimizing the runtime overhead.

Definition at line 16 of file TensorIndex.h.

Member Enumeration Documentation

template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
anonymous enum
Enumerator
SIZE 

Definition at line 18 of file TensorIndex.h.

18 {SIZE = d1*d2*d3*d4 };
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
anonymous enum
Enumerator
LEN1 

Definition at line 19 of file TensorIndex.h.

19 {LEN1 = d1 };
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
anonymous enum
Enumerator
LEN2 

Definition at line 20 of file TensorIndex.h.

20 {LEN2 = d2 };
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
anonymous enum
Enumerator
LEN3 

Definition at line 21 of file TensorIndex.h.

21 {LEN3 = d3 };
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
anonymous enum
Enumerator
LEN4 

Definition at line 22 of file TensorIndex.h.

22 {LEN4 = d4 };

Member Function Documentation

template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
static int TensorIndex< d1, d2, d3, d4 >::indexOf ( const int  i)
inlinestatic

Definition at line 24 of file TensorIndex.h.

References i.

Referenced by big::bigEntry::fill().

24  {
25  return i;
26  }
int i
Definition: DBlmapReader.cc:9
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
static int TensorIndex< d1, d2, d3, d4 >::indexOf ( const int  i,
const int  j 
)
inlinestatic

Definition at line 27 of file TensorIndex.h.

References i.

27  {
28  return j*d1 + i;
29  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
static int TensorIndex< d1, d2, d3, d4 >::indexOf ( const int  i,
const int  j,
const int  k 
)
inlinestatic

Definition at line 30 of file TensorIndex.h.

References i.

30  {
31  return (k*d2 + j)*d1 + i;
32  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
template<int d1, int d2 = 1, int d3 = 1, int d4 = 1>
static int TensorIndex< d1, d2, d3, d4 >::indexOf ( const int  i,
const int  j,
const int  k,
const int  l 
)
inlinestatic

Definition at line 33 of file TensorIndex.h.

References i.

33  {
34  return ((l*d3 + k)*d2 + j)*d1 + i;
35  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9