34 #ifndef CLASSES_LAYOUTS_H_ 35 #define CLASSES_LAYOUTS_H_ 56 virtual idx operator()(
const std::vector<idx>& xs)
const = 0;
64 virtual std::vector<idx> to_coordinates(idx i)
const = 0;
71 virtual std::vector<idx> get_dims()
const = 0;
76 virtual ~ILayout() =
default;
84 class Lattice :
public ILayout {
86 std::vector<idx> dims_;
92 Lattice(
const std::vector<idx>& dims) : dims_{dims} {
96 throw exception::ZeroSize(
"qpp::Lattice::Lattice()");
106 template <
class... Ts>
107 Lattice(Ts... ds) : Lattice(std::vector<idx>{
static_cast<idx
>(ds)...}) {}
117 idx operator()(
const std::vector<idx>& xs)
const override {
120 if (xs.size() != dims_.size())
121 throw exception::DimsNotEqual(
"qpp::Lattice::operator()");
122 for (idx i = 0; i < dims_.size(); ++i)
123 if (xs[i] >= dims_[i])
124 throw exception::OutOfRange(
"qpp::Lattice::operator()");
127 return internal::multiidx2n(xs.data(), dims_.size(), dims_.data());
139 template <
class... Ts>
140 idx operator()(Ts... xs)
const {
141 return operator()(std::vector<idx>{
static_cast<idx
>(xs)...});
150 std::vector<idx> to_coordinates(idx i)
const override {
153 if (i >= prod(dims_))
154 throw exception::OutOfRange(
"qpp::Lattice::to_coordinates()");
157 std::vector<idx> result(dims_.size());
158 internal::n2multiidx(i, dims_.size(), dims_.data(), result.data());
168 std::vector<idx> get_dims()
const override {
return dims_; }
177 class PeriodicBoundaryLattice :
public Lattice {
179 using Lattice::Lattice;
180 using Lattice::operator();
190 idx operator()(
const std::vector<idx>& xs)
const override {
193 if (xs.size() != dims_.size())
194 throw exception::DimsNotEqual(
"qpp::Lattice::operator()");
197 std::vector<idx> xs_copy = xs;
198 for (idx i = 0; i < dims_.size(); ++i)
199 xs_copy[i] = xs[i] % dims_[i];
200 return Lattice::operator()(xs_copy);
Quantum++ main namespace.
Definition: circuits.h:35