Skip to content

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

Description

@misungson

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;

}
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions