pysheaf.dataTools

 1import numpy as np
 2
 3
 4# dataTools is meant to serve as a place to put general serialize/deserialize/compare/edgeMethods that may be
 5# useful for other users. 
 6
 7
 8class SetMorphism():
 9  """A morphism in a subcategory of Set, described by a function object"""
10  def __init__(self,fcn):
11      self.fcn=fcn
12
13  def __mul__(self,other): # Composition of morphisms
14      return SetMorphism(lambda x : self.fcn(other.fcn(x)))
15
16  def __call__(self,arg): # Calling the morphism on an element of the set
17      return self.fcn(arg)
18
19class LinearMorphism(SetMorphism):
20  """A morphism in a category that has a matrix representation"""
21  def __init__(self,matrix):
22      self.matrix=matrix
23      SetMorphism.__init__(self,lambda x: np.dot(matrix,x))
24
25  def __mul__(self,other): # Composition of morphisms
26      try: # Try to multiply matrices.  This might fail if the other morphism isn't a LinearMorphism
27         return LinearMorphism(np.dot(self.matrix, other.matrix))
28      except AttributeError:
29         return SetMorphism.__mul__(self,other)
class SetMorphism:
 9class SetMorphism():
10  """A morphism in a subcategory of Set, described by a function object"""
11  def __init__(self,fcn):
12      self.fcn=fcn
13
14  def __mul__(self,other): # Composition of morphisms
15      return SetMorphism(lambda x : self.fcn(other.fcn(x)))
16
17  def __call__(self,arg): # Calling the morphism on an element of the set
18      return self.fcn(arg)

A morphism in a subcategory of Set, described by a function object

SetMorphism(fcn)
11  def __init__(self,fcn):
12      self.fcn=fcn
fcn
class LinearMorphism(SetMorphism):
20class LinearMorphism(SetMorphism):
21  """A morphism in a category that has a matrix representation"""
22  def __init__(self,matrix):
23      self.matrix=matrix
24      SetMorphism.__init__(self,lambda x: np.dot(matrix,x))
25
26  def __mul__(self,other): # Composition of morphisms
27      try: # Try to multiply matrices.  This might fail if the other morphism isn't a LinearMorphism
28         return LinearMorphism(np.dot(self.matrix, other.matrix))
29      except AttributeError:
30         return SetMorphism.__mul__(self,other)

A morphism in a category that has a matrix representation

LinearMorphism(matrix)
22  def __init__(self,matrix):
23      self.matrix=matrix
24      SetMorphism.__init__(self,lambda x: np.dot(matrix,x))
matrix
Inherited Members
SetMorphism
fcn