1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System ;
3+ using System . Collections . Generic ;
4+ using System . Text ;
5+ using NumSharp . Core . Extensions ;
6+ using NumSharp . Core ;
7+
8+ namespace NumSharp . UnitTest
9+ {
10+ [ TestClass ]
11+ public class ImplicitCastTester
12+ {
13+ [ TestMethod ]
14+ public void FromDotNetVector ( )
15+ {
16+ NDArray nd = new double [ ] { 1 , 2 , 3 , 4 } ;
17+
18+ Assert . IsTrue ( ( ( double ) nd [ 0 ] ) == 1 ) ;
19+ Assert . IsTrue ( ( ( double ) nd [ 1 ] ) == 2 ) ;
20+ Assert . IsTrue ( ( ( double ) nd [ 2 ] ) == 3 ) ;
21+ Assert . IsTrue ( ( ( double ) nd [ 3 ] ) == 4 ) ;
22+ }
23+ [ TestMethod ]
24+ public void FromDotNetMatrix ( )
25+ {
26+ NDArray nd = new double [ , ] { { 1 , 2 , 3 } , { 4 , 5 , 6 } } ;
27+
28+ var doubleMatr = new double [ , ] { { 1 , 2 , 3 } , { 4 , 5 , 6 } } ;
29+
30+ for ( int idx = 0 ; idx < doubleMatr . GetLength ( 0 ) ; idx ++ )
31+ for ( int jdx = 0 ; jdx < doubleMatr . GetLength ( 1 ) ; jdx ++ )
32+ Assert . IsTrue ( ( double ) nd [ idx , jdx ] == doubleMatr [ idx , jdx ] ) ;
33+ }
34+
35+ [ TestMethod ]
36+ public void FromAndToDotNetMatrix ( )
37+ {
38+ NDArray nd = new double [ , ] { { 1 , 2 , 3 } , { 4 , 5 , 6 } } ;
39+
40+ double [ , ] nd_ = new double [ , ] { { 1 , 2 , 3 } , { 4 , 5 , 6 } } ;
41+
42+ Array arr = nd ;
43+
44+ double [ , ] doubleMatr = ( double [ , ] ) arr ;
45+
46+ for ( int idx = 0 ; idx < doubleMatr . GetLength ( 0 ) ; idx ++ )
47+ for ( int jdx = 0 ; jdx < doubleMatr . GetLength ( 1 ) ; jdx ++ )
48+ {
49+ Assert . IsTrue ( ( double ) nd [ idx , jdx ] == doubleMatr [ idx , jdx ] ) ;
50+ Assert . IsTrue ( nd_ [ idx , jdx ] == doubleMatr [ idx , jdx ] ) ;
51+ }
52+
53+ }
54+ [ TestMethod ]
55+ public void StringCast ( )
56+ {
57+ NDArray nd = "[1,2,3;4,5,6]" ;
58+
59+ var doubleMatr = new double [ , ] { { 1 , 2 , 3 } , { 4 , 5 , 6 } } ;
60+
61+ for ( int idx = 0 ; idx < doubleMatr . GetLength ( 0 ) ; idx ++ )
62+ for ( int jdx = 0 ; jdx < doubleMatr . GetLength ( 1 ) ; jdx ++ )
63+ Assert . IsTrue ( ( double ) nd [ idx , jdx ] == doubleMatr [ idx , jdx ] ) ;
64+ }
65+
66+ }
67+
68+ }
0 commit comments