Skip to content

Commit 9b2ded0

Browse files
committed
Merge branch 'fix_sparse_matrix_write' into 'develop'
fix sparse matrix write See merge request devel/gams-transfer-matlab!82
2 parents 5e528d1 + 9da2b0e commit 9b2ded0

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

+gams/+transfer/+gdx/gt_gdx_write.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ void mexFunction(
493493
{
494494
for (size_t k = 0; k < sizes[1]; k++)
495495
{
496+
bool is_default_rec = true;
497+
496498
/* set domains */
497499
if (dim >= 1)
498500
gdx_uel_index[0] = domain_uel_ids[0][j];
@@ -507,13 +509,16 @@ void mexFunction(
507509
continue;
508510
idx = mx_cols[kk][k] + col_nnz[kk][k];
509511
if (idx >= mx_cols[kk][k+1] || mx_rows[kk][idx] != j)
510-
{
511512
gdx_values[kk] = 0;
512-
continue;
513+
else
514+
{
515+
col_nnz[kk][k]++;
516+
gdx_values[kk] = gt_utils_sv_matlab2gams(mx_values[kk][idx], eps_to_zero);
513517
}
514-
col_nnz[kk][k]++;
515-
gdx_values[kk] = gt_utils_sv_matlab2gams(mx_values[kk][idx], eps_to_zero);
518+
is_default_rec = (gdx_values[kk] != def_values[kk]) ? false : is_default_rec;
516519
}
520+
if (can_skip_default_recs && is_default_rec)
521+
continue;
517522

518523
/* write values */
519524
if (issorted)

.gitlab-ci.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ matlab:build:macos:
232232
stage: matlab:build
233233
tags:
234234
- macos
235+
- clarus
235236
needs: [download:macos]
236237
script:
237238
- mkdir -p macos/matlab
@@ -252,6 +253,7 @@ matlab:build:macos_arm:
252253
stage: matlab:build
253254
tags:
254255
- macos-arm64
256+
- stan
255257
needs: [download:macos_arm]
256258
script:
257259
- mkdir -p macos_arm/matlab
@@ -357,6 +359,7 @@ matlab:test:macos:
357359
stage: matlab:test
358360
tags:
359361
- macos
362+
- clarus
360363
needs: [download:macos, matlab:build:macos]
361364
before_script:
362365
- PATH=$PWD/macos/gdx:$PATH
@@ -379,6 +382,7 @@ matlab:test:macos_arm:
379382
stage: matlab:test
380383
tags:
381384
- macos-arm64
385+
- stan
382386
needs: [download:macos_arm, matlab:build:macos_arm]
383387
before_script:
384388
- PATH=$PWD/macos_arm/gdx:$PATH
@@ -426,14 +430,14 @@ package:
426430
image:
427431
name: $CI_REGISTRY_IMAGE/linux/builder
428432
script:
429-
- cd linux/matlab
430-
- sudo zip -r gams_transfer_matlab_linux.zip +gams
431-
- cd ../../macos/matlab
432-
- sudo zip -r gams_transfer_matlab_macos.zip +gams
433-
- cd ../../macos_arm/matlab
434-
- sudo zip -r gams_transfer_matlab_macos_arm.zip +gams
435-
- cd ../../windows/matlab
436-
- sudo zip -r gams_transfer_matlab_windows.zip +gams
433+
- |
434+
for d in linux macos macos_arm windows
435+
do
436+
cd $d/matlab
437+
sudo zip -r gams_transfer_matlab_$d.zip +gams
438+
cd ../..
439+
mv $d/matlab/gams_transfer_matlab_$d.zip .
440+
done
437441
artifacts:
438442
name: release
439443
paths:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
GAMS Transfer Matlab v1.0.3
2+
==================
3+
- Fixed sparse write of format `sparse_matrix`.
4+
15
GAMS Transfer Matlab v1.0.2
26
==================
37
- Fixed GDX setup.

test/test_readwrite.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
test_readWriteCompress(t, cfg);
3939
test_readWriteDomainCheck(t, cfg);
4040
test_writeEpsToZero(t, cfg);
41+
test_writeSparse(t, cfg);
4142
[~, n_fails1] = t.summary();
4243

4344
t = GAMSTest('readwrite_rc');
@@ -1738,3 +1739,28 @@ function test_writeEpsToZero(t, cfg)
17381739
t.assert(gams.transfer.SpecialValues.isEps(gdx.data.e.records.scale));
17391740

17401741
end
1742+
1743+
function test_writeSparse(t, cfg)
1744+
1745+
gdx = gams.transfer.Container();
1746+
i = gams.transfer.Set(gdx, 'i', '*', 'records', {'i1', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7', 'i8', 'i9', 'i10'});
1747+
gams.transfer.Parameter(gdx, 'p', i, 'records', {{'i2', 'i6'}, [2 6]});
1748+
1749+
t.add('write_sparse_sparse_matrix');
1750+
gdx.data.p.transformRecords('sparse_matrix');
1751+
gdx.write('test.gdx');
1752+
t.assert(~system(sprintf('gdxdump %s Symbols | grep -q "p *1 *Par *2"', 'test.gdx')));
1753+
1754+
t.add('write_sparse_struct');
1755+
gdx.data.p.transformRecords('struct');
1756+
gdx.write('test.gdx');
1757+
t.assert(~system(sprintf('gdxdump %s Symbols | grep -q "p *1 *Par *2"', 'test.gdx')));
1758+
1759+
if gams.transfer.Constants.SUPPORTS_TABLE
1760+
t.add('write_sparse_table');
1761+
gdx.data.p.transformRecords('table');
1762+
gdx.write('test.gdx');
1763+
t.assert(~system(sprintf('gdxdump %s Symbols | grep -q "p *1 *Par *2"', 'test.gdx')));
1764+
end
1765+
1766+
end

0 commit comments

Comments
 (0)