File: _MMT.py

package info (click to toggle)
xmds2 3.0.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 52,068 kB
  • sloc: python: 63,652; javascript: 9,230; cpp: 3,929; ansic: 1,463; makefile: 121; sh: 54
file content (76 lines) | stat: -rwxr-xr-x 2,958 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# encoding: utf-8
"""
_MMT.py

Created by Graham Dennis on 2008-12-12.

Copyright (c) 2008-2012, Graham Dennis

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""

from xpdeint.Features.Transforms._Transform import _Transform

from xpdeint.Geometry.DimensionRepresentation import DimensionRepresentation


class _MMT (_Transform):
  transformName = 'MMT'
  
  coordinateSpaceTag = DimensionRepresentation.registerTag('MMT coordinate space', parent = 'coordinate')
  spectralSpaceTag = DimensionRepresentation.registerTag('MMT spectral space', parent = 'spectral')
  auxiliarySpaceTag = DimensionRepresentation.registerTag('MMT auxiliary space', parent = 'auxiliary')
  
  def __init__(self, *args, **KWs):
    _Transform.__init__(self, *args, **KWs)
    self.basisMap = {}
  
  @property
  def children(self):
    children = super(_MMT, self).children
    [children.extend(list(basisDict['transformations'].values())) for basisDict in list(self.basisMap.values())]
    return children
  
  def globals(self):
    return '\n'.join([basisDict.get('globalsFunction')(dimName, basisDict) \
                          for dimName, basisDict in list(self.basisMap.items()) if basisDict.get('globalsFunction')])
  
  def availableTransformations(self):
    results = []
    geometry = self.getVar('geometry')
    # Sort dimension names based on their ordering in the geometry.
    sortedDimNames = [(geometry.indexOfDimensionName(dimName), dimName) for dimName in self.basisMap]
    sortedDimNames.sort()
    sortedDimNames = [o[1] for o in sortedDimNames]
    # Create all transforms just for each dimension individually
    for dimName, basisDict in list(self.basisMap.items()):
      dimReps = geometry.dimensionWithName(dimName).representations
      for transformPair, basis in list(basisDict['transformations'].items()):
        basisReps = [[rep for rep in dimReps if rep.name == repName][0] for repName in transformPair]
        def addTransform(outOfPlace):
          results.append(dict(
            transformations = [transformPair],
            cost = basis.costEstimate(basisReps),
            outOfPlace = outOfPlace,
            transformFunction = basis.transformFunction,
            transformType = basis.matrixType,
          ))
        addTransform(True)
        if basis.supportsInPlaceOperation:
            addTransform(False)
    
    return results