0

I'm trying to do multidimensional dot product with two valarray, i.e. return a valarray such that each element is the dot product on two rows of the input valarrays.

I use slices to divide by array into rows. Checking the documentation, it states that * is an operator of slice_array, and I believe I works similarly to * to valarrays. It performs elementwise multiplication between two arrays.

valarray<float> mult(valarray<float> arr1, valarray<float> arr2, int row1, int mid, int col2)
{
    valarray<float> new_arr;
    new_arr.resize(row1*col2);
    for (int i = 0; i < row1*col2; ++i)
    {
    slice s (i*mid,mid,1);
    new_arr[i] = (arr1[s] * arr2[s]).sum();
    }

    return new_arr;
}

The error I keep getting is: |12|error: no match for 'operator*' (operand types are 'std::slice_array<float>' and 'std::slice_array<float>')|

I'm not sure what I'm doing wrong. Before I make my own elementwise multiplying function, is there any mistake in the code or my use of the slice_array?

NukeyFox
  • 11
  • 1
  • 1

1 Answers1

0

Documentation for slice_array says that the interface is

template <class T> class slice_array {
public:
  /* Skipped for brevity */
  void operator*=  (const valarray<T>&) const;
};

In other words, you can multiply a slice by a valaray, but it says nothing about multiplying two slices.

jvd
  • 764
  • 4
  • 14