Boost logo

Ublas :

From: Ashima Atul (ashima_at_[hidden])
Date: 2007-11-27 02:57:28


Thanks for the reply Sourabh, it proved to be helpful. I am facing a
different issue now. The code I sent before did not include boost shared
pointers and in my actual code I use them. I have attached the code
using boost shared pointer below.

The matrices actually contain shared pointer of type myType as their
elements. Now when I try to multiply two matrices with elements of type
myTypePtr (boost shared pointer of type myType) I get an error for
myTypePtr constructor. Since myTypePtr is a boost shared pointer I
cannot write the constructor for boost shared pointer.

Is there a way to work around this problem?

Thanks,
Ashima

Error
*****

/usr/local/include/boost-1_34_1/boost/numeric/ublas/functional.hpp:1197:
error: no matching function for call to
'boost::shared_ptr<myType>::shared_ptr(int)'
/usr/local/include/boost-1_34_1/boost/shared_ptr.hpp:144: note:
candidates are: boost::shared_ptr<T>::shared_ptr() [with T = myType]
/usr/local/include/boost-1_34_1/boost/shared_ptr.hpp:131:
note: boost::shared_ptr<myType>::shared_ptr(const
boost::shared_ptr<myType>&)

Code
*****

#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>

struct myType{
                myType(int i) {}
                myType() {}
                myType(const myType& a) {}
                char a[4];
                int y;
        };

typedef boost::shared_ptr<myType> myTypePtr;

myTypePtr operator+(const myTypePtr& lhs, const myTypePtr& rhs)
 {
        //to add logic for addition
        return lhs;
 }

myTypePtr operator*(const myTypePtr& lhs, const myTypePtr& rhs)
 {
        //to add logic for multiplication
        return lhs;
 }

myTypePtr operator+=(const myTypePtr& lhs, const myTypePtr& rhs)
 {
        //to add logic
        return lhs;
 }

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
typedef matrix< myTypePtr > myTypePtrMatrix;
typedef boost::shared_ptr<myTypePtrMatrix> MatrixPtr;

int main () {
    MatrixPtr m1(new myTypePtrMatrix(3,3));
    MatrixPtr m2(new myTypePtrMatrix(3,3));
    MatrixPtr m3(new myTypePtrMatrix(3,3));

    for (unsigned i = 0; i < 3; ++ i)
        for (unsigned j = 0; j < 3; ++ j){
            myType* t1 = new myType;
            myTypePtr p1(t1);
            (*m1)(i, j) = p1;
            myType* t2 = new myType;
            myTypePtr p2(t2);
            (*m2)(i, j) = p2;

            strcpy( (*m1)(i,j)->a, "ash");
            strcpy( (*m2)(i,j)->a, "ash");
            ((myTypePtr) (*m1) (i, j))->y = ((myTypePtr) (*m2) (i,
j))->y = 7;
        }
     (*m3) = (*m1) + (*m2);
     (*m3) = prod ((*m1), (*m2));

}

