1function C = GB_spec_resize (A, nrows_new, ncols_new)
2%GB_SPEC_RESIZE a MATLAB mimic of GxB_resize
3%
4% Usage:
5% C = GB_spec_resize (A, nrows_new, ncols_new)
6
7% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
8% SPDX-License-Identifier: Apache-2.0
9
10%-------------------------------------------------------------------------------
11% get inputs
12%-------------------------------------------------------------------------------
13
14if (nargout > 1 || nargin ~= 3)
15    error ('usage: C = GB_spec_resize (A, nrows_new, ncols_new)') ;
16end
17
18C = GB_spec_matrix (A) ;
19c_class = C.class ;
20
21%-------------------------------------------------------------------------------
22% do the work via a clean MATLAB interpretation of the entire GraphBLAS spec
23%-------------------------------------------------------------------------------
24
25[nrows_old ncols_old] = size (C.matrix) ;
26
27if (ncols_new < ncols_old)
28    C.matrix  = C.matrix  (:, 1:ncols_new) ;
29    C.pattern = C.pattern (:, 1:ncols_new) ;
30elseif (ncols_new > ncols_old)
31    z = GB_spec_zeros ([nrows_old, ncols_new - ncols_old], c_class) ;
32    C.matrix  = [C.matrix  z ] ;
33    C.pattern = [C.pattern (false (nrows_old, ncols_new - ncols_old))] ;
34end
35
36if (nrows_new < nrows_old)
37    C.matrix  = C.matrix  (1:nrows_new, :) ;
38    C.pattern = C.pattern (1:nrows_new, :) ;
39elseif (nrows_new > nrows_old)
40    z = GB_spec_zeros ([nrows_new - nrows_old, ncols_new], c_class) ;
41    C.matrix  = [C.matrix  ; z ] ;
42    C.pattern = [C.pattern ; (false (nrows_new - nrows_old, ncols_new))] ;
43end
44
45