NumCpp icon indicating copy to clipboard operation
NumCpp copied to clipboard

outer function currently doesn't support input arrays of different sizes

Open misungson opened this issue 3 years ago • 0 comments

Describe the bug outer function currently doesn't support input arrays of different sizes

To Reproduce nc::NdArray<double> x = {1., 2.}; nc::NdArray<double> y = {1., 2., 3.}; auto output = nc::outer (x, z);

Expected behavior output should be something like { {1, 2, 3}, {2, 4, 6} }

Code suggestions In addition to below, it would be good for the function to flatten the input arrays.

` template NdArray outer(const NdArray& inArray1, const NdArray& inArray2) { STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype);

const auto size1 = inArray1.size();
const auto size2 = inArray2.size();

auto returnArray = NdArray<dtype>(size1, size2);
for (uint32 row = 0; row < size1; ++row)
{
    const auto array1Value = inArray1[row];

    std::transform(inArray2.begin(), inArray2.end(), returnArray.begin(row),
        [array1Value](dtype value) -> dtype
        {
            return array1Value * value;
        });
}

return returnArray;

} `

misungson avatar Mar 29 '22 17:03 misungson