Skip to content

Commit

Permalink
Fixing numpy copy=false
Browse files Browse the repository at this point in the history
  • Loading branch information
roigcarlo committed Nov 29, 2024
1 parent 1d7ec51 commit e5ceaf0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def AppendCurrentStepResiduals(self):
err_msg = f"Projection strategy \'{self.projection_strategy}\' for HROM is not supported."
raise Exception(err_msg)

np_res_mat = np.array(res_mat, copy=False)
np_res_mat = np.asarray(res_mat)
self.time_step_residual_matrix_container.append(np_res_mat)

def GetJacobianPhiMultiplication(self, computing_model_part):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def AppendCurrentStepProjectedSystem(self):
err_msg = "\'self.basis_strategy\' is not available. Select either 'jacobian' or 'residuals'."
raise Exception(err_msg)

np_snapshots_matrix = np.array(snapshots_matrix, copy=False)
np_snapshots_matrix = np.asarray(snapshots_matrix)
self.time_step_snapshots_matrix_container.append(np_snapshots_matrix)

def GetJacobianPhiMultiplication(self, computing_model_part):
Expand Down
2 changes: 1 addition & 1 deletion applications/RomApplication/python_scripts/rom_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def ModifyInitialGeometry(self):

print('Nodal variables: ', nodal_unknown_names)

s_default = np.array(s, copy=False)
s_default = np.asarray(s)
print(s_default.shape)

q, _ = nn_rom_interface.get_encode_function()(s_default)
Expand Down
2 changes: 1 addition & 1 deletion applications/RomApplication/python_scripts/rom_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ def Initialize(cls):

def GetNonconvergedSolutions(cls):
a,_ = cls._GetSolver()._GetSolutionStrategy().GetNonconvergedSolutions()
return np.array(a, copy=False)
return np.asarray(a)

simulation.Initialize = types.MethodType(Initialize, simulation)
simulation.GetNonconvergedSolutions = types.MethodType(GetNonconvergedSolutions, simulation)
Expand Down
12 changes: 6 additions & 6 deletions kratos/python_scripts/petsc_conversion_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ def __init__(self, A): #Kratos DistributedCsrMatrix
N = A.GetColNumbering().Size()

##pointers to the kratos arrays of values
self.a = np.array(A.GetDiagonalBlock().value_data(), copy=False)
self.oa = np.array(A.GetOffDiagonalBlock().value_data(), copy=False)
self.a = np.asarray(A.GetDiagonalBlock().value_data())
self.oa = np.asarray(A.GetOffDiagonalBlock().value_data())

if(type(m) == type(PETSc.IntType)): #we can avoid doing copies
#indices of diagonal block
self.i = np.array(A.GetDiagonalBlock().index1_data(), copy=False)
self.j = np.array(A.GetDiagonalBlock().index2_data(), copy=False)
self.i = np.asarray(A.GetDiagonalBlock().index1_data())
self.j = np.asarray(A.GetDiagonalBlock().index2_data())

#indices of offdiagonal block
self.oi = np.array(A.GetOffDiagonalBlock().index1_data(), copy=False)
self.oj = np.array(A.GetOffDiagonalIndex2DataInGlobalNumbering(), copy=False)
self.oi = np.asarray(A.GetOffDiagonalBlock().index1_data())
self.oj = np.asarray(A.GetOffDiagonalIndex2DataInGlobalNumbering())

else: #WE NEED TO COPY INDICES! since the size of the IndexType is not compatible between Kratos and PETSc
if(A.GetComm().Rank() == 0):
Expand Down
4 changes: 2 additions & 2 deletions kratos/tests/test_numpy_export_dense_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_numpy_export_dense_matrix_no_copying(self):
KratosMatrix.fill(1.0)

# Export it to numpy array (No copying is performed)
NumpyMatrix = np.array(KratosMatrix,copy=False)
NumpyMatrix = np.asarray(KratosMatrix)

# Test correct creation
for i in range(3):
Expand All @@ -35,7 +35,7 @@ def test_numpy_export_complex_dense_matrix_no_copying(self):
KratosMatrix.fill(1.0+1.0j)

# Export it to numpy array (No copying is performed)
NumpyMatrix = np.array(KratosMatrix,copy=False)
NumpyMatrix = np.asarray(KratosMatrix)

# Test correct creation
for i in range(3):
Expand Down
2 changes: 1 addition & 1 deletion kratos/tests/test_vectorized_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def testVectorizedInterpolation(self):

#obtaining a copy of database onto numpy array, and reshaping it into matrices
nnodes = len(self.mp.Nodes)
vdata = np.array(Kratos.VariableUtils().GetSolutionStepValuesVector(self.mp.Nodes, Kratos.VELOCITY, 0, 3),copy=False).reshape(nnodes,3)
vdata = np.asarray(Kratos.VariableUtils().GetSolutionStepValuesVector(self.mp.Nodes, Kratos.VELOCITY, 0, 3)).reshape(nnodes,3)
coords = np.array(Kratos.VariableUtils().GetCurrentPositionsVector(self.mp.Nodes,3)).reshape(nnodes,3)

##coordinates to search for
Expand Down

0 comments on commit e5ceaf0

Please sign in to comment.