Bugzilla – Attachment 143 Details for
Bug 99
Expression evaluator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
new proof of concept creating and storing evaluators, not expressions
proof_of_concept_v2.cpp (text/plain), 1.76 KB, created by
Gael Guennebaud
on 2011-03-18 19:23:22 UTC
(
hide
)
Description:
new proof of concept creating and storing evaluators, not expressions
Filename:
MIME Type:
Creator:
Gael Guennebaud
Created:
2011-03-18 19:23:22 UTC
Size:
1.76 KB
patch
obsolete
>#include <iostream> > >struct Matrix >{ > Matrix() { data = new int[4]; } > ~Matrix() { delete[] data; } > Matrix(const Matrix& m) { std::cerr << "COPY\n"; } > typedef const Matrix& Nested; > int* data;//[4]; >}; > >template<typename A, typename B> struct Plus >{ > typedef const Plus Nested; > Plus(const A& a, const B& b) : m_a(a), m_b(b) {} > typename A::Nested m_a; > typename B::Nested m_b; >}; > >template<typename A, typename B> struct Product >{ > typedef const Product Nested; > Product(const A& a, const B& b) : m_a(a), m_b(b) {} > typename A::Nested m_a; > typename B::Nested m_b; >}; > >template<typename T> struct evaluator {}; > >template<> struct evaluator<Matrix> >{ > evaluator(const Matrix& m) : m_m(m) {} > int coeff(int i) const { return m_m.data[i]; } > const Matrix& m_m; >}; > >template<typename A, typename B> struct evaluator<Plus<A,B> > >{ > evaluator(const Plus<A,B>& plus) : m_lhs(plus.m_a), m_rhs(plus.m_b) {} > int coeff(int i) const { return m_lhs.coeff(i) + m_rhs.coeff(i); } > evaluator<A> m_lhs; > evaluator<B> m_rhs; >}; > >template<typename A, typename B> struct evaluator<Product<A,B> > >{ > evaluator(const Product<A,B>& plus) : m_lhs(plus.m_a), m_rhs(plus.m_b) > { > for(int i=0;i<4;++i) > res.data[i] = m_lhs.coeff(i) * m_rhs.coeff(i); > } > int coeff(int i) const { return res.data[i]; } > Matrix res; > evaluator<A> m_lhs; > evaluator<B> m_rhs; >}; > >int main() >{ > Matrix a, b, c, d; > for (int i=0;i<4;++i) > { > a.data[i] = i+10; > b.data[i] = i+20; > c.data[i] = i+30; > d.data[i] = i+40; > } > typedef Plus<Matrix, Plus<Matrix, Product<Matrix,Matrix> > > Xpr; > Xpr xpr(a,Plus<Matrix,Product<Matrix,Matrix> >(b,Product<Matrix,Matrix>(c,d) ) ); > evaluator<Xpr> eval(xpr); > for (int i=0;i<4;++i) > std::cout << eval.coeff(i) << " "; > std::cout << "\n"; > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 99
:
28
|
30
|
143
|
156
|
165
|
295
|
400