|
1276 | 1276 | expect(n.positive_definite?).to be_truthy
|
1277 | 1277 | end
|
1278 | 1278 | end
|
| 1279 | + |
| 1280 | + context "#svd_rank" do |
| 1281 | + FLOAT_DTYPES.each do |dtype| |
| 1282 | + context dtype do |
| 1283 | + #examples from https://www.cliffsnotes.com/study-guides/algebra/linear-algebra/real-euclidean-vector-spaces/the-rank-of-a-matrix |
| 1284 | + it "calculates the rank of matrix using singular value decomposition with NMatrix on rectangular matrix without tolerence" do |
| 1285 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
| 1286 | + a = NMatrix.new([4,3],[2,-1,3, 1,0,1, 0,2,-1, 1,1,4], dtype: dtype) |
| 1287 | + |
| 1288 | + begin |
| 1289 | + rank = a.svd_rank() |
| 1290 | + |
| 1291 | + rank_true = 3 |
| 1292 | + expect(rank).to eq (rank_true) |
| 1293 | + |
| 1294 | + rescue NotImplementedError |
| 1295 | + pending "Suppressing a NotImplementedError when the lapacke plugin is not available" |
| 1296 | + end |
| 1297 | + end |
| 1298 | + |
| 1299 | + it "calculates the rank of matrix using singular value decomposition with NMatrix on rectangular matrix with tolerence" do |
| 1300 | + |
| 1301 | + a = NMatrix.new([4,3],[2,-1,3, 1,0,1, 0,2,-1, 1,1,4], dtype: dtype) |
| 1302 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
| 1303 | + begin |
| 1304 | + rank = a.svd_rank(4) |
| 1305 | + |
| 1306 | + rank_true = 1 |
| 1307 | + expect(rank).to eq (rank_true) |
| 1308 | + |
| 1309 | + rescue NotImplementedError |
| 1310 | + pending "Suppressing a NotImplementedError when the lapacke plugin is not available" |
| 1311 | + end |
| 1312 | + end |
| 1313 | + |
| 1314 | + it "calculates the rank of matrix using singular value decomposition with NMatrix on square matrix without tolerence" do |
| 1315 | + |
| 1316 | + a = NMatrix.new([4,4],[1,-1,1,-1, -1,1,-1,1, 1,-1,1,-1, -1,1,-1,1], dtype: dtype) |
| 1317 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
| 1318 | + begin |
| 1319 | + rank = a.svd_rank() |
| 1320 | + |
| 1321 | + rank_true = 1 |
| 1322 | + expect(rank).to eq (rank_true) |
| 1323 | + |
| 1324 | + rescue NotImplementedError |
| 1325 | + pending "Suppressing a NotImplementedError when the lapacke plugin is not available" |
| 1326 | + end |
| 1327 | + end |
| 1328 | + |
| 1329 | + it "calculates the rank of matrix using singular value decomposition with NMatrix on square matrix with very small tolerence(for float32)" do |
| 1330 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
| 1331 | + a = NMatrix.new([4,4],[1,-1,1,-1, -1,1,-1,1, 1,-1,1,-1, -1,1,-1,1], dtype: :float32) |
| 1332 | + |
| 1333 | + begin |
| 1334 | + rank = a.svd_rank(1.7881389169360773e-08) |
| 1335 | + |
| 1336 | + rank_true = 2 |
| 1337 | + expect(rank).to eq (rank_true) |
| 1338 | + |
| 1339 | + rescue NotImplementedError |
| 1340 | + pending "Suppressing a NotImplementedError when the lapacke plugin is not available" |
| 1341 | + end |
| 1342 | + end |
| 1343 | + |
| 1344 | + it "calculates the rank of matrix using singular value decomposition with NMatrix on square matrix with very small tolerence(for float64)" do |
| 1345 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
| 1346 | + a = NMatrix.new([4,4],[1,-1,1,-1, -1,1,-1,1, 1,-1,1,-1, -1,1,-1,1], dtype: :float64) |
| 1347 | + |
| 1348 | + begin |
| 1349 | + rank = a.svd_rank(1.7881389169360773e-08) |
| 1350 | + |
| 1351 | + rank_true = 1 |
| 1352 | + expect(rank).to eq (rank_true) |
| 1353 | + |
| 1354 | + rescue NotImplementedError |
| 1355 | + pending "Suppressing a NotImplementedError when the lapacke plugin is not available" |
| 1356 | + end |
| 1357 | + end |
| 1358 | + |
| 1359 | + end |
| 1360 | + end |
| 1361 | + end |
| 1362 | + |
1279 | 1363 | end
|
0 commit comments