Commit cd1b57fe authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

TensorEvalNew::operator() implemented

parent 7de77d05
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ private:
			TensorEvalType tensorEval(*ptr, tensors_, nameToIndexLut_, symmLocal_);

			typename TensorEvalType::HandleType handle = tensorEval();
			while (!handle.done());
			while (!handle);

			VectorSizeType args(1,0);
			const SizeType index = tensorEval.nameToIndexLut("e" + ttos(ind));
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ public:

		typename TensorEvalType::HandleType handle = tensorEval();

		while (!handle.done());
		while (!handle);

		// copy result into m
		SizeType count = 0;
+77 −5
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ along with MERA++. If not, see <http://www.gnu.org/licenses/>.

#include "Tensor.h"
#include "SrepStatement.h"
#include "TensorEvalHandle.h"
#include "SymmetryLocal.h"
#include "NameToIndexLut.h"

@@ -31,7 +30,7 @@ class TensorEval {

public:

	typedef TensorEvalHandle HandleType;
	typedef bool HandleType;
	typedef Tensor<ComplexOrRealType> TensorType;
	typedef typename PsimagLite::Vector<TensorType*>::Type VectorTensorType;
	typedef typename PsimagLite::Vector<SizeType>::Type VectorSizeType;
@@ -42,10 +41,10 @@ public:
	typedef SymmetryLocal SymmetryLocalType;

	TensorEval(const SrepStatementType& tSrep,
	           const VectorTensorType& vt,
	           const VectorTensorType&,
	           const NameToIndexLut<TensorType>&,
	           SymmetryLocalType*,
	           bool = false)
	           bool = false) : srepStatement_(tSrep)
	{}

	SizeType nameToIndexLut(PsimagLite::String name)
@@ -55,13 +54,86 @@ public:

	HandleType operator()()
	{
		throw PsimagLite::RuntimeError("TensorEvalNew::operator: Not implemented yet\n");
		PsimagLite::String copy = srepStatement_.sRep();
		filterForExatn(copy);
		std::cout<<copy<<"\n";
		//Evaluate a tensor network:
		auto evaluated = exatn::evaluateTensorNetwork("srepStatement_.sRep()" , copy);
		TensorType::checkTalshErrorCode(evaluated, "evaluateTensorNetwork");
		PsimagLite::String lhs = srepStatement_.lhs().sRep();
		filterForExatn(lhs);
		auto synced = exatn::sync(lhs);
		return synced;
	}

	void printResult(std::ostream& os) const
	{
		throw PsimagLite::RuntimeError("TensorEvalNew::printResult: Not implemented yet\n");
	}

private:

	static void filterForExatn(PsimagLite::String& str)
	{
		removeAll(str, '*');
		replaceAll(str, '|', ',');
		addMultiplication(str);
	}

	static void removeAll(PsimagLite::String& str, char what)
	{
		PsimagLite::String buffer;
		const SizeType n = str.length();
		for (SizeType i = 0; i < n; ++i)
			if (str[i] != what)
				buffer += str[i];
		str	= buffer;
	}

	static void replaceAll(PsimagLite::String& str, char this1, char that1)
	{
		PsimagLite::String buffer;
		const SizeType n = str.length();
		for (SizeType i = 0; i < n; ++i) {
			if (str[i] == this1)
				buffer += that1;
			else
				buffer += str[i];
		}

		str	= buffer;
	}

	static void addMultiplication(PsimagLite::String& str)
	{
		PsimagLite::String buffer;
		const SizeType n = str.length();
		for (SizeType i = 0; i < n; ++i) {
			if (str[i] == ')' && followsSomething(str, i + 1))
				buffer += ")*";
			else
				buffer += str[i];
		}

		str	= buffer;
	}

	static bool followsSomething(const PsimagLite::String& str, SizeType ind)
	{
		const SizeType n = str.length();
		SizeType i = ind;
		for (; i < n; ++i)
			if (str[i] != ' ' && str[i] != '\t')
				break;

		if (i >= n) return false;

		if (str[i] == '=') return false;

		return true;
	}

	const SrepStatementType& srepStatement_;
};
} // namespace Mera
#endif // TENSOREVALNEW_H
+6 −6
Original line number Diff line number Diff line
@@ -285,6 +285,12 @@ public:
		exatn::finalize();
	}

	static void checkTalshErrorCode(bool code, PsimagLite::String what)
	{
		if (code) return;
		throw PsimagLite::RuntimeError("MERA++: TALSH returned false from " + what + "\n");
	}

	// Tensor with only one dimension
	Tensor(PsimagLite::String name, SizeType dim0, SizeType ins)
	    : name_(name),
@@ -435,12 +441,6 @@ private:
		return index;
	}

	static void checkTalshErrorCode(bool code, PsimagLite::String what)
	{
		if (code) return;
		throw PsimagLite::RuntimeError("MERA++: TALSH returned false from " + what + "\n");
	}

	static PsimagLite::RandomForTests<ComplexOrRealType> rng_;
	PsimagLite::String name_;
	VectorSizeType dimensions_;
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
	TensorEvalType tensorEval(srepEq, vt, nameToIndexLut, 0, false);
	TensorEvalType::HandleType handle = tensorEval();

	while (!handle.done());
	while (!handle);

	tensorEval.printResult(std::cout);