Sourabh wrote:
> Hi,
> One way is you can provide a constructor for myType which takes an integer.
> Doing this, will turn off any compiler-generated constructors. So, you
> need to provide another constructor with
> no arguments.
> Something like this:
>
> struct myType{
> myType ()
> {
> //Initialize a, y;
> }
> myType (int i)
> {
> //Initialize a, y;
> }
> char a[4];
> int y;
> };
>
>
> Regards,
> Sourabh
>
> Ashima Atul wrote:
>
>
>> Hi,
>>
>> I am a new user of boost and am trying to do a product of two matrices.
>> The elements inside the matrices are not int/double but are objects of a
>> structure 'myType'. I have added definitions for the required operator
>> overloading functions.
>>
>> But, when I try to compile the code, I get a huge error with all the
>> template information and in the end the error says
>> */usr/local/include/boost-1_34_1/boost/numeric/ublas/functional.hpp:1197:
>> error: no matching function for call to 'myType::myType(int)'
>> matDouble.cpp:4: note: candidates are: myType::myType()
>> matDouble.cpp:4: note: myType::myType(const myType&)
>>
>> *I have attached the whole error at the end.
>>
>> Here's the code :
>>
>> #include <string>
>> #include <iostream>
>>
>> struct myType{
>> char a[4];
>> int y;
>> };
>>
>> myType operator+(const myType& lhs, const myType& rhs)
>> {
>> //to add addition logic
>> return lhs;
>> }
>>
>> myType operator*(const myType& lhs, const myType& rhs)
>> {
>> //to add multiplication logic
>> return lhs;
>> }
>>
>> myType operator+=(const myType& lhs, const myType& rhs)
>> {
>> //to add logic
>> return lhs;
>> }
>>
>> #include <boost/numeric/ublas/matrix.hpp>
>> #include <boost/numeric/ublas/io.hpp>
>> using namespace boost::numeric::ublas;
>> typedef matrix< myType > myTypeMatrix;
>>
>> int main () {
>> myTypeMatrix m1(3,3);
>> myTypeMatrix m2(3,3);
>> myTypeMatrix m3(3,3);
>>
>> for (unsigned i = 0; i < 3; ++ i)
>> for (unsigned j = 0; j < 3; ++ j){
>> strcpy( ((m1)(i,j)).a, "abc");
>> strcpy( ((m2)(i,j)).a, "abc");
>> ((myType) (m1) (i, j)).y = ((myType) (m2) (i, j)).y = 7;
>> }
>> (m3) = prod ((m1), (m2));
>>
>> }
>>
>>
>> Any help regarding this would be highly appreciated.
>>
>> Thanks,
>> Ashima
>>
>>
>> Error
>> *****
>>
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/functional.hpp: In
>> static member function 'static typename
>> boost::numeric::ublas::matrix_matrix_binary_functor<T1, T2,
>> TR>::result_type boost::numeric::ublas::matrix_matrix_prod<T1, T2,
>> TR>::apply(const boost::numeric::ublas::matrix_expression<E1>&, const
>> boost::numeric::ublas::matrix_expression<E2>&, typename
>> boost::numeric::ublas::matrix_matrix_binary_functor<T1, T2,
>> TR>::size_type, typename
>> boost::numeric::ublas::matrix_matrix_binary_functor<T1, T2,
>> TR>::size_type) [with E1 = boost::numeric::ublas::matrix_reference<const
>> boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>>> , E2 = boost::numeric::ublas::matrix_reference<const
>>>>
>> boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>>> , T1 = myType, T2 = myType, TR = myType]':
>>>>
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/matrix_expression.hpp:4239:
>> instantiated from 'typename F::result_type
>> boost::numeric::ublas::matrix_matrix_binary<E1, E2,
>> F>::operator()(typename boost::numeric::ublas::promote_traits<typename
>> E1::size_type, typename E2::size_type>::promote_type, typename
>> boost::numeric::ublas::promote_traits<typename E1::size_type, typename
>> E2::size_type>::promote_type) const [with E1 =
>> boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , E2 = boost::numeric::ublas::matrix<myType,
>>>
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , F = boost::numeric::ublas::matrix_matrix_prod<myType, myType, myType>]'
>>>
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/detail/matrix_assign.hpp:592:
>> instantiated from 'void
>> boost::numeric::ublas::indexing_matrix_assign(M&, const
>> boost::numeric::ublas::matrix_expression<E2>&,
>> boost::numeric::ublas::row_major_tag) [with F =
>> boost::numeric::ublas::scalar_assign, M =
>> boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , E =
>>>
>> boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix<myType,
>>>
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix_matrix_prod<myType, myType, myType> >]'
>>>
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/detail/matrix_assign.hpp:625:
>> instantiated from 'void boost::numeric::ublas::matrix_assign(M&, const
>> boost::numeric::ublas::matrix_expression<E>&,
>> boost::numeric::ublas::dense_proxy_tag, C) [with F =
>> boost::numeric::ublas::scalar_assign, R =
>> boost::numeric::ublas::basic_full<size_t>, M =
>> boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , E =
>>>
>> boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix<myType,
>>>
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix_matrix_prod<myType, myType, myType> >,
>>>
>> C = boost::numeric::ublas::row_major_tag]'
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/detail/matrix_assign.hpp:1215:
>> instantiated from 'void boost::numeric::ublas::matrix_assign(M&, const
>> boost::numeric::ublas::matrix_expression<E2>&) [with F =
>> boost::numeric::ublas::scalar_assign, M =
>> boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , E =
>>>
>> boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix<myType,
>>>
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix_matrix_prod<myType, myType, myType> >]'
>>>
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/matrix.hpp:111:
>> instantiated from 'boost::numeric::ublas::matrix<T, L, A>::matrix(const
>> boost::numeric::ublas::matrix_expression<E1>&) [with AE =
>> boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix<myType,
>>>
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix_matrix_prod<myType, myType, myType> >,
>>>
>> T = myType, L = boost::numeric::ublas::basic_row_major<size_t,
>> ptrdiff_t>, A = boost::numeric::ublas::unbounded_array<myType,
>> std::allocator<myType> >]'
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/matrix.hpp:200:
>> instantiated from 'boost::numeric::ublas::matrix<T, L, A>&
>> boost::numeric::ublas::matrix<T, L, A>::operator=(const
>> boost::numeric::ublas::matrix_expression<E1>&) [with AE =
>> boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<myType,
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix<myType,
>>>
>> boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>,
>> boost::numeric::ublas::unbounded_array<myType, std::allocator<myType> >
>>
>>> , boost::numeric::ublas::matrix_matrix_prod<myType, myType, myType> >,
>>>
>> T = myType, L = boost::numeric::ublas::basic_row_major<size_t,
>> ptrdiff_t>, A = boost::numeric::ublas::unbounded_array<myType,
>> std::allocator<myType> >]'
>> *matDouble.cpp:43: instantiated from here
>> /usr/local/include/boost-1_34_1/boost/numeric/ublas/functional.hpp:1197:
>> error: no matching function for call to 'myType::myType(int)'
>> matDouble.cpp:4: note: candidates are: myType::myType()
>> matDouble.cpp:4: note: myType::myType(const myType&)*
>>
>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>>
>>
>>
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>