Skip to content

Commit

Permalink
add squeeze
Browse files Browse the repository at this point in the history
  • Loading branch information
kinnala committed Apr 7, 2024
1 parent 4767ef6 commit 680063b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/examples/ex41.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
on mixed meshes is work-in-progress.
"""
import numpy as np
from pathlib import Path
from skfem import *
from skfem.models import laplace, unit_load
Expand All @@ -35,7 +36,7 @@
A = asm(laplace, basis)
f = asm(unit_load, basis)

y = solve(*condense(A, f, D=out[0]['boundary']['line']).astype(np.int64))
y = solve(*condense(A, f, D=out[0]['boundary']['line'].astype(np.int64)))

def visualize():
from skfem.visuals.matplotlib import plot, draw
Expand Down
15 changes: 12 additions & 3 deletions skfem/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,16 @@ def _remove_duplicate_nodes(p, t):
tmp = np.ascontiguousarray(p.T)
tmp, ixa, ixb = np.unique(tmp.view([('', tmp.dtype)] * tmp.shape[1]),
return_index=True, return_inverse=True)
return p[:, ixa], ixb[t]
return p[:, ixa], Mesh._squeeze_if(ixb[t])

@staticmethod
def _squeeze_if(arr):
# Workaround for the additional dimension introduced in
# numpy 2.0 for the output of np.unique when using
# return_index=True
if len(arr.shape) > 2:
return arr.squeeze(axis=2)
return arr

def __iter__(self):
return iter((self.doflocs, self.t))
Expand All @@ -609,8 +618,8 @@ def __matmul__(self, other):
return_index=True, return_inverse=True)
p = p[:, ixa]
return [
cls(p, ixb[self.t]),
*[type(m)(p, ixb[m.t + self.p.shape[1]])
cls(p, self._squeeze_if(ixb[self.t])),
*[type(m)(p, self._squeeze_if(ixb[m.t + self.p.shape[1]]))
for i, m in enumerate(other)],
]
raise NotImplementedError
Expand Down

0 comments on commit 680063b

Please sign in to comment.