| 225 | TYPED_TEST_SUITE(Sparse, SparseTypes); |
| 226 | |
| 227 | TYPED_TEST(Sparse, DeepCopy) { |
| 228 | SUPPORTED_TYPE_CHECK(TypeParam); |
| 229 | |
| 230 | cleanSlate(); |
| 231 | |
| 232 | array s; |
| 233 | { |
| 234 | // Create a sparse array from a dense array. Make sure that the dense |
| 235 | // arrays are removed |
| 236 | array dense = randu(10, 10); |
| 237 | array d = makeSparse<TypeParam>(dense, 5); |
| 238 | s = sparse(d); |
| 239 | } |
| 240 | |
| 241 | // At this point only the sparse array will be allocated in memory. |
| 242 | // Determine how much memory is allocated by one sparse array |
| 243 | size_t alloc_bytes, alloc_buffers; |
| 244 | size_t lock_bytes, lock_buffers; |
| 245 | |
| 246 | deviceMemInfo(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers); |
| 247 | size_t size_of_alloc = lock_bytes; |
| 248 | size_t buffers_per_sparse = lock_buffers; |
| 249 | |
| 250 | { |
| 251 | array s2 = s.copy(); |
| 252 | s2.eval(); |
| 253 | |
| 254 | // Make sure that the deep copy allocated additional memory |
| 255 | deviceMemInfo(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers); |
| 256 | |
| 257 | EXPECT_NE(s.get(), s2.get()) << "The sparse arrays point to the same " |
| 258 | "af_array object."; |
| 259 | EXPECT_EQ(size_of_alloc * 2, lock_bytes) |
| 260 | << "The number of bytes allocated by the deep copy do " |
| 261 | "not match the original array"; |
| 262 | |
| 263 | EXPECT_EQ(buffers_per_sparse * 2, lock_buffers) |
| 264 | << "The number of buffers allocated by the deep " |
| 265 | "copy do not match the original array"; |
| 266 | array d = dense(s); |
| 267 | array d2 = dense(s2); |
| 268 | ASSERT_ARRAYS_EQ(d, d2); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | TYPED_TEST(Sparse, Empty) { |
| 273 | SUPPORTED_TYPE_CHECK(TypeParam); |
nothing calls this directly
no test coverage detected