Repository navigation
Fix plani4e and soli8e for NumPy 2 and ndarray inputs - #96
Merged
jonaslindemann merged 1 commit intoOct 1, 2026
Merged
Conversation
Both functions assume np.matrix semantics that no longer hold when callers pass plain ndarrays, which breaks them under NumPy 2. plani4e: - coerce D to np.matrix so B.T * Dm * B keeps matrix multiplication - build wp, xsi and eta as explicit column vectors, so the subsequent np.append(..., axis=1) has a 2-D operand to append along - use @ for JTinv * dNr, which is a matrix product rather than an elementwise one - extract detJ, wp[i] and t as Python floats and reshape q to a column before accumulating into Ke1 and fe1, instead of relying on 1x1 matrix coercion soli8e: - reshape eqp to (3, 1) so fe accumulates against a column - test `eqp is not None` rather than `eqp != None`. The latter is an elementwise comparison when eqp is an ndarray, producing an array whose truth value is ambiguous, so the function raises instead of returning fe Verified against NumPy 2.4.6 and 2.5.2. No intended change in results for inputs that already worked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
plani4eandsoli8eassumenp.matrixsemantics that don't hold when inputs are plain ndarrays, which breaks them under NumPy 2. Same area as #89, different call sites.plani4e: coerceDtonp.matrixsoB.T * Dm * Bstays a matrix product, buildwp/xsi/etaas columns so the followingnp.append(..., axis=1)has a 2-D operand, use@forJTinv * dNr, and takedetJ/wp[i]/tas floats withqreshaped to a column when accumulatingKe1/fe1.soli8e: reshapeeqpto(3, 1), and testeqp is not Nonerather thaneqp != None.That last one is a plain bug. On master, with a unit cube and
D = np.eye(6):eqpas an ndarray:eqp != Nonecompares elementwise, so truth-testing the result raisesValueError: The truth value of an array with more than one element is ambiguous.eqpas a list: no error, butfecomes back(24, 24)instead of(24, 1).So
soli8ewith a body force is wrong either loudly or quietly. Both cases givefe(24, 1)after the change.Tested on NumPy 2.4.6 and 2.5.2. No intended change where things already worked.
Found while using calfem-python as a reference implementation for a Julia port.