示例#1
0
def test_matrix_zeros_scipy():
    if not np:
        skip("numpy not installed or Python too old.")
    if not scipy:
        skip("scipy not installed.")

    sci = matrix_zeros(4, 4, format='scipy.sparse')
    assert isinstance(sci, scipy_sparse_matrix)
示例#2
0
def test_matrix_zeros_scipy():
    if not np:
        skip("numpy not installed.")
    if not scipy:
        skip("scipy not installed.")

    sci = matrix_zeros(4, 4, format='scipy.sparse')
    assert isinstance(sci, scipy_sparse_matrix)
示例#3
0
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get('ndim', 4)
     format = options.get('format', 'sympy')
     matrix = matrix_zeros(ndim_info, ndim_info, **options)
     for i in range(ndim_info):
         value = i + S.Half
         if format == 'scipy.sparse':
             value = float(value)
         matrix[i, i] = value
     if format == 'scipy.sparse':
         matrix = matrix.tocsr()
     return hbar * omega * matrix
示例#4
0
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get('ndim', 4)
     format = options.get('format', 'sympy')
     matrix = matrix_zeros(ndim_info, ndim_info, **options)
     for i in range(ndim_info - 1):
         value = sqrt(i + 1)
         if format == 'scipy.sparse':
             value = float(value)
         matrix[i, i + 1] = value
     if format == 'scipy.sparse':
         matrix = matrix.tocsr()
     return matrix
示例#5
0
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get("ndim", 4)
     format = options.get("format", "sympy")
     matrix = matrix_zeros(ndim_info, ndim_info, **options)
     for i in range(ndim_info):
         value = i + Integer(1) / Integer(2)
         if format == "scipy.sparse":
             value = float(value)
         matrix[i, i] = value
     if format == "scipy.sparse":
         matrix = matrix.tocsr()
     return hbar * omega * matrix
示例#6
0
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get("ndim", 4)
     format = options.get("format", "sympy")
     matrix = matrix_zeros(ndim_info, ndim_info, **options)
     for i in range(ndim_info - 1):
         value = sqrt(i + 1)
         if format == "scipy.sparse":
             value = float(value)
         matrix[i, i + 1] = value
     if format == "scipy.sparse":
         matrix = matrix.tocsr()
     return matrix
示例#7
0
文件: sho1d.py 项目: ChaliZhg/sympy
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get('ndim', 4)
     format = options.get('format', 'sympy')
     spmatrix = options.get('spmatrix', 'csr')
     matrix = matrix_zeros(ndim_info, ndim_info, **options)
     for i in range(ndim_info):
         value = i + Integer(1)/Integer(2)
         if format == 'scipy.sparse':
             value = float(value)
         matrix[i,i] = value
     if format == 'scipy.sparse':
         matrix = matrix.tocsr()
     return hbar*omega*matrix
示例#8
0
文件: sho1d.py 项目: ChaliZhg/sympy
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get('ndim', 4)
     format = options.get('format', 'sympy')
     spmatrix = options.get('spmatrix', 'csr')
     matrix = matrix_zeros(ndim_info, ndim_info, **options)
     for i in range(ndim_info - 1):
         value = sqrt(i + 1)
         if format == 'scipy.sparse':
             value = float(value)
         matrix[i,i + 1] = value
     if format == 'scipy.sparse':
         matrix = matrix.tocsr()
     return matrix
示例#9
0
文件: sho1d.py 项目: ChaliZhg/sympy
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get('ndim', 4)
     format = options.get('format', 'sympy')
     options['spmatrix'] = 'lil'
     vector = matrix_zeros(1, ndim_info, **options)
     if isinstance(self.n, Integer):
         if self.n >= ndim_info:
             return ValueError("N-Dimension too small")
         if format == 'scipy.sparse':
             vector[0, int(self.n)] = 1.0
             vector = vector.tocsr()
         elif format == 'numpy':
             vector[0, int(self.n)] = 1.0
         else:
             vector[0, self.n] = Integer(1)
         return vector
     else:
         return ValueError("Not Numerical State")
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get('ndim', 4)
     format = options.get('format', 'sympy')
     options['spmatrix'] = 'lil'
     vector = matrix_zeros(1, ndim_info, **options)
     if isinstance(self.n, Integer):
         if self.n >= ndim_info:
             return ValueError("N-Dimension too small")
         if format == 'scipy.sparse':
             vector[0, int(self.n)] = 1.0
             vector = vector.tocsr()
         elif format == 'numpy':
             vector[0, int(self.n)] = 1.0
         else:
             vector[0, self.n] = Integer(1)
         return vector
     else:
         return ValueError("Not Numerical State")
示例#11
0
 def _represent_NumberOp(self, basis, **options):
     ndim_info = options.get("ndim", 4)
     format = options.get("format", "sympy")
     options["spmatrix"] = "lil"
     vector = matrix_zeros(1, ndim_info, **options)
     if isinstance(self.n, Integer):
         if self.n >= ndim_info:
             return ValueError("N-Dimension too small")
         if format == "scipy.sparse":
             vector[0, int(self.n)] = 1.0
             vector = vector.tocsr()
         elif format == "numpy":
             vector[0, int(self.n)] = 1.0
         else:
             vector[0, self.n] = Integer(1)
         return vector
     else:
         return ValueError("Not Numerical State")
示例#12
0
def test_matrix_zeros_numpy():
    if not np:
        skip("numpy not installed.")

    num = matrix_zeros(4, 4, format='numpy')
    assert isinstance(num, numpy_ndarray)
示例#13
0
def test_matrix_zeros_sympy():
    sym = matrix_zeros(4, 4, format='sympy')
    assert isinstance(sym, Matrix)
示例#14
0
def test_matrix_zeros_numpy():
    if not np:
        skip("numpy not installed or Python too old.")

    num = matrix_zeros(4, 4, format='numpy')
    assert isinstance(num, numpy_ndarray)
示例#15
0
def test_matrix_zeros_sympy():
    sym = matrix_zeros(4, 4, format='sympy')
    assert isinstance(sym, Matrix)
示例#16
0
def test_matrix_zeros_numpy():
    if not np:
        skip("numpy not installed.")

    num = matrix_zeros(4, 4, format="numpy")
    assert isinstance(num, numpy_ndarray)