22using System . Collections . Generic ;
33using System . Text ;
44
5- namespace NumSharp . Core . Creation
5+ namespace NumSharp . Core
66{
77 static partial class np
88 {
@@ -14,12 +14,68 @@ static partial class np
1414 /// .. versionchanged:: 1.9
1515 /// 1-D and 0-D cases are allowed.
1616 /// </summary>
17- /// <param name="x1"></param>
18- /// <param name="x2"></param>
17+ /// <param name="x1"> 1-D arrays representing the coordinates of a grid </param>
18+ /// /// <param name="x2"> 1-D arrays representing the coordinates of a grid </param>
1919 /// <returns></returns>
20- public static NDArray meshgrid ( NDArray x1 , NDArray x2 )
20+ public static ( NDArray , NDArray ) meshgrid ( NDArray x1 , NDArray x2 , Kwargs kwargs = null )
2121 {
22- throw new NotFiniteNumberException ( ) ;
22+ if ( kwargs == null )
23+ {
24+ kwargs = new Kwargs ( ) ;
25+ }
26+ int ndim = 2 ;
27+ var s0 = ( 1 , 1 ) ;
28+ var output = new NDArray [ ] { np . asanyarray ( x1 ) . reshape ( - 1 , 1 ) , np . asanyarray ( x2 ) . reshape ( 1 , - 1 ) } ;
29+
30+ if ( kwargs . indexing == "xy" && ndim > 1 )
31+ {
32+ // Switch first and second axis
33+ output [ 0 ] . reshape ( 1 , - 1 ) ;
34+ output [ 1 ] . reshape ( - 1 , 1 ) ;
35+ }
36+
37+ if ( ! kwargs . sparse )
38+ {
39+ // Return the full N-D matrix(not only the 1 - D vector)
40+ output = np . broadcast_arrays ( output [ 0 ] , output [ 1 ] , true ) ;
41+ }
42+
43+ if ( kwargs . copy )
44+ {
45+
46+ }
47+
48+ return ( output [ 0 ] , output [ 1 ] ) ;
49+ }
50+
51+ }
52+
53+ public class Kwargs
54+ {
55+ public string indexing { get ; set ; }
56+ public bool sparse { get ; set ; }
57+ public bool copy { get ; set ; }
58+ /// <summary>
59+ /// Kwargs constructor
60+ /// </summary>
61+ /// <param name="indexing"> {'xy', 'ij'}, optional Cartesian('xy', default) or matrix('ij') indexing of output.</param>
62+ /// <param name="sparse">If True a sparse grid is returned in order to conserve memory. Default is False.</param>
63+ /// <param name="copy">If False, a view into the original arrays are returned in order to conserve memory.
64+ /// Default is True.Please note that sparse= False, copy= False`` will likely return non-contiguous arrays.
65+ /// Furthermore, more than one element of a broadcast array may refer to a single memory location.
66+ /// If you need to write to the arrays, make copies first.</param>
67+ public Kwargs ( string indexing , bool sparse , bool copy )
68+ {
69+ this . indexing = indexing ;
70+ this . sparse = sparse ;
71+ this . copy = copy ;
72+ }
73+
74+ public Kwargs ( )
75+ {
76+ this . indexing = "xy" ;
77+ this . sparse = false ;
78+ this . copy = true ;
2379 }
2480 }
2581}
0 commit comments