random_matrix.py 1.0 KB

123456789101112131415161718192021222324252627282930
  1. from sympy.core.basic import Basic
  2. from sympy.stats.rv import PSpace, _symbol_converter, RandomMatrixSymbol
  3. class RandomMatrixPSpace(PSpace):
  4. """
  5. Represents probability space for
  6. random matrices. It contains the mechanics
  7. for handling the API calls for random matrices.
  8. """
  9. def __new__(cls, sym, model=None):
  10. sym = _symbol_converter(sym)
  11. if model:
  12. return Basic.__new__(cls, sym, model)
  13. else:
  14. return Basic.__new__(cls, sym)
  15. @property
  16. def model(self):
  17. try:
  18. return self.args[1]
  19. except IndexError:
  20. return None
  21. def compute_density(self, expr, *args):
  22. rms = expr.atoms(RandomMatrixSymbol)
  23. if len(rms) > 2 or (not isinstance(expr, RandomMatrixSymbol)):
  24. raise NotImplementedError("Currently, no algorithm has been "
  25. "implemented to handle general expressions containing "
  26. "multiple random matrices.")
  27. return self.model.density(expr)