# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#
import numpy as np
[docs]def ImmutableView(data: np.ndarray) -> np.ndarray:
"""Return a immutable view of a numpy array
Parameters
----------
data : np.ndarray
input numpy array
Returns
-------
np.ndarray
immutable view of data
"""
res = data.view()
res.flags.writeable = False
return res
# to eliminate dofs with know values
[docs]def DeleteRowsCols(A, rows, cols, fixedValues):
"""This function will be eliminated. Please do not use it
Parameters
----------
A : _type_
_description_
rows : _type_
_description_
cols : _type_
_description_
fixedValues : _type_
_description_
Returns
-------
_type_
_description_
"""
# Assumes that matrix is in symmetric csc form !
rhs = A.dot(fixedValues)
A = A[np.logical_not(rows), :]
A = A[:, np.logical_not(cols)]
return [A, rhs]
[docs]def CheckIntegrity():
from scipy.sparse import csr_matrix
fv = np.array([[1, 2],]).T
mask = np.zeros(2)
mask[1] = True
for sp in [True, False]:
if sp:
K = csr_matrix([[1, 2], [3, 4]])
else:
K = np.array([[1, 2], [3, 4]])
A, rhs = DeleteRowsCols(K, mask, mask, fv)
print("using Sparse : " + ("True" if sp else "False"))
print("Vals")
print(A)
print("--")
print(rhs)
print("Types")
print(type(A))
print(type(rhs))
ImmutableView(np.array([4, 3, 2, 1]))
return "ok"
if __name__ == '__main__':
print(CheckIntegrity()) # pragma: no cover