Skip to content

Commit

Permalink
transposed delta matrix should be cols X rows (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
swilly22 committed Sep 17, 2021
1 parent d35d498 commit 90351f2
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/graph/rg_matrix/rg_new.c
Expand Up @@ -76,13 +76,13 @@ GrB_Info RG_Matrix_new
info = _RG_Matrix_init(matrix, type, nrows, ncols);
ASSERT(info == GrB_SUCCESS);

//----------------------------------------------------------------------------
//--------------------------------------------------------------------------
// create transpose matrix if required
//----------------------------------------------------------------------------
//--------------------------------------------------------------------------

if(type == GrB_UINT64) {
matrix->transposed = rm_calloc(1, sizeof(_RG_Matrix));
info = _RG_Matrix_init(matrix->transposed, GrB_BOOL, nrows, ncols);
info = _RG_Matrix_init(matrix->transposed, GrB_BOOL, ncols, nrows);
ASSERT(info == GrB_SUCCESS);
}

Expand Down
2 changes: 1 addition & 1 deletion src/graph/rg_matrix/rg_resize.c
Expand Up @@ -17,7 +17,7 @@ GrB_Info RG_Matrix_resize // change the size of a matrix
GrB_Info info;

if(RG_MATRIX_MAINTAIN_TRANSPOSE(C)) {
info = RG_Matrix_resize(C->transposed, nrows_new, ncols_new);
info = RG_Matrix_resize(C->transposed, ncols_new, nrows_new);
ASSERT(info == GrB_SUCCESS);
}

Expand Down
84 changes: 83 additions & 1 deletion tests/unit/test_rg_matrix.cpp
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 Redis Labs Ltd. and Contributors
* Copyright 2018-2021 Redis Labs Ltd. and Contributors
*
* This file is available under the Redis Labs Source Available License Agreement
*/
Expand Down Expand Up @@ -1451,6 +1451,88 @@ TEST_F(RGMatrixTest, RGMatrix_mxm) {
ASSERT_TRUE(C == NULL);
}

TEST_F(RGMatrixTest, RGMatrix_resize) {
RG_Matrix A = NULL;
RG_Matrix T = NULL;
GrB_Info info = GrB_SUCCESS;
GrB_Type t = GrB_UINT64;
GrB_Index nrows = 10;
GrB_Index ncols = 20;

info = RG_Matrix_new(&A, t, nrows, ncols);
T = RG_Matrix_getTranspose(A);

GrB_Index A_nrows;
GrB_Index A_ncols;
GrB_Index T_nrows;
GrB_Index T_ncols;

// verify A and T dimensions
RG_Matrix_nrows(&A_nrows, A);
ASSERT_EQ(info, GrB_SUCCESS);
RG_Matrix_ncols(&A_ncols, A);
ASSERT_EQ(info, GrB_SUCCESS);

ASSERT_EQ(A_nrows, nrows);
ASSERT_EQ(A_ncols, ncols);

RG_Matrix_nrows(&T_nrows, T);
ASSERT_EQ(info, GrB_SUCCESS);
RG_Matrix_ncols(&T_ncols, T);
ASSERT_EQ(info, GrB_SUCCESS);

ASSERT_EQ(T_nrows, ncols);
ASSERT_EQ(T_ncols, nrows);

// resize matrix, increase size by 2
nrows *= 2;
ncols *= 2;

info = RG_Matrix_resize(A, nrows, ncols);
ASSERT_EQ(info, GrB_SUCCESS);

// verify A and T dimensions
RG_Matrix_nrows(&A_nrows, A);
ASSERT_EQ(info, GrB_SUCCESS);
RG_Matrix_ncols(&A_ncols, A);
ASSERT_EQ(info, GrB_SUCCESS);

ASSERT_EQ(A_nrows, nrows);
ASSERT_EQ(A_ncols, ncols);

RG_Matrix_nrows(&T_nrows, T);
ASSERT_EQ(info, GrB_SUCCESS);
RG_Matrix_ncols(&T_ncols, T);
ASSERT_EQ(info, GrB_SUCCESS);

ASSERT_EQ(T_nrows, ncols);
ASSERT_EQ(T_ncols, nrows);

// resize matrix decrease size by 2
nrows /= 2;
ncols /= 2;

info = RG_Matrix_resize(A, nrows, ncols);
ASSERT_EQ(info, GrB_SUCCESS);

// verify A and T dimensions
RG_Matrix_nrows(&A_nrows, A);
ASSERT_EQ(info, GrB_SUCCESS);
RG_Matrix_ncols(&A_ncols, A);
ASSERT_EQ(info, GrB_SUCCESS);

ASSERT_EQ(A_nrows, nrows);
ASSERT_EQ(A_ncols, ncols);

RG_Matrix_nrows(&T_nrows, T);
ASSERT_EQ(info, GrB_SUCCESS);
RG_Matrix_ncols(&T_ncols, T);
ASSERT_EQ(info, GrB_SUCCESS);

ASSERT_EQ(T_nrows, ncols);
ASSERT_EQ(T_ncols, nrows);
}

//#ifndef RG_DEBUG
//// test RGMatrix_pending
//// if RG_DEBUG is defined, each call to setElement will flush all 3 matrices
Expand Down

0 comments on commit 90351f2

Please sign in to comment.