15 #include <boost/fusion/adapted/std_pair.hpp>
28 namespace MultiDimensional {
31 : _indexing{dimensions, labels} {
38 if(input !=
nullptr) {
39 auto serialvals = input->vals();
40 auto serialpos = input->pos();
41 auto serialdims = input->dims();
42 auto seriallabels = input->labels();
43 if(serialdims !=
nullptr && seriallabels !=
nullptr) {
44 vector<IndexLabel> tmplabels;
45 tmplabels.reserve(seriallabels->size());
46 vector<IndexType> tmpdims;
47 tmpdims.reserve(serialdims->size());
48 for (
unsigned int i = 0; i < serialdims->size(); ++i) {
49 tmplabels.push_back(static_cast<IndexLabel>(seriallabels->Get(i)));
50 tmpdims.push_back(serialdims->Get(i));
54 if(serialvals !=
nullptr && serialpos !=
nullptr) {
55 for (
unsigned int i = 0; i < serialvals->size(); ++i) {
56 _data[
_indexing.posToAlignedPos(serialpos->Get(i))] = complex<double>{serialvals->Get(i)->re(), serialvals->Get(i)->im()};
106 return _data.erase(first, last);
134 return (
sizeof(complex<double>) +
sizeof(
PositionType));
166 return value(coords);
177 return value(start, end);
182 if(tmp ==
nullptr)
return false;
184 if(!dimcheck)
return false;
189 [](
const pair<PositionType, ElementType>& a,
const pair<PositionType, ElementType>& b) ->
bool {
190 return (a.first == b.first) &&
isZero(a.second - b.second);
213 for(
auto& elem:
_data) {
214 elem.second *=
value;
220 for (
auto& elem :
_data) {
221 elem.second *=
value;
228 for (
auto& elem :
_data) {
229 elem.second = conj(elem.second);
236 vector<Serial::FBComplex> datalist;
237 vector<uint32_t> poslist;
238 datalist.reserve(
_data.size());
239 poslist.reserve(
_data.size());
240 if (
_data.size() > 4294967295ul) {
241 MSG_ERROR(
"Error saving binary tensor: too many entries!");
245 for (
auto& elem:
_data) {
246 if (!
isZero(elem.second)) {
250 auto resc = Serial::FBComplex{elem.second.real(), elem.second.imag()};
251 datalist.push_back(resc);
252 poslist.push_back(static_cast<uint32_t>(
_indexing.alignedPosToPos(elem.first)));
257 auto serialdata = msgwriter->CreateVectorOfStructs(datalist.data(), datalist.size());
258 auto serialpos = msgwriter->CreateVector(poslist);
259 vector<uint16_t>
dims;
261 dims.push_back(static_cast<uint16_t>(elem));
265 labels.push_back(static_cast<int16_t>(elem));
267 auto serialdims = msgwriter->CreateVector(dims);
268 auto seriallabels = msgwriter->CreateVector(labels);
269 Serial::FBSingleTensorBuilder serialtensor{*msgwriter};
270 serialtensor.add_sparse(
true);
271 serialtensor.add_vals(serialdata);
272 serialtensor.add_pos(serialpos);
273 serialtensor.add_labels(seriallabels);
274 serialtensor.add_dims(serialdims);
275 auto out = serialtensor.Finish();
276 return make_pair(out.Union(), Serial::FBTensorTypes::FBSingleTensor);
312 return _it ==
static_cast<const ItAligned&
>(other)._it;
320 return distance(static_cast<const ItAligned&>(other)._it, _it);
size_t entrySize() const override
NonZeroIt endNonZero() const override
Log & getLog() const
logging facility
TensorData makeEmptySparse(const IndexList &dimensions, const LabelsList &labels)
std::pair< flatbuffers::Offset< void >, Serial::FBTensorTypes > SerialType
bool compare(const IContainer &other) const override
std::unique_ptr< ItBase > NonZeroIt
const LabeledIndexing< AlignedIndexing > & getIndexing() const
SerialType write(flatbuffers::FlatBufferBuilder *msgwriter) const override
virtual LabelsList labels() const =0
std::vector< IndexPair > IndexPairList
IContainer & conjugate() override
size_t numValues() const override
NonZeroIt firstNonZero() const override
Message logging routines.
IndexList dims() const override
std::complex< double > ElementType
ItAligned(DataType::const_iterator it)
IndexPairList getSameLabelPairs(const IContainer &other, const UniqueLabelsList &indices) const override
std::unique_ptr< IContainer > TensorData
IContainer::ElementType value() const override
static Log & getLog(const std::string &name)
Get a logger with the given name.
LabeledIndexing< AlignedIndexing > _indexing
ValueType getOrDefault(const std::map< KeyType, ValueType > &data, KeyType key, ValueType fallback)
Hammer exception definitions.
void next(int n=1) override
Sparse tensor data container.
std::vector< IndexType > IndexList
DataType::const_iterator const_iterator
ElementType value(const IndexList &indices) const
TensorData clone() const override
bool canAddAt(const IContainer &subContainer, IndexLabel coord, IndexType position) const override
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
virtual IndexList dims() const =0
bool isZero(const std::complex< double > val)
PositionType position() const override
size_t rank() const override
ptrdiff_t distanceFrom(const ItBase &other) const override
std::vector< IndexLabel > LabelsList
std::set< IndexLabel > UniqueLabelsList
iterator erase(const_iterator first, const_iterator last)
bool isSame(const ItBase &other) const override
LabelsList labels() const override
IndexType labelToIndex(IndexLabel label) const override
size_t dataSize() const override
void setValue(const IndexList &indices, ElementType value=0.)
auto end(reversion_wrapper< T > w)
DataType::iterator iterator
Serialization related typedefs and includes.
IndexPairList getSpinLabelPairs() const override
IContainer & operator*=(double value) override
bool isAligned() const override
reference operator[](PositionType pos)
bool isSameShape(const IContainer &other) const override
SparseContainer(const IndexList &dimensions, const LabelsList &labels)
reference element(const IndexList &coords={}) override