 
             extern "C" void set_to_without_mask(DevMem2D mat, int depth, const double *scalar, int channels, const cudaStream_t & stream)
             {
-                cudaSafeCall( cudaMemcpyToSymbol(mat_operators::scalar_d, scalar, sizeof(double) * 4));
+                double * scalar_vec = new double [256];
+                int index = 0;
+                for (int i = 0; i < 256; i++)
+                {
+                    scalar_vec[i] = scalar[index];
+                    index++;
+                    if (index == channels) index = 0;
+                }
+                cudaSafeCall( cudaMemcpyToSymbol(mat_operators::scalar_d, scalar_vec, sizeof(double) * 256));
+
+                delete [] scalar_vec;
 
                 static SetToFunc_without_mask tab[8] =
                 {


namespace mat_operators
{
    __constant__ double scalar_d[4];


    template <typename T>


            extern "C" void set_to_with_mask(DevMem2D mat, int depth, const double * scalar, const DevMem2D& mask, int channels, const cudaStream_t & stream)
            {
                double * scalar_vec = new double [256];
                int index = 0;
                for (int i = 0; i < 256; i++)
                {
                    scalar_vec[i] = scalar[index];
                    index++;
                    if (index == channels) index = 0;
                }
                cudaSafeCall( cudaMemcpyToSymbol(mat_operators::scalar_d, scalar_vec, sizeof(double) * 256));

                delete [] scalar_vec;

                static SetToFunc_with_mask tab[8] =
                {
