Skip to content

Commit f6a3abb

Browse files
committed
add cache accessor for private member to test
1 parent fb83400 commit f6a3abb

File tree

4 files changed

+174
-55
lines changed

4 files changed

+174
-55
lines changed

core/base/dense_cache.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ginkgo/core/base/executor.hpp>
1313
#include <ginkgo/core/matrix/dense.hpp>
1414

15+
#include "core/base/dense_cache_accessor.hpp"
1516

1617
namespace gko {
1718
namespace detail {
@@ -38,6 +39,13 @@ void DenseCache<ValueType>::init_from(
3839
}
3940

4041

42+
const array<char>& GenericDenseCacheAccessor::get_workspace(
43+
const GenericDenseCache& cache)
44+
{
45+
return cache.workspace;
46+
}
47+
48+
4149
GenericDenseCache::GenericDenseCache(const GenericDenseCache&) {}
4250

4351

@@ -76,6 +84,26 @@ std::shared_ptr<matrix::Dense<ValueType>> GenericDenseCache::get(
7684
}
7785

7886

87+
std::shared_ptr<const Executor> ScalarCacheAccessor::get_executor(
88+
const ScalarCache& cache)
89+
{
90+
return cache.exec;
91+
}
92+
93+
94+
double ScalarCacheAccessor::get_value(const ScalarCache& cache)
95+
{
96+
return cache.value;
97+
}
98+
99+
100+
const std::map<std::string, std::shared_ptr<const gko::LinOp>>&
101+
ScalarCacheAccessor::get_scalars(const ScalarCache& cache)
102+
{
103+
return cache.scalars;
104+
}
105+
106+
79107
ScalarCache::ScalarCache(std::shared_ptr<const Executor> executor,
80108
double scalar_value)
81109
: exec(std::move(executor)), value(scalar_value){};

core/base/dense_cache_accessor.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: 2025 The Ginkgo authors
2+
//
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
#ifndef GKO_CORE_BASE_DENSE_CACHE_ACCESSOR_HPP_
6+
#define GKO_CORE_BASE_DENSE_CACHE_ACCESSOR_HPP_
7+
8+
9+
#include <iostream>
10+
#include <map>
11+
#include <string>
12+
13+
#include <ginkgo/core/base/array.hpp>
14+
#include <ginkgo/core/base/dense_cache.hpp>
15+
#include <ginkgo/core/base/executor.hpp>
16+
#include <ginkgo/core/base/lin_op.hpp>
17+
18+
19+
namespace gko {
20+
namespace detail {
21+
22+
23+
// helper to access private member for testing
24+
class GenericDenseCacheAccessor {
25+
public:
26+
// access to the workspace
27+
static const array<char>& get_workspace(const GenericDenseCache& cache);
28+
};
29+
30+
31+
// helper to access private member for testing
32+
class ScalarCacheAccessor {
33+
public:
34+
// access to the executor
35+
static std::shared_ptr<const Executor> get_executor(
36+
const ScalarCache& cache);
37+
38+
// access to the value
39+
static double get_value(const ScalarCache& cache);
40+
41+
// access to the scalars
42+
static const std::map<std::string, std::shared_ptr<const gko::LinOp>>&
43+
get_scalars(const ScalarCache& cache);
44+
};
45+
46+
47+
} // namespace detail
48+
} // namespace gko
49+
50+
51+
#endif // GKO_CORE_BASE_DENSE_CACHE_ACCESSOR_HPP_

0 commit comments

Comments
 (0)