Commit ae4f1b8
committed
fix(asanyarray): handle object[] via type-promotion path
np.asanyarray(new object[]{1, 2.5, 3}) threw NotSupportedException because
`case Array array` matched object[] first and `new NDArray(object[])` rejects
object as an element type. object[] has no fixed dtype, so routing through the
non-generic IEnumerable path (which applies NumPy-like type promotion) is the
correct behavior.
Added an explicit `case object[] objArr` branch that delegates to
ConvertNonGenericEnumerable, which already handles:
- Homogeneous object[]: detected via FindCommonNumericType, single dtype
- Mixed object[]: promoted to common type (e.g. int + double -> double)
- Empty object[]: returns empty double[] (matches NumPy float64 default)
- Bool+int mix: promotes bool to int via Convert.ToInt32 (True=1, False=0)
Regression tests added in np.asanyarray.Tests.cs covering all four cases.
All 66 np.asanyarray tests pass on net8.0 and net10.0.1 parent 4e8af8b commit ae4f1b8
2 files changed
Lines changed: 53 additions & 0 deletions
File tree
- src/NumSharp.Core/Creation
- test/NumSharp.UnitTest/Creation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
750 | 795 | | |
751 | 796 | | |
0 commit comments