Skip to content

Commit daacf42

Browse files
wence-chrisrichardson
authored andcommitted
Merged in no-numpy-matrix (pull request #50)
Remove reliance on numpy.matrix Approved-by: Chris Richardson <[email protected]>
2 parents f2a3059 + 812395a commit daacf42

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

FIAT/hdiv_trace.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,13 @@ def barycentric_coordinates(points, vertices):
348348
"""
349349

350350
# Form mapping matrix
351-
last = np.asarray(vertices[-1])
352-
T = np.matrix([np.array(v) - last for v in vertices[:-1]]).T
351+
T = (np.asarray(vertices[:-1]) - vertices[-1]).T
353352
invT = np.linalg.inv(T)
354353

355-
# Compute the barycentric coordinates for all points
356-
coords = []
357-
for p in points:
358-
y = np.asarray(p) - last
359-
bary = invT.dot(y.T)
360-
bary = [bary[(0, i)] for i in range(len(y))]
361-
bary += [1.0 - sum(bary)]
362-
coords.append(bary)
363-
return coords
354+
points = np.asarray(points)
355+
bary = np.einsum("ij,kj->ki", invT, (points - vertices[-1]))
356+
last = (1 - bary.sum(axis=1))
357+
return np.concatenate([bary, last[..., np.newaxis]], axis=1)
364358

365359

366360
def map_from_reference_facet(point, vertices):

FIAT/nedelec_second_kind.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ def _generate_face_dofs(self, cell, degree, offset):
160160

161161
# Map Phis -> phis (reference values to physical values)
162162
J = Q_face.jacobian()
163-
scale = 1.0 / numpy.sqrt(numpy.linalg.det(J.transpose() * J))
163+
scale = 1.0 / numpy.sqrt(numpy.linalg.det(numpy.dot(J.T, J)))
164164
phis = numpy.ndarray((d, num_quad_points))
165165
for i in range(num_rts):
166166
for q in range(num_quad_points):
167-
phi_i_q = scale * J * numpy.matrix(Phis[i, :, q]).transpose()
167+
phi_i_q = scale * numpy.dot(J, Phis[numpy.newaxis, i, :, q].T)
168168
for j in range(d):
169169
phis[j, q] = phi_i_q[j]
170170

FIAT/quadrature.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,12 @@ def __init__(self, face_number, degree):
211211
# Use tet to map points and weights on the appropriate face
212212
vertices = [numpy.array(list(vertex)) for vertex in vertices]
213213
x0 = vertices[0]
214-
J = numpy.matrix([vertices[1] - x0, vertices[2] - x0]).transpose()
215-
x0 = numpy.matrix(x0).transpose()
214+
J = numpy.vstack([vertices[1] - x0, vertices[2] - x0]).T
216215
# This is just a very numpyfied way of writing J*p + x0:
217-
F = lambda p: \
218-
numpy.array(J*numpy.matrix(p).transpose() + x0).flatten()
219-
points = numpy.array([F(p) for p in ref_points])
216+
points = numpy.einsum("ij,kj->ki", J, ref_points) + x0
220217

221218
# Map weights: multiply reference weights by sqrt(|J^T J|)
222-
detJTJ = numpy.linalg.det(J.transpose() * J)
219+
detJTJ = numpy.linalg.det(numpy.dot(J.T, J))
223220
weights = numpy.sqrt(detJTJ) * ref_weights
224221

225222
# Initialize super class with new points and weights

0 commit comments

Comments
 (0)