1515 */
1616
1717#include < runtime/local/datagen/GenGivenVals.h>
18+ #include < runtime/local/datastructures/DataObjectFactory.h>
1819#include < runtime/local/datastructures/DenseMatrix.h>
1920#include < runtime/local/datastructures/Frame.h>
2021#include < runtime/local/kernels/CastObjSca.h>
2122#include < runtime/local/kernels/CheckEq.h>
2223
23- #include < catch.hpp>
24- #include < cstdint>
2524#include < tags.h>
25+
26+ #include < catch.hpp>
27+
2628#include < vector>
2729
28- TEMPLATE_TEST_CASE (" castObjSca, matrix to scalar" , TAG_KERNELS, double , float , int64_t , uint64_t , int32_t , uint32_t ) {
30+ #include < cstdint>
31+
32+ TEMPLATE_TEST_CASE (" castObjSca, matrix to scalar, single-element" , TAG_KERNELS, double , float , int64_t , uint64_t ,
33+ int32_t , uint32_t ) {
2934 using VTRes = TestType;
3035
31- VTRes res = VTRes (0 );
3236 SECTION (" DenseMatrix<int64_t> to VTRes" ) {
33- VTRes exp = 2 ;
34- auto m0 = genGivenVals<DenseMatrix< int64_t >>( 1 , { static_cast < int64_t >(exp)} );
35- res = castObjSca<VTRes, DenseMatrix<int64_t >>(m0 , nullptr );
37+ auto arg = genGivenVals<DenseMatrix< int64_t >>( 1 , { static_cast < int64_t >( 2 )}) ;
38+ VTRes exp = VTRes ( 2 );
39+ VTRes res = castObjSca<VTRes, DenseMatrix<int64_t >>(arg , nullptr );
3640 CHECK (res == exp);
37- DataObjectFactory::destroy (m0 );
41+ DataObjectFactory::destroy (arg );
3842 }
39-
4043 SECTION (" DenseMatrix<double> to VTRes" ) {
41- VTRes exp = 2.2 ;
42- auto m0 = genGivenVals<DenseMatrix< double >>( 1 , { static_cast < double >(exp)} );
43- res = castObjSca<VTRes, DenseMatrix<double >>(m0 , nullptr );
44+ auto arg = genGivenVals<DenseMatrix< double >>( 1 , { static_cast < double >( 2.2 )}) ;
45+ VTRes exp = VTRes ( 2.2 );
46+ VTRes res = castObjSca<VTRes, DenseMatrix<double >>(arg , nullptr );
4447 CHECK (res == exp);
45- DataObjectFactory::destroy (m0 );
48+ DataObjectFactory::destroy (arg );
4649 }
4750}
4851
49- TEMPLATE_TEST_CASE (" castObjSca, frame to scalar" , TAG_KERNELS, double , float , int64_t , uint64_t , int32_t , uint32_t ) {
50- using VTRes = TestType;
52+ TEMPLATE_TEST_CASE (" castObjSca, matrix to scalar, non-single-element " , TAG_KERNELS, double , int64_t , uint32_t ) {
53+ using VT = TestType;
5154
52- Frame *arg = nullptr ;
53- SECTION (" Frame[double] to VTRes" ) {
54- VTRes exp = 2.2 ;
55+ DenseMatrix<VT> *arg;
56+ SECTION (" zero-element" ) { arg = DataObjectFactory::create<DenseMatrix<VT>>(0 , 0 , false ); }
57+ SECTION (" multi-element (nx1)" ) { arg = genGivenVals<DenseMatrix<VT>>(2 , {VT (1 ), VT (2 )}); }
58+ SECTION (" multi-element (1xm)" ) { arg = genGivenVals<DenseMatrix<VT>>(1 , {VT (1 ), VT (2 )}); }
59+ SECTION (" multi-element (nxm)" ) { arg = genGivenVals<DenseMatrix<VT>>(2 , {VT (1 ), VT (2 ), VT (3 ), VT (4 )}); }
60+ VT res;
61+ CHECK_THROWS (res = castObjSca<VT, DenseMatrix<VT>>(arg, nullptr ));
62+ DataObjectFactory::destroy (arg);
63+ }
5564
56- auto m0 = genGivenVals<DenseMatrix< double >>( 1 , { static_cast < double >(exp)});
57- std::vector<Structure *> cols = {m0};
58- arg = DataObjectFactory::create<Frame>(cols, nullptr ) ;
65+ TEMPLATE_TEST_CASE ( " castObjSca, frame to scalar, single-element " , TAG_KERNELS, double , float , int64_t , uint64_t ,
66+ int32_t , uint32_t ) {
67+ using VTRes = TestType ;
5968
69+ SECTION (" Frame[int64_t] to VTRes" ) {
70+ auto argC0 = genGivenVals<DenseMatrix<int64_t >>(1 , {static_cast <int64_t >(2 )});
71+ std::vector<Structure *> cols = {argC0};
72+ auto arg = DataObjectFactory::create<Frame>(cols, nullptr );
73+ VTRes exp = VTRes (2 );
6074 VTRes res = castObjSca<VTRes, Frame>(arg, nullptr );
6175 CHECK (res == exp);
62- DataObjectFactory::destroy (m0 );
76+ DataObjectFactory::destroy (argC0, arg );
6377 }
64-
65- SECTION (" Frame[int64_t] to VTRes" ) {
66- VTRes exp = 2 ;
67-
68- auto m0 = genGivenVals<DenseMatrix<int64_t >>(1 , {static_cast <int64_t >(exp)});
69- std::vector<Structure *> cols = {m0};
70- arg = DataObjectFactory::create<Frame>(cols, nullptr );
71-
78+ SECTION (" Frame[double] to VTRes" ) {
79+ auto argC0 = genGivenVals<DenseMatrix<double >>(1 , {static_cast <double >(2.2 )});
80+ std::vector<Structure *> cols = {argC0};
81+ auto arg = DataObjectFactory::create<Frame>(cols, nullptr );
82+ VTRes exp = VTRes (2.2 );
7283 VTRes res = castObjSca<VTRes, Frame>(arg, nullptr );
7384 CHECK (res == exp);
74- DataObjectFactory::destroy (m0 );
85+ DataObjectFactory::destroy (argC0, arg );
7586 }
76- DataObjectFactory::destroy (arg);
7787}
88+
89+ TEMPLATE_TEST_CASE (" castObjSca, frame to scalar, non-single-element" , TAG_KERNELS, double , int64_t , uint32_t ) {
90+ using VT = TestType;
91+
92+ Frame *arg;
93+ DenseMatrix<VT> *argC0;
94+ SECTION (" zero-element" ) {
95+ argC0 = DataObjectFactory::create<DenseMatrix<VT>>(0 , 1 , false );
96+ std::vector<Structure *> cols = {argC0};
97+ arg = DataObjectFactory::create<Frame>(cols, nullptr );
98+ }
99+ SECTION (" multi-element (nx1)" ) {
100+ argC0 = genGivenVals<DenseMatrix<VT>>(2 , {VT (1 ), VT (2 )});
101+ std::vector<Structure *> cols = {argC0};
102+ arg = DataObjectFactory::create<Frame>(cols, nullptr );
103+ }
104+ SECTION (" multi-element (1xm)" ) {
105+ argC0 = genGivenVals<DenseMatrix<VT>>(1 , {VT (1 )});
106+ std::vector<Structure *> cols = {argC0, argC0};
107+ arg = DataObjectFactory::create<Frame>(cols, nullptr );
108+ }
109+ SECTION (" multi-element (nxm)" ) {
110+ argC0 = genGivenVals<DenseMatrix<VT>>(2 , {VT (1 ), VT (2 )});
111+ std::vector<Structure *> cols = {argC0, argC0};
112+ arg = DataObjectFactory::create<Frame>(cols, nullptr );
113+ }
114+ VT res;
115+ CHECK_THROWS (res = castObjSca<VT, Frame>(arg, nullptr ));
116+ DataObjectFactory::destroy (argC0, arg);
117+ }
0 commit comments