15 #include <boost/fusion/adapted/std_pair.hpp>
28 namespace MultiDimensional {
31 _indexing{dimensions, labels} {
40 if (input !=
nullptr) {
41 auto serialvals = input->vals();
42 auto serialpos = input->pos();
43 auto serialdims = input->dims();
44 auto seriallabels = input->labels();
45 if (serialdims !=
nullptr && seriallabels !=
nullptr) {
46 vector<IndexLabel> tmplabels;
47 tmplabels.reserve(seriallabels->size());
48 vector<IndexType> tmpdims;
49 tmpdims.reserve(serialdims->size());
50 for (
unsigned int i = 0; i < serialdims->size(); ++i) {
51 tmplabels.push_back(static_cast<IndexLabel>(seriallabels->Get(i)));
52 tmpdims.push_back(serialdims->Get(i));
57 if (serialvals !=
nullptr && serialpos !=
nullptr) {
58 for (
unsigned int i = 0; i < serialvals->size(); ++i) {
59 _data[serialpos->Get(i)] = complex<double>{serialvals->Get(i)->re(), serialvals->Get(i)->im()};
135 return (count_if(
_data.begin(),
_data.end(), [](complex<double> val) ->
bool {
return !
isZero(val); })
136 *
sizeof(complex<double>));
140 return sizeof(complex<double>);
173 return value(coords);
184 return value(start, end);
219 for (
auto& elem :
_data) {
226 for (
auto& elem :
_data) {
233 for (
auto& elem :
_data) {
241 vector<Serial::FBComplex> datalist;
242 vector<uint32_t> poslist;
243 datalist.reserve(
_data.size());
244 poslist.reserve(
_data.size());
245 if (
_data.size() > 4294967295ul) {
246 MSG_ERROR(
"Error saving binary tensor: too many entries!");
250 for (
size_t i = 0; i <
_data.size(); ++i) {
255 auto resc = Serial::FBComplex{
_data[i].real(),
_data[i].imag()};
256 datalist.push_back(resc);
257 poslist.push_back(static_cast<uint32_t>(i));
262 auto serialdata = msgwriter->CreateVectorOfStructs(datalist.data(), datalist.size());
263 auto serialpos = msgwriter->CreateVector(poslist);
264 vector<uint16_t>
dims;
266 dims.push_back(static_cast<uint16_t>(elem));
270 labels.push_back(static_cast<int16_t>(elem));
272 auto serialdims = msgwriter->CreateVector(dims);
273 auto seriallabels = msgwriter->CreateVector(labels);
274 Serial::FBSingleTensorBuilder serialtensor{*msgwriter};
275 serialtensor.add_sparse(
false);
276 serialtensor.add_vals(serialdata);
277 serialtensor.add_pos(serialpos);
278 serialtensor.add_labels(seriallabels);
279 serialtensor.add_dims(serialdims);
280 auto out = serialtensor.Finish();
281 return make_pair(out.Union(), Serial::FBTensorTypes::FBSingleTensor);
309 result->
swap(values);
316 : _it{it}, _maxPosition{maxPos}, _nonZeroPos{nonZeroPos}, _position{pos} {
317 if(_position == 0 && _nonZeroPos == 0 && _maxPosition > 0 &&
isZero(*_it)) {
318 while (_position < _maxPosition &&
isZero(*_it)) {
335 for (
size_t i = 0; i < static_cast<size_t>(n) && _position < _maxPosition; ++i) {
338 while (_position < _maxPosition &&
isZero(*_it)) {
346 for (
size_t i = 0; i < static_cast<size_t>(-n) && _nonZeroPos > 0; ++i) {
359 return _it ==
static_cast<const ItSequential&
>(other)._it;
367 return _nonZeroPos -
static_cast<const ItSequential&
>(other)._nonZeroPos;
std::pair< flatbuffers::Offset< void >, Serial::FBTensorTypes > SerialType
size_t rank() const override
friend TensorData makeVector(IndexList, LabelsList, std::vector< std::complex< double >>)
DataType::const_iterator const_iterator
LabeledIndexing< SequentialIndexing > _indexing
const LabeledIndexing< SequentialIndexing > & getIndexing() const
bool compare(const IContainer &other) const override
std::unique_ptr< ItBase > NonZeroIt
Log & getLog() const
logging facility
reference operator[](PositionType pos)
virtual LabelsList labels() const =0
std::vector< IndexPair > IndexPairList
LabelsList labels() const override
TensorData clone() const override
ItSequential(DataType::const_iterator it, PositionType maxPosition, PositionType pos=0, PositionType nonZeroPos=0)
IContainer & operator*=(double value) override
DataType::iterator iterator
Non-sparse tensor data container.
VectorContainer(const IndexList &dimensions, const LabelsList &labels)
size_t dataSize() const override
void swap(std::vector< std::complex< double >> &values)
Message logging routines.
std::complex< double > ElementType
PositionType position() const override
std::unique_ptr< IContainer > TensorData
bool isSame(const ItBase &other) const override
const ElementType & const_reference
static Log & getLog(const std::string &name)
Get a logger with the given name.
void setValue(const IndexList &indices, ElementType value=0.)
Hammer exception definitions.
size_t numValues() const override
std::vector< IndexType > IndexList
SerialType write(flatbuffers::FlatBufferBuilder *msgwriter) const override
ptrdiff_t distanceFrom(const ItBase &other) const override
ElementType value(const IndexList &indices) const
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
virtual IndexList dims() const =0
IContainer & conjugate() override
bool isZero(const std::complex< double > val)
ElementType value() const override
std::vector< ElementType > DataType
void next(int n=1) override
bool isSameShape(const IContainer &other) const override
IndexPairList getSpinLabelPairs() const override
IndexType labelToIndex(IndexLabel label) const override
reference element(const IndexList &coords={}) override
bool canAddAt(const IContainer &subContainer, IndexLabel coord, IndexType position) const override
std::vector< IndexLabel > LabelsList
bool isAligned() const override
std::set< IndexLabel > UniqueLabelsList
TensorData makeEmptyVector(const IndexList &dimensions, const LabelsList &labels)
IndexPairList getSameLabelPairs(const IContainer &other, const UniqueLabelsList &indices) const override
size_t entrySize() const override
NonZeroIt endNonZero() const override
NonZeroIt firstNonZero() const override
auto end(reversion_wrapper< T > w)
IndexList dims() const override
Serialization related typedefs and includes.