Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extent of a matrix local row #107

Closed
devreal opened this issue Nov 15, 2016 · 4 comments
Closed

Extent of a matrix local row #107

devreal opened this issue Nov 15, 2016 · 4 comments

Comments

@devreal
Copy link
Member

devreal commented Nov 15, 2016

Consider the following code:
Consider the row of a two-dimensional matrix in DASH. My expectation was that a row has one dimension less than the number of dimensions of the matrix it belongs to, i.e., 1 for a 2D matrix.

However, the following example shows that a row is still two-dimensional with the extent in one dimension set to 1:

{
    size_t team_size = dash::Team::All().size();
    size_t myid = dash::Team::All().myid();

    dash::TeamSpec<2> teamspec_2d(team_size, 1);
    teamspec_2d.balance_extents();

    dash::SizeSpec<2> sspec(200, 30);
    dash::DistributionSpec<2> dspec(dash::BLOCKED, dash::BLOCKED);

    dash::Matrix<double, 2> matrix(sspec,dspec, dash::Team::All(), teamspec_2d);

    initialize(matrix);
    dash::barrier();

    auto row = matrix.local.row(0);
    auto num_elements = std::distance(row.begin(), row.end());
    std::cout << "[" << dash::myid() << "] local row 0 has " << num_elements << " elements" << std::endl;
    std::cout << "[" << dash::myid() << "] local row 0 has extent(0) " << row.extent(0) << std::endl;
    std::cout << "[" << dash::myid() << "] local row 0 has extent(1) " << row.extent(1) << std::endl;
    std::cout << "[" << dash::myid() << "] local row 0 has " << row.extents().size() << " dimensions" << std::endl;
}

which results in the following output:

[0] local row 0 has 30 elements
[0] local row 0 has extent(0) 1
[0] local row 0 has extent(1) 30
[0] local row 0 has 2 dimensions

The same holds true for a column:

[0] local column 0 has 100 elements
[0] local column 0 has extent(0) 100
[0] local column 0 has extent(1) 1
[0] local column 0 has 2 dimensions

Is this expected behavior? From how I understand the code in LocalMatrixRef, a row is meant to have N-1 columns:

template<typename T, dim_t NumDim, dim_t CUR, class PatternT>
inline LocalMatrixRef<T, NumDim, NumDim-1, PatternT>
LocalMatrixRef<T, NumDim, CUR, PatternT>::row(
  size_type n)
{
  return sub<0>(n);
}
@fuchsto
Copy link
Member

fuchsto commented Nov 15, 2016

No, any view referencing a multi-dimensional container depends on the container type, like dash::Matrix<int, 2> would only be compatible with dash::MatrixRef<int, 2>.

The dimensionality is part of the view type. The behavior (representation) of the type is defined by the second dimension parameter in the view templates (NumDim or CurDim). These are decremented in RA operators and sub<N>.

The dimensionality of views does not change, but their rank does.

A row is equivalent to a slice with extent 1. A slice with extent 2 would not change its dimensionality, so why should it for extent 1?

row.viewspec().rank() should be 1 for a row or column slice.

My suggestion is to remove methods row and col as they are misleading and just syntactic sugar.

@devreal
Copy link
Member Author

devreal commented Nov 15, 2016

A row is equivalent to a slice with extent 1. A slice with extent 2 would not change its dimensionality, so why should it for extent 1?

Because a row or column can be seen as a one-dimensional vector. Of course they can be seen as a special case of an otherwise arbitrary slice as well, hence my confusion.

My suggestion is to remove methods row and col as they are misleading and just syntactic sugar.

What would be the replacement to use?

row.viewspec().rank() should be 1 for a row or column slice.

LocalMatrixRef does not seem to have a viewspec member.

@fuchsto
Copy link
Member

fuchsto commented Nov 15, 2016

Not too happy about the interface and ambiguities myself. I wrote formal semantics of the NArray concept some time ago and the implementation does not comply in places, obviously.
So my job is now to:

  • use NArray specification to document semantics and interfaces of the NArray concept (Doxygen, user guide)
  • add tests for these semantics
  • adjust implementation of Matrix types accordingly

@fuchsto fuchsto added this to the dash-0.3.0 milestone Nov 16, 2016
@fuchsto
Copy link
Member

fuchsto commented Nov 18, 2016

Closed and continued in #117

@fuchsto fuchsto closed this as completed Nov 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants