Thrust Complex Transform of 3 different vectors

Hello I have this loop in C+, and I was trying to convert it to thrust but without getting the same results…

Any ideas?

thank you

C++ Code

for (i=0;i<n;i++) 

        for (j=0;j<n;j++) 

          values[i]=values[i]+(binv[i*n+j]*d[j]);

Thrust Code

thrust::fill(values.begin(), values.end(), 0);

    thrust::transform(make_zip_iterator(make_tuple(

    				thrust::make_permutation_iterator(values.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexDivFunctor(n))),

    				binv.begin(),

    				thrust::make_permutation_iterator(d.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexModFunctor(n))))),

    				make_zip_iterator(make_tuple(

    				thrust::make_permutation_iterator(values.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexDivFunctor(n))) + n,

    				binv.end(),

    				thrust::make_permutation_iterator(d.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexModFunctor(n))) + n)),

    				thrust::make_permutation_iterator(values.begin(), thrust::make_transform_iterator(thrust::make_counting_iterator(0), IndexDivFunctor(n))),

    				function1()

    				);

Thrust Functions

struct IndexDivFunctor: thrust::unary_function<int, int>

    {

      int n;

IndexDivFunctor(int n_) : n(n_) {}

__host__ __device__

      int operator()(int idx)

      {

        return idx / n;

      }

    };

struct IndexModFunctor: thrust::unary_function<int, int>

    {

      int n;

IndexModFunctor(int n_) : n(n_) {}

__host__ __device__

      int operator()(int idx)

      {

        return idx % n;

      }

    };

struct function1

    {

      template <typename Tuple>

      __host__ __device__

      double operator()(Tuple v)

      {

        return thrust::get<0>(v) + thrust::get<1>(v) * thrust::get<2>(v);

      }

    };