# Shape Mismatch in np.linalg.solve in soln-plugin-sampler (sampler.py) Causing ValueError

**URL:** https://pyfr.discourse.group/t/shape-mismatch-in-np-linalg-solve-in-soln-plugin-sampler-sampler-py-causing-valueerror/1152
**Category:** Bugs
**Tags:** plugins
**Created:** [24 August 2024 17:55 UTC](https://pyfr.discourse.group/t/shape-mismatch-in-np-linalg-solve-in-soln-plugin-sampler-sampler-py-causing-valueerror/1152 "2024-08-24T17:55:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Debdoot](https://yyz2.discourse-cdn.com/free1/user_avatar/pyfr.discourse.group/debdoot/32/648_2.png) [@Debdoot](https://pyfr.discourse.group/u/Debdoot)
#### Post date: [24 August 2024 17:55 UTC](https://pyfr.discourse.group/t/shape-mismatch-in-np-linalg-solve-in-soln-plugin-sampler-sampler-py-causing-valueerror/1152/1 "2024-08-24T17:55:05Z")

</div>

# Nature of bug

Error in using **[soln-plugin-sampler]** ( associated to sampler.py file)

# Error print out (if applicable)

```auto
ValueError: solve: Input operand 1 has a mismatch in its core
dimension 0, with gufunc signature (m,m), (m, n) ›(m,n) (size 20 is different from 2)

```

# PyFR information

- PyFR version: pyfr 2.0.2
- OS: NAME=CentOS Linux; VERSION=“7 (Core)”
- System description: Architecture x86\_64; Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz ; NVIDIA v100
- Compiler and version: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
- Backend (if applicable): CUDA

# Git diff that reproduces bug

```auto
diff --git a/pyfr/plugins/sampler.py b/pyfr/plugins/sampler.py
index 818dc81..79dd8e3 100644
--- a/pyfr/plugins/sampler.py
+++ b/pyfr/plugins/sampler.py
@@ -43,7 +43,13 @@ def _plocs_to_tlocs(sbasis, spts, plocs, tlocs):
     for k in range(3):
         jac_ops = sbasis.jac_nodal_basis_at(ktlocs)
         kjplocs = np.einsum('ijk,jkl->kli', jac_ops, spts)
- ktlocs -= np.linalg.solve(kjplocs, kplocs - plocs)
+ # ktlocs -= np.linalg.solve(kjplocs, kplocs - plocs)
+# Adjust the shape of kplocs - plocs to match kjplocs
+ rhs = (kplocs - plocs)[..., np.newaxis]
+
+# Solve the linear system
+ ktlocs -= np.linalg.solve(kjplocs, rhs).reshape(ktlocs.shape)
+
 
         ops = sbasis.nodal_basis_at(ktlocs)
         np.einsum('ij,jik->ik', ops, spts, out=kplocs)

```

---

<div class="post-metadata">

### Author: ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)
#### Post date: [24 August 2024 17:55 UTC](https://pyfr.discourse.group/t/shape-mismatch-in-np-linalg-solve-in-soln-plugin-sampler-sampler-py-causing-valueerror/1152/2 "2024-08-24T17:55:49Z")

</div>

Please provide an .ini file which reproduces the issue (ideally with a built-in test case).

Regards, Freddie.

---

<div class="post-metadata">

### Author: ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)
#### Post date: [29 August 2024 18:23 UTC](https://pyfr.discourse.group/t/shape-mismatch-in-np-linalg-solve-in-soln-plugin-sampler-sampler-py-causing-valueerror/1152/3 "2024-08-29T18:23:50Z")

</div>

As a follow up this appears to be an issue with NumPy v2. A simple workaround is to downgrade to 1.26. Alternatively, you can switch to the current development version of PyFR where this issue is resolved.

Regards, Freddie.

---

<div class="post-metadata">

### Author: ![Debdoot](https://yyz2.discourse-cdn.com/free1/user_avatar/pyfr.discourse.group/debdoot/32/648_2.png) [@Debdoot](https://pyfr.discourse.group/u/Debdoot)
#### Post date: [6 September 2024 01:22 UTC](https://pyfr.discourse.group/t/shape-mismatch-in-np-linalg-solve-in-soln-plugin-sampler-sampler-py-causing-valueerror/1152/4 "2024-09-06T01:22:06Z")

</div>

Thank you for the suggestions, Dr. Freddie.
