2323using System . Text ;
2424using System . Globalization ;
2525using System . Collections ;
26- using NumSharp . Core ;
2726using System . Numerics ;
2827
2928namespace NumSharp . Core
3029{
3130 public partial class NDArray
3231 {
32+ public static implicit operator NDArray ( float d )
33+ {
34+ var ndArray = new NDArray ( typeof ( float ) , new int [ 0 ] ) ;
35+ ndArray . Storage . SetData ( new float [ ] { d } ) ;
36+
37+ return ndArray ;
38+ }
39+
3340 public static implicit operator float ( NDArray nd )
3441 {
3542 if ( nd . ndim > 0 )
@@ -38,20 +45,20 @@ public static implicit operator float(NDArray nd)
3845 return nd . Data < float > ( 0 ) ;
3946 }
4047
41- public static implicit operator NDArray ( float d )
48+ public static implicit operator NDArray ( double d )
4249 {
43- var ndArray = new NDArray ( typeof ( float ) , new int [ 0 ] ) ;
44- ndArray . Storage . SetData ( new float [ ] { d } ) ;
50+ var ndArray = new NDArray ( typeof ( double ) , new int [ 0 ] ) ;
51+ ndArray . Storage . SetData ( new double [ ] { d } ) ;
4552
4653 return ndArray ;
4754 }
4855
49- public static implicit operator NDArray ( double d )
56+ public static implicit operator double ( NDArray nd )
5057 {
51- var ndArray = new NDArray ( typeof ( double ) , new int [ 0 ] ) ;
52- ndArray . Storage . SetData ( new double [ ] { d } ) ;
58+ if ( nd . ndim > 0 )
59+ throw new IncorrectShapeException ( ) ;
5360
54- return ndArray ;
61+ return nd . Data < double > ( 0 ) ;
5562 }
5663
5764 public static implicit operator NDArray ( short d )
@@ -62,6 +69,14 @@ public static implicit operator NDArray(short d)
6269 return ndArray ;
6370 }
6471
72+ public static implicit operator short ( NDArray nd )
73+ {
74+ if ( nd . ndim > 0 )
75+ throw new IncorrectShapeException ( ) ;
76+
77+ return nd . Data < short > ( 0 ) ;
78+ }
79+
6580 public static implicit operator NDArray ( int d )
6681 {
6782 var ndArray = new NDArray ( typeof ( int ) , new int [ 0 ] ) ;
@@ -70,6 +85,14 @@ public static implicit operator NDArray(int d)
7085 return ndArray ;
7186 }
7287
88+ public static implicit operator int ( NDArray nd )
89+ {
90+ if ( nd . ndim > 0 )
91+ throw new IncorrectShapeException ( ) ;
92+
93+ return nd . Data < int > ( 0 ) ;
94+ }
95+
7396 public static implicit operator NDArray ( long d )
7497 {
7598 var ndArray = new NDArray ( typeof ( Int64 ) , new int [ 0 ] ) ;
@@ -78,6 +101,14 @@ public static implicit operator NDArray(long d)
78101 return ndArray ;
79102 }
80103
104+ public static implicit operator long ( NDArray nd )
105+ {
106+ if ( nd . ndim > 0 )
107+ throw new IncorrectShapeException ( ) ;
108+
109+ return nd . Data < long > ( 0 ) ;
110+ }
111+
81112 public static implicit operator NDArray ( Complex d )
82113 {
83114 var ndArray = new NDArray ( typeof ( Complex ) , new int [ 0 ] ) ;
0 commit comments