RF: Rewrite of the tensor mode calculation with no loops.

Also, broke it down into separate functions, added some testing, etc.
Merge pull request #1 from arokem/swederik-enh/TensorMode

RF: Rewrite of the tensor mode calculation with no loops.