Click here to Skip to main content
Licence 
First Posted 26 Jun 2001
Views 73,039
Downloads 1,504
Bookmarked 25 times

Tensor templates

By | 26 Jun 2001 | Article
A template class that enable you to make tensors with any dimensionality. Process convolution of any tensors and so on.

Introduction

The Tensor class was written in 1997 during my study of templates (I found it examining my archives).

But I've not seen any such classes since. So I think it can be useful for students. The main reason I've wrote it - for the convolution of tensors with any dimensionality. Also you can get and use any sub-tensor using operator[], for example Sample Image can be written like

Tensor2 qq,a1,a2,aa;
convolution(aa["li"],a2["lj"],qq["ij"]);
convolution(qq["kl"],a1["ki"],aa["li"]);

Using

The demo project shows usage of tensors. You can:

Declare and init tensors (you should specify dimension and indexes range).

   Tensor2 result2(2);
   Tensor4 tt(3);  // 4 - dimensions indexes can be 0-2 or "1"-"3"
   Tensor2 t1(2);       t1[0][0] = 1.0;
                        t1[1][0] = 2.0;
                        t1[0][1] = 3.0;
                        t1[1][1] = 4.0;

Convolute tensors - note that you can use different dimensions and one or more constants in indices.

   convolution(result5["2i"],t3["2"],t2["i3"]);    
   convolution(result6["ij"],t1["ja"],t2["ai"]);

Use some arithmetical operations.

    result3 = t1 + t2*2;

Print part or whole tensor.

    t4["ijkl"].printf(std::cout);      
    result5["1j"].printf(std::cout);

Average tensors.

    Tensor2 t[2];
    double q[2];
    t2.averaging(&t[0],q,2);

Invert 4-dimension tensor with indexes (0,1).

    Tensor4 t(2),ti(2);
    ti = inverse(t);      

To Do list

It can be easy to implement some more operations with tensors (different multiplication and so). Please let me know, if you need some.

Note

Make sure to check out the my web site which is more likely to have updates and betas: http://www.zmike.net

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mike Melnikov

Web Developer

Russian Federation Russian Federation

Member

Mike has been programming in C/C++ for 11 years and Visual C++/MFC for 4 years. His background includes pure and applied mathematics, engineering and physics, and he is currently based in Moscow, Russia.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generallinear algebra PinmemberVeganFanatic15:22 9 Jun '10  
GeneralIntroduction to Tensor Convolution PinmemberPho3NiX7:52 15 Aug '09  
GeneralGeneral comment PinmemberDarid Tromer23:08 24 Feb '08  
GeneralRe: General comment PinmemberMike Melnikov0:26 1 Mar '08  
General[Message Deleted] PinmemberDanny Rodriguez9:41 27 Jan '08  
Generalthis is good! Pinmemberyulin113:50 14 Jun '07  
GeneralTensors, great fun! ;) PinmemberPedroMC23:48 10 Aug '05  
GeneralRe: Tensors, great fun! ;) Pinmemberyulin113:52 14 Jun '07  
Generalthk u Pinmembersyit3154:37 15 May '04  
GeneralWell Done ! PinmemberColin Davies0:42 6 Jul '02  
GeneralRe: Well Done ! PinmemberMike Melnikov3:11 10 Aug '02  
GeneralI'm ashamed to ask but... PinmemberDaniel Turini4:17 22 Dec '01  
GeneralRe: I'm ashamed to ask but... PinmemberMike Melnikov21:01 26 Dec '01  
GeneralRe: I'm ashamed to ask but... PinmemberJerry Jeremiah13:56 14 Mar '06  

This is also good:
 
http://en.wikipedia.org/wiki/Tensor
 
And I thought this was really helpful:
 
http://www.grc.nasa.gov/WWW/K-12/Numbers/ Math/documents/Tensors_TM2002211716.pdf

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 27 Jun 2001
Article Copyright 2001 by Mike Melnikov
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid