1+ /* *********************************************************************************/
2+ /* MIT License */
3+ /* */
4+ /* Copyright (c) 2020, 2021 JetBrains-Research */
5+ /* */
6+ /* Permission is hereby granted, free of charge, to any person obtaining a copy */
7+ /* of this software and associated documentation files (the "Software"), to deal */
8+ /* in the Software without restriction, including without limitation the rights */
9+ /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
10+ /* copies of the Software, and to permit persons to whom the Software is */
11+ /* furnished to do so, subject to the following conditions: */
12+ /* */
13+ /* The above copyright notice and this permission notice shall be included in all */
14+ /* copies or substantial portions of the Software. */
15+ /* */
16+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
17+ /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
18+ /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
19+ /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
20+ /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
21+ /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
22+ /* SOFTWARE. */
23+ /* *********************************************************************************/
24+
25+ #include < testing/testing.hpp>
26+
27+ void testVectorExtractSubVector (cuBool_Index m, cuBool_Index N, float density, cuBool_Hints flags) {
28+ cuBool_Vector r, a;
29+
30+ auto ta = testing::Vector::generateSparse (m, density);
31+
32+ ASSERT_EQ (cuBool_Vector_New (&a, m), CUBOOL_STATUS_SUCCESS);
33+ ASSERT_EQ (cuBool_Vector_Build (a, ta.index .data (), ta.nvals , CUBOOL_HINT_VALUES_SORTED), CUBOOL_STATUS_SUCCESS);
34+
35+ for (size_t i = 0 ; i < N; i++) {
36+ auto k = m / N;
37+
38+ ASSERT_EQ (cuBool_Vector_New (&r, k), CUBOOL_STATUS_SUCCESS);
39+ ASSERT_EQ (cuBool_Vector_ExtractSubVector (r, a, i * k, k, flags), CUBOOL_STATUS_SUCCESS);
40+
41+ auto tr = ta.subVector (i * k, k);
42+
43+ ASSERT_TRUE (tr.areEqual (r));
44+ ASSERT_EQ (cuBool_Vector_Free (r), CUBOOL_STATUS_SUCCESS);
45+ }
46+
47+ ASSERT_EQ (cuBool_Vector_Free (a), CUBOOL_STATUS_SUCCESS);
48+ }
49+
50+ void testRun (cuBool_Index m, float step, cuBool_Hints setup) {
51+ // Setup library
52+ EXPECT_EQ (cuBool_Initialize (setup), CUBOOL_STATUS_SUCCESS);
53+
54+ auto N = 10 ;
55+
56+ for (size_t i = 0 ; i < N; i++) {
57+ testVectorExtractSubVector (m, N, 0 .1f + step * ((float ) i), CUBOOL_HINT_NO);
58+ }
59+
60+ // Finalize library
61+ EXPECT_EQ (cuBool_Finalize (), CUBOOL_STATUS_SUCCESS);
62+ }
63+
64+ TEST (cuBool_Matrix, SubVectorExtractSmall) {
65+ cuBool_Index m = 10000 ;
66+ float step = 0 .05f ;
67+ testRun (m, step, CUBOOL_HINT_NO);
68+ }
69+
70+ TEST (cuBool_Matrix, SubVectorExtractMedium) {
71+ cuBool_Index m = 50000 ;
72+ float step = 0 .05f ;
73+ testRun (m, step, CUBOOL_HINT_NO);
74+ }
75+
76+ TEST (cuBool_Matrix, SubVectorExtractLarge) {
77+ cuBool_Index m = 100000 ;
78+ float step = 0 .05f ;
79+ testRun (m, step, CUBOOL_HINT_NO);
80+ }
81+
82+ TEST (cuBool_Matrix, SubVectorExtractSmallFallback) {
83+ cuBool_Index m = 10000 ;
84+ float step = 0 .05f ;
85+ testRun (m, step, CUBOOL_HINT_CPU_BACKEND);
86+ }
87+
88+ TEST (cuBool_Matrix, SubVectorExtractMediumFallback) {
89+ cuBool_Index m = 50000 ;
90+ float step = 0 .05f ;
91+ testRun (m, step, CUBOOL_HINT_CPU_BACKEND);
92+ }
93+
94+ TEST (cuBool_Matrix, SubVectorExtractLargeFallback) {
95+ cuBool_Index m = 100000 ;
96+ float step = 0 .05f ;
97+ testRun (m, step, CUBOOL_HINT_CPU_BACKEND);
98+ }
99+
100+ CUBOOL_GTEST_MAIN
0 commit comments