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)
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)
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
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
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
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
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
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
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")
def test_matrix_zeros_numpy(): if not np: skip("numpy not installed.") num = matrix_zeros(4, 4, format='numpy') assert isinstance(num, numpy_ndarray)
def test_matrix_zeros_sympy(): sym = matrix_zeros(4, 4, format='sympy') assert isinstance(sym, Matrix)
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)
def test_matrix_zeros_numpy(): if not np: skip("numpy not installed.") num = matrix_zeros(4, 4, format="numpy") assert isinstance(num, numpy_ndarray)