{"id":3851,"date":"2025-08-12T09:42:54","date_gmt":"2025-08-12T13:42:54","guid":{"rendered":"https:\/\/blogs.mathworks.com\/matlab\/?p=3851"},"modified":"2025-08-13T06:40:37","modified_gmt":"2025-08-13T10:40:37","slug":"new-in-matlab-single-precision-sparse-matrices","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/matlab\/2025\/08\/12\/new-in-matlab-single-precision-sparse-matrices\/","title":{"rendered":"New in MATLAB: Single precision sparse matrices"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/sparse.html\"><span>Sparse matrices<\/span><\/a><span> have been in MATLAB for a long time but, up until now, the only types of sparse matrices you could create were  <\/span><span style=' font-family: monospace;'>double<\/span><span> or <\/span><span style=' font-family: monospace;'>logical <\/span><span>sparse matrices.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This is no longer the case and one of the thousands of new features in <\/span><a href = \"https:\/\/blogs.mathworks.com\/matlab\/2025\/05\/15\/matlab-r2025a-has-been-released-whats-new\/\"><span>MATLAB R2025a<\/span><\/a><span> is the fact that you can now create and use <\/span><span style=' font-family: monospace;'>single<\/span><span> precision sparse matrices. For example, here is how you create a random single precision sparse matrix of size 50 <\/span><span style=' font-family: monospace;'>x<\/span><span> 100 with density 0.001.<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >mySparseSingleMat = sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"1EC27586\" prevent-scroll=\"true\" data-testid=\"output_0\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"94\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">mySparseSingleMat = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">50\u00d7100 sparse single matrix (5 nonzeros)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  (39,4)       0.7142\r\n  (46,67)      0.9240\r\n   (4,69)      0.8103\r\n  (37,74)      0.5364\r\n  (33,89)      0.0137\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The <\/span><span style=' font-family: monospace;'>\"single\"<\/span><span> argument is new and is also available for several other sparse matrix creation functions such as <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/sparse.html\"><span style=' font-family: monospace;'>sparse<\/span><\/a><span style=' font-family: monospace;'>, <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/speye.html\"><span style=' font-family: monospace;'>speye<\/span><\/a><span style=' font-family: monospace;'>, <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/spalloc.html\"><span style=' font-family: monospace;'>spalloc<\/span><\/a><span style=' font-family: monospace;'>, <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/sprandn.html\"><span style=' font-family: monospace;'>sprandn<\/span><\/a><span style=' font-family: monospace;'> <\/span><span>and <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/sprandsym.html\"><span style=' font-family: monospace;'>sprandsym<\/span><\/a><span style=' font-family: monospace;'>.<\/span><span> As with previous versions, if you don't specify any type then the default is <\/span><span style=' font-family: monospace;'>double<\/span><span> but you can now also be explicit if you prefer.<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >mySpeyeSingleMat = speye(5,<\/span><span style=\"color: rgb(167, 9, 245);\">\"double\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"28AF8F64\" prevent-scroll=\"true\" data-testid=\"output_1\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"94\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">mySpeyeSingleMat = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">5\u00d75 sparse double matrix (5 nonzeros)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">   (1,1)        1\r\n   (2,2)        1\r\n   (3,3)        1\r\n   (4,4)        1\r\n   (5,5)        1\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Support for single precision sparse matrices has been on many people's wish-lists for a long time and its great news that we now have them. In the remainder of this post I'm going to dig into some of the details about why single precision sparse matrices are useful, why it was a lot of work to add them to MATLAB and a couple of tips about best practice when using them. <\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Single precision sparse matrices save memory<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>A <\/span><span style=' font-family: monospace;'>double<\/span><span> precision number requires 64-bits (8 bytes) to store it while a <\/span><span style=' font-family: monospace;'>single<\/span><span> precision number uses 32-bits (4 bytes). So, the first benefit of using a <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrix is that it requires less memory compared to the <\/span><span style=' font-family: monospace;'>double<\/span><span> version <\/span><span style=' font-weight: bold;'>but at the cost of reduced precision<\/span><span>. Given this information, your first guess might be that a <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrix requires half the space of a <\/span><span style=' font-family: monospace;'>double<\/span><span> sparse matrix, which is the case for dense matrices. If so, your first guess is wrong<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >mySparseDoubleMat = sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">\"double\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"099B8C15\" prevent-scroll=\"true\" data-testid=\"output_2\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"94\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">mySparseDoubleMat = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">50\u00d7100 sparse double matrix (5 nonzeros)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  (27,5)       0.8934\r\n  (45,5)       0.4957\r\n  (45,39)      0.3892\r\n  (31,68)      0.2711\r\n  (11,81)      0.1672\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>We use the <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/whos.html?searchHighlight=whos\"><span style=' font-family: monospace;'>whos<\/span><\/a><span> function to determine how much memory this matrix is using<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >whos <\/span><span style=\"color: rgb(167, 9, 245);\">mySparseDoubleMat<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"9DF9A1CF\" prevent-scroll=\"true\" data-testid=\"output_3\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"46\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  Name                    Size             Bytes  Class     Attributes\r\n\r\n  mySparseDoubleMat      50x100              888  double    sparse    <\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's now create a <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrix with the same size and with the same number of non-zero elements<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >mySparseSingleMat = sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"B408A508\" prevent-scroll=\"true\" data-testid=\"output_4\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"94\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">mySparseSingleMat = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">50\u00d7100 sparse single matrix (5 nonzeros)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  (20,6)       0.2901\r\n  (44,19)      0.7310\r\n  (19,76)      0.2183\r\n  (34,85)      0.7405\r\n  (22,92)      0.9392\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Again, we show how much memory this is using<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >whos <\/span><span style=\"color: rgb(167, 9, 245);\">mySparseSingleMat<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"ADC7C6FE\" prevent-scroll=\"true\" data-testid=\"output_5\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"46\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  Name                    Size             Bytes  Class     Attributes\r\n\r\n  mySparseSingleMat      50x100              868  single    sparse    <\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The <\/span><span style=' font-family: monospace;'>double<\/span><span> sparse matrix is using 888 bytes while <\/span><span style=' font-family: monospace;'>single<\/span><span style=' font-weight: bold;'> <\/span><span>sparse is using 868 bytes -- a saving of only 20 bytes! The reason for this is that along with the actual values of the non-zeros, sparse matrices have to store their locations. The memory required for location storage of the non-zeros is the same no matter what precision the actual values are.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In the two examples given above, the memory required for the storage of the locations of the non-zeros is identical. The difference between them is simply that the 5 non-zeros are stored as <\/span><span style=' font-family: monospace;'>double<\/span><span> in the first case (and hence taking up 40 bytes) and <\/span><span style=' font-family: monospace;'>single <\/span><span>in the second case (and hence using 20 bytes) which gives us the 20 byte difference between the two.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Both are significantly better than the <\/span><span style=' font-family: monospace;'>50 x 100 x 8 = 40,000<\/span><span> bytes for the dense <\/span><span style=' font-family: monospace;'>double<\/span><span> matrix or <\/span><span style=' font-family: monospace;'>50 x 100 x 4 = 20,000 <\/span><span>bytes for the dense <\/span><span style=' font-family: monospace;'>single<\/span><span> matrix. For dense matrices, a zero takes up just as much memory space as any other number. Sparse matrices can save a lot of memory and <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrices can save even more, particularly when dealing with very large matrices with a large number of non-zero elements. For example, consider this sparse double matrix<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >largeDoubleSparse = sprand(10000,10000,0.1,<\/span><span style=\"color: rgb(167, 9, 245);\">\"double\"<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fprintf(<\/span><span style=\"color: rgb(167, 9, 245);\">\"This double matrix has %d non-zeros\\n\"<\/span><span >,nnz(largeDoubleSparse))<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"347340DC\" prevent-scroll=\"true\" data-testid=\"output_6\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"17\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">This double matrix has 9515142 non-zeros<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's see how much memory this matrix is using<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >whos <\/span><span style=\"color: rgb(167, 9, 245);\">largeDoubleSparse<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"5683B711\" prevent-scroll=\"true\" data-testid=\"output_7\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"46\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  Name                       Size                   Bytes  Class     Attributes\r\n\r\n  largeDoubleSparse      10000x10000            152322280  double    sparse    <\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>A single precision version of the same matrix is about 25% smaller in memory, saving about 36 Megabytes in this instance. <\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >largeSingleSparse = single(largeDoubleSparse);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >whos <\/span><span style=\"color: rgb(167, 9, 245);\">largeSingleSparse<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"CA706F3A\" prevent-scroll=\"true\" data-testid=\"output_8\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"46\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  Name                       Size                   Bytes  Class     Attributes\r\n\r\n  largeSingleSparse      10000x10000            114261712  single    sparse    <\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span><\/span><\/div><h2  style = 'margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Operations with single sparse matrices can be faster<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Roughly speaking, since we have fewer bytes to compute when operating on <\/span><span style=' font-family: monospace;'>single<\/span><span> precision numbers, we can expect to compute things more quickly compared to <\/span><span style=' font-family: monospace;'>double<\/span><span> precision. Iterative computations are often faster too since we have fewer decimal places of precision to worry about.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As an example, let's create a large <\/span><span style=' font-family: monospace;'>double sparse <\/span><span>random matrix and time how long it takes to find the largest 6 singular values using <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/svds.html\"><span style=' font-family: monospace;'>svds<\/span><\/a><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >rng(5); <\/span><span style=\"color: rgb(0, 128, 19);\">% Seed the random number generator for <\/span><span style=\"color: rgb(0, 128, 19);\">reproducibility<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randDoubleSparse =  sprand(40000,10000,0.0005,<\/span><span style=\"color: rgb(167, 9, 245);\">\"double\"<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >tic<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >svds(randDoubleSparse,6,<\/span><span style=\"color: rgb(167, 9, 245);\">\"largest\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableMatrixElement\" uid=\"9E655043\" prevent-scroll=\"true\" data-testid=\"output_9\" data-width=\"1115\" tabindex=\"-1\" style=\"width: 1145px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"outputLayer selectedOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer activeOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer scrollableOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer navigationFocusLayer doNotExport\" aria-hidden=\"false\" role=\"application\" tabindex=\"-1\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"matrixElement veSpecifier saveLoad eoOutputContent\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"veVariableName variableNameElement double\" style=\"width: 1115px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"headerElementClickToInteract\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">ans = <\/span><span class=\"veVariableValueSummary veMetaSummary\" style=\"white-space: normal; font-style: italic; color: rgb(97, 97, 97); font-size: 12px;\">6\u00d71<\/span><\/div><\/div><div class=\"valueContainer\" data-layout=\"{&quot;columnWidth&quot;:73,&quot;totalColumns&quot;:1,&quot;totalRows&quot;:6,&quot;charsPerColumn&quot;:10}\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"variableValue\" style=\"width: 75px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">    5.9095\r\n    4.2673\r\n    4.2507\r\n    4.2486\r\n    4.2456\r\n    4.2381\r\n<\/div><div class=\"horizontalEllipsis hide\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><mw-icon icon-id=\"meatballMenuUI\" icon-width=\"16\" icon-height=\"16\" icon-config=\"{}\" svg-path=\"\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/mw-icon><\/div><div class=\"verticalEllipsis hide\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><mw-icon icon-id=\"kebabMenuUI\" icon-width=\"16\" icon-height=\"16\" icon-config=\"{}\" svg-path=\"\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/mw-icon><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >doubleSvdsTime = toc<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"6A543744\" prevent-scroll=\"true\" data-testid=\"output_10\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"20\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">doubleSvdsTime = <\/span>1.7272<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Now I'll cast the large random matrix to <\/span><span style=' font-family: monospace;'>single<\/span><span> precision so that the only difference between these two matrices is the precision. <\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randSingleSparse = single(randDoubleSparse);<\/span><\/span><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I perform the <\/span><span style=' font-family: monospace;'>svds<\/span><span> calculation on the result<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >tic<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >svds(randSingleSparse,6,<\/span><span style=\"color: rgb(167, 9, 245);\">\"largest\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableMatrixElement\" uid=\"F0BC27EE\" prevent-scroll=\"true\" data-testid=\"output_11\" data-width=\"1115\" tabindex=\"-1\" style=\"width: 1145px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"outputLayer selectedOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer activeOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer scrollableOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer navigationFocusLayer doNotExport\" aria-hidden=\"false\" role=\"application\" tabindex=\"-1\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"matrixElement veSpecifier saveLoad eoOutputContent\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"veVariableName variableNameElement\" style=\"width: 1115px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"headerElementClickToInteract\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">ans = <\/span><span class=\"veVariableValueSummary headerElement\" style=\"white-space: normal; font-style: italic; color: rgb(97, 97, 97); font-size: 12px;\">6\u00d71 single column vector<\/span><\/div><\/div><div class=\"valueContainer\" data-layout=\"{&quot;columnWidth&quot;:73,&quot;totalColumns&quot;:1,&quot;totalRows&quot;:6,&quot;charsPerColumn&quot;:10}\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"variableValue\" style=\"width: 75px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">    5.9095\r\n    4.2673\r\n    4.2507\r\n    4.2486\r\n    4.2456\r\n    4.2381\r\n<\/div><div class=\"horizontalEllipsis hide\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><mw-icon icon-id=\"meatballMenuUI\" icon-width=\"16\" icon-height=\"16\" icon-config=\"{}\" svg-path=\"\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/mw-icon><\/div><div class=\"verticalEllipsis hide\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><mw-icon icon-id=\"kebabMenuUI\" icon-width=\"16\" icon-height=\"16\" icon-config=\"{}\" svg-path=\"\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/mw-icon><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >singleSvdsTime = toc<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"87A470E5\" prevent-scroll=\"true\" data-testid=\"output_12\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"20\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">singleSvdsTime = <\/span>1.2296<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Which is a very nice speed-up! <\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fprintf(<\/span><span style=\"color: rgb(167, 9, 245);\">\"The speed-up gained from using single precision was %f times\\n\"<\/span><span >,doubleSvdsTime\/singleSvdsTime)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"01ED8FD3\" prevent-scroll=\"true\" data-testid=\"output_13\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"17\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">The speed-up gained from using single precision was 1.404657 times<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The primary reason for this is that the tolerance is reduced for <\/span><span style=' font-family: monospace;'>single<\/span><span> inputs. <\/span><span style=' font-family: monospace;'>svds<\/span><span> sets the default tolerance to 1e-5 instead of 1e-10 because 1e-10 is not reachable in single-precision. T<\/span><span style=' font-weight: bold;'>his is something you should always bear in mind when using <\/span><span style=' font-weight: bold; font-family: monospace;'>single<\/span><span style=' font-weight: bold;'> precision for anything; yes, it can be faster but you always pay the cost of reduced precision.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The reduction in precision isn't the only reason why this operation is faster though.  Let's request the exact same tolerance in both <\/span><span style=' font-family: monospace;'>double<\/span><span> and <\/span><span style=' font-family: monospace;'>single<\/span><span> cases<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >tic; svds(randDoubleSparse,6,<\/span><span style=\"color: rgb(167, 9, 245);\">\"largest\"<\/span><span >,Tolerance=1e-4); toc<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"13EFCC04\" prevent-scroll=\"true\" data-testid=\"output_14\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"17\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">Elapsed time is 1.215458 seconds.<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span style=' font-family: monospace;'>single<\/span><span> is still faster.<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >tic; svds(randSingleSparse,6,<\/span><span style=\"color: rgb(167, 9, 245);\">\"largest\"<\/span><span >,Tolerance=1e-4); toc<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"980341A5\" prevent-scroll=\"true\" data-testid=\"output_15\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"17\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">Elapsed time is 0.866802 seconds.<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Several other iterative solvers such as <\/span><span style=' font-family: monospace;'>eigs<\/span><span>, <\/span><span style=' font-family: monospace;'>pcg<\/span><span>, <\/span><span style=' font-family: monospace;'>minres<\/span><span> and <\/span><span style=' font-family: monospace;'>gmres<\/span><span> might also be faster when using <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrices for similar reasons but I haven't investigated.<\/span><\/div><h2  style = 'margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Matrix-vector products are faster too<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>An example of a non-iterative algorithm where moving to <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse gives a performance boost  is multiplying a sparse matrix by a dense vector.  Even for large matrices, this is a fast operation so I'll do it 100 times and time that.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>First in double precision<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randDoubleSparse = sprand(80000,80000,0.0006,<\/span><span style=\"color: rgb(167, 9, 245);\">\"double\"<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randDoubleVector = rand(80000,1,<\/span><span style=\"color: rgb(167, 9, 245);\">\"double\"<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >tic<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">for <\/span><span >repeats = 1:100<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >   singleSquared = randDoubleSparse * randDoubleVector;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">end<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >toc<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"B0E3DCCE\" prevent-scroll=\"true\" data-testid=\"output_16\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"17\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">Elapsed time is 1.995894 seconds.<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>and now in single precision<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randSingleSparse = sprand(80000,80000,0.0006,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randSingleVector = rand(80000,1,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >tic<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">for <\/span><span >repeats = 1:100<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >   singleSquared = randSingleSparse * randSingleVector;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">end<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >toc<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"26D390A5\" prevent-scroll=\"true\" data-testid=\"output_17\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"17\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">Elapsed time is 0.703923 seconds.<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Again, this is another nice speed-up.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Speaking of speed....<\/span><\/div><h2  style = 'margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Single Sparse works on GPUs and distributed arrays as well<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As part of a cross-team collaboration, the Parallel Computing Toolbox team ensured that you can use single precision sparse matrices on GPUs too. You can transfer <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrices created earlier from main memory to the GPU using <\/span><span style=' font-family: monospace;'>gpuArray<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >gpuSparse = gpuArray(mySparseSingleMat)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"41C5867F\" prevent-scroll=\"true\" data-testid=\"output_18\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"135\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">gpuSparse =\r\n\r\n  50\u00d7100 sparse gpuArray single matrix (5 nonzeros)\r\n\r\n  (20,6)       0.2901\r\n  (44,19)      0.7310\r\n  (19,76)      0.2183\r\n  (34,85)      0.7405\r\n  (22,92)      0.9392<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>or you can create them directly in GPU memory<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >R = gpuArray.sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"1C4612EB\" prevent-scroll=\"true\" data-testid=\"output_19\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"135\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">R =\r\n\r\n  50\u00d7100 sparse gpuArray single matrix (5 nonzeros)\r\n\r\n  (49,12)      0.2728\r\n  (32,49)      0.8346\r\n  (28,72)      0.3244\r\n  (27,74)      0.8721\r\n   (7,85)      0.8113<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>All GPU functions that can compute with <\/span><span style=' font-family: monospace;'>double<\/span><span> sparse have also had <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse enabled.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's transfer those 80,000 x 80,000 sparse matrices I created earlier onto the GPU<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randDoubleSparseGpu = gpuArray(randDoubleSparse);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >randSingleSparseGpu = gpuArray(randSingleSparse);<\/span><\/span><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span> and time how long it takes to multiply them together using <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/parallel-computing\/gputimeit.html\"><span style=' font-family: monospace;'>gputimeit<\/span><\/a><span>. I'll also time how long it takes to do this on the CPU for comparison<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >singleCPUTime = timeit(@() randSingleSparse * randSingleSparse);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >doubleCPUTime = timeit(@() randDoubleSparse * randDoubleSparse);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '>&nbsp;<\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >singleGpuTime = gputimeit(@() randSingleSparseGpu * randSingleSparseGpu);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >doubleGpuTime = gputimeit(@() randDoubleSparseGpu * randDoubleSparseGpu);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fprintf(<\/span><span style=\"color: rgb(167, 9, 245);\">\"The CPU did the sparse double matrix multiplication in %.3fs\\n\" <\/span><span >+ <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >        <\/span><span style=\"color: rgb(167, 9, 245);\">\"The CPU did the sparse single matrix multiplication in %.3fs\\n\\n\" <\/span><span >+ <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >        <\/span><span style=\"color: rgb(167, 9, 245);\">\"The GPU did the sparse double matrix multiplication in %.3fs\\n\" <\/span><span >+ <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >        <\/span><span style=\"color: rgb(167, 9, 245);\">\"The GPU did the sparse single matrix multiplication in %.3fs\\n\" <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    ,doubleCPUTime, singleCPUTime ,doubleGpuTime,singleGpuTime);<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"700D9971\" prevent-scroll=\"true\" data-testid=\"output_20\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\" textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"76\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">The CPU did the sparse double matrix multiplication in 4.733s\r\nThe CPU did the sparse single matrix multiplication in 2.888s\r\n\r\nThe GPU did the sparse double matrix multiplication in 0.674s\r\nThe GPU did the sparse single matrix multiplication in 0.391s<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Not only is the GPU version of this computation much faster than the CPU version on my machine but you also see a speed-up when moving from <\/span><span style=' font-family: monospace;'>double<\/span><span> to <\/span><span style=' font-family: monospace;'>single<\/span><span> as you'd expect.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Similarly, the team has added supported for <\/span><a href = \"https:\/\/www.mathworks.com\/help\/parallel-computing\/distributed-arrays.html\"><span>Distributed Arrays<\/span><\/a><span> so now you can create and use single precision sparse matrices that are so big you need to distribute them over multiple nodes of a High Performance Computing (HPC) cluster.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Is single sparse one new feature or many new features?<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>While putting together this blog post, I found 4 entries in the Release Notes related to <\/span><span style=' font-family: monospace;'>single<\/span><span> sparse matrices in R2025a.  <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/release-notes.html#mw_add92a60-05d0-46be-b388-44510096b9ee\"><span>The first entry was in MATLAB itself <\/span><\/a><span>and referred to the fact that we now have them. Two entries <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/parallel-computing\/release-notes.html?s_tid=CRUX_lftnav#mw_22a06eb3-d848-46b8-b997-58b39e961b63\"><span>were for the GPU<\/span><\/a><span> and <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/parallel-computing\/release-notes.html?s_tid=CRUX_lftnav#mw_5ad2272a-de5e-490f-9a60-0c300ceb2621\"><span>Distributed Array support<\/span><\/a><span> discussed above from Parallel Computing Toolbox and one entry referred to calling <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/release-notes.html?s_tid=CRUX_lftnav#mw_d932c4ce-72f6-4237-a2df-bb1af176b23f\"><span>MATLAB from C++<\/span><\/a><span> since single-precision sparse matrices work there too now! <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>That one entry in the MATLAB release notes mentioned the 6 creation functions that have been updated: <\/span><span style=' font-family: monospace;'>sparse<\/span><span>, <\/span><span style=' font-family: monospace;'>speye<\/span><span>, <\/span><span style=' font-family: monospace;'>spalloc<\/span><span>, <\/span><span style=' font-family: monospace;'>sprand<\/span><span>, <\/span><span style=' font-family: monospace;'>sprandn<\/span><span> and <\/span><span style=' font-family: monospace;'>sprandsym<\/span><span>. If I were the lead developer of this tranche of work I'd be arguing that I had at least 6 new features and not one.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Actually, If I were the lead developer of this, I'd be arguing that this is dozens of new features because <\/span><span style=' font-weight: bold;'>all functions in MATLAB that support double-precision sparse matrices including elementary math, linear algebra, and sparse matrix functions<\/span><span> now also support <\/span><span style=' font-family: monospace;'>single<\/span><span> precision sparse matrices. All of those functions had to be modified, tested and get updated documentation.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>It's an astonishing amount of work. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I think that this is also an illustration of why different people in MathWorks can give different feature counts when talking about new releases. Like all the truths we cling to, it depends on your point of view.<\/span><\/div><h2  style = 'margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>More informative display for sparse matrices<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Another feature that hasn't even been mentioned in the release notes is the improved display of sparse matrices. In R2024a and earlier, it looked like this<\/span><\/div><div class = 'preformatted-plain' style = 'margin: 10px 3px 10px 55px; padding: 10px 10px 10px 5px; '><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px; line-height: 15.6px; min-height: 16px; white-space: pre; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 12px; '><span style=\"white-space: pre\"><span >sparse([0 0;0 0.2])<\/span><\/span><\/div><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px; line-height: 15.6px; min-height: 16px; white-space: pre; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 12px; '><span style=\"white-space: pre\"><span >ans =<\/span><\/span><\/div><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px; line-height: 15.6px; min-height: 16px; white-space: pre; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 12px; '><span style=\"white-space: pre\"><span >   (2,2)       0.2000<\/span><\/span><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>compared to the more informative<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >sparse([0 0;0 0.2])<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"E38F02EE\" prevent-scroll=\"true\" data-testid=\"output_21\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"35\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">ans = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">2\u00d72 sparse double matrix (1 nonzero)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">   (2,2)       0.2000\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This was actually done in R2024b but it's even more meaningful now that single precision sparse matrices are possible.<\/span><\/div><h2  style = 'margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>What happens when we open MAT files containing single sparse matrices in old versions of MATLAB<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>If you save a single-precision sparse matrix to a MAT file, you can load it into an earlier release of MATLAB. However, how the data is loaded depends on the release of MATLAB:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>MATLAB R2021b through R2024b \u2014 MATLAB warns that the data has an unsupported data type and loads it as a double-precision sparse matrix.<\/span><\/li><\/ul><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(0, 128, 19);\">% This line was run in <\/span><span style=\"color: rgb(0, 128, 19);\">R2024b<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >load(<\/span><span style=\"color: rgb(167, 9, 245);\">\"from25a.mat\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsWarningElement\" uid=\"A4A721AF\" prevent-scroll=\"true\" data-testid=\"output_22\" tabindex=\"-1\" style=\"width: 1145px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"diagnosticMessage-wrapper diagnosticMessage-warningType eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"19\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"warning output \" style=\"max-height: 261px; white-space: normal; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><div class=\"diagnosticMessage-messagePart\" style=\"white-space: pre-wrap; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\">Warning: Sparse matrix of unsupported datatype. Matrix has been converted to double.<\/div><div class=\"diagnosticMessage-stackPart\" style=\"white-space: pre; font-style: normal; color: rgb(179, 98, 5); font-size: 12px;\"><\/div><\/div><\/div><\/div><\/div><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>MATLAB R2021a and earlier \u2014 MATLAB loads the data as a single-precision sparse matrix, but you cannot use the matrix because its data type is unsupported. Attempting to use the matrix can result in undefined behavior.<\/span><\/li><\/ul><h2  style = 'margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Style tip: Use \"single\" and not 'single' when creating single sparse matrices<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>MATLAB old-timers like me are often guilty of using character arrays such as <\/span><span style=' font-family: monospace;'>'single'<\/span><span> when we really should get with the times and use strings, i.e. \"<\/span><span style=' font-family: monospace;'>single\"<\/span><span>. We seem to get away with it too<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >smallSparse = sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">'single'<\/span><span >)  <\/span><span style=\"color: rgb(0, 128, 19);\">% Don't use 'single' like this<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"650286F6\" prevent-scroll=\"true\" data-testid=\"output_23\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"94\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">smallSparse = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">50\u00d7100 sparse single matrix (5 nonzeros)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  (22,28)      0.8777\r\n  (42,71)      0.0741\r\n  (24,80)      0.9256\r\n  (37,82)      0.1663\r\n  (18,89)      0.7241\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>We really should be using strings though!<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >smallSparse =  sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >)  <\/span><span style=\"color: rgb(0, 128, 19);\">% Using \"single\" is much better<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"7D8C57A7\" prevent-scroll=\"true\" data-testid=\"output_24\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"94\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">smallSparse = <span class=\"headerElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">50\u00d7100 sparse single matrix (5 nonzeros)<\/span><\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  (14,33)      0.8020\r\n  (44,43)      0.8440\r\n  (46,63)      0.3696\r\n   (4,81)      0.9557\r\n  (16,98)      0.7799\r\n<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>One good reason for this is so that the operation will fail more gracefully in older versions of MATLAB. Obviously, specifying the type of a <\/span><span style=' font-family: monospace;'>sparse<\/span><span> will fail in older versions of MATLAB since it wasn't supported but which type of failure would you prefer here?<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(0, 128, 19);\">% Run this line in <\/span><span style=\"color: rgb(0, 128, 19);\">R2024b<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >smallSparse =  sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">\"single\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsErrorElement\" uid=\"3411E547\" prevent-scroll=\"true\" data-testid=\"output_25\" tabindex=\"-1\" style=\"width: 1145px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"diagnosticMessage-wrapper diagnosticMessage-errorType eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"63\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"error output \" style=\"max-height: 261px; white-space: normal; font-style: normal; color: rgb(225, 27, 20); font-size: 12px;\"><div class=\"diagnosticMessage-messagePart\" style=\"white-space: pre-wrap; font-style: normal; color: rgb(225, 27, 20); font-size: 12px;\">Error using  &lt;= <br style=\"white-space: pre-wrap; font-style: normal; color: rgb(225, 27, 20); font-size: 12px;\">Comparison between string and double is not supported.<br style=\"white-space: pre-wrap; font-style: normal; color: rgb(225, 27, 20); font-size: 12px;\">Error in sprand (line 61)<br style=\"white-space: pre-wrap; font-style: normal; color: rgb(225, 27, 20); font-size: 12px;\">     if ~(rc &lt;= 1 &amp;&amp; rc &gt;= 0 &amp;&amp; imag(rc) == 0)<\/div><div class=\"diagnosticMessage-stackPart\" style=\"white-space: pre; font-style: normal; color: rgb(225, 27, 20); font-size: 12px;\"><\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>We get an error message. Admittedly its a little confusing but since we couldn't go back in time and change this to something like <\/span><span style=' font-family: monospace;'>\"Choosing the data type for sparse is not supported\"<\/span><span> its a lot better than the alternative:<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(0, 128, 19);\">%Run this line in <\/span><span style=\"color: rgb(0, 128, 19);\">R2024b<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >smallSparse =  sprand(50,100,0.001,<\/span><span style=\"color: rgb(167, 9, 245);\">'single'<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableStringElement\" uid=\"BD061FFD\" prevent-scroll=\"true\" data-testid=\"output_26\" tabindex=\"-1\" style=\"width: 1145px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1108\" data-previous-scroll-height=\"108\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">smallSparse = <\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">  (34,41)     103\r\n  (22,42)     110\r\n  (40,49)     105\r\n   (6,69)     101\r\n  (32,73)     115\r\n  (35,96)     108<\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>When this first happened to me, it took a little bit of thought to figure out what was going on. When I say 'thought' I mean 'looking at the documentation' which explains the situation. There's a version of <\/span><span style=' font-family: monospace;'>sprand<\/span><span> that accepts 4 input arguments:<\/span><\/div><div class = 'preformatted-matlab' style = 'margin: 10px 3px 10px 55px; padding: 10px 10px 10px 5px; '><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px; line-height: 15.6px; min-height: 16px; white-space: pre; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 12px; '><span style=\"white-space: pre\"><span >R = sprand(m,n,density,rc) creates <\/span><span style=\"color: rgb(167, 9, 245);\">a matrix that also has reciprocal condition number approximately equal to rc. <\/span><\/span><\/div><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px; line-height: 15.6px; min-height: 16px; white-space: pre; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 12px; '><span style=\"white-space: pre\"><span >The <\/span><span style=\"color: rgb(167, 9, 245);\">matrix R is constructed from a sum of matrices of rank one.<\/span><\/span><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>If you give MATLAB a character array where it is expecting a numerical array, it converts it to its ASCII numerical equivalent:<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >double(<\/span><span style=\"color: rgb(167, 9, 245);\">'single'<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsVariableMatrixElement\" uid=\"1A741676\" prevent-scroll=\"true\" data-testid=\"output_27\" data-width=\"1115\" tabindex=\"-1\" style=\"width: 1145px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"outputLayer selectedOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer activeOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer scrollableOutputDecorationLayer doNotExport\" aria-hidden=\"true\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"outputLayer navigationFocusLayer doNotExport\" aria-hidden=\"false\" role=\"application\" tabindex=\"-1\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/div><div class=\"matrixElement veSpecifier saveLoad eoOutputContent\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"variable output \" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"veVariableName variableNameElement double\" style=\"width: 1115px; white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"headerElementClickToInteract\" style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><span style=\"white-space: normal; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">ans = <\/span><span class=\"veVariableValueSummary veMetaSummary\" style=\"white-space: normal; font-style: italic; color: rgb(97, 97, 97); font-size: 12px;\">1\u00d76<\/span><\/div><\/div><div class=\"valueContainer\" data-layout=\"{&quot;columnWidth&quot;:44,&quot;totalColumns&quot;:6,&quot;totalRows&quot;:1,&quot;charsPerColumn&quot;:6}\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><div class=\"variableValue\" style=\"width: 266px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">   115   105   110   103   108   101\r\n<\/div><div class=\"horizontalEllipsis hide\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><mw-icon icon-id=\"meatballMenuUI\" icon-width=\"16\" icon-height=\"16\" icon-config=\"{}\" svg-path=\"\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/mw-icon><\/div><div class=\"verticalEllipsis hide\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><mw-icon icon-id=\"kebabMenuUI\" icon-width=\"16\" icon-height=\"16\" icon-config=\"{}\" svg-path=\"\" style=\"white-space: nowrap; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\"><\/mw-icon><\/div><\/div><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This then gets used as the 4th input argument to <\/span><span style=' font-family: monospace;'>sprand<\/span><span> and weirdness ensues. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The fact that using <\/span><span style=' font-family: monospace;'>\"single\"<\/span><span> instead of <\/span><span style=' font-family: monospace;'>'single'<\/span><span> is useful here was not a design decision. It's just a concrete reason I discovered while writing this post to prefer the newer syntax. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>My advice is always to use strings instead of character arrays whenever you can. It's newer and tends to be where development focuses its attention on these days.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Will you be using single precision sparse matrices?<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Many users have been asking for this functionality for a long time. Are you one of them? Will you be using these features? What is your application? Tell us all about it in the comments section.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = '.eoOutputWrapper { width: calc(90vw - 10px) !important; } \/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsErrorElement {    min-height: 18px;    max-height: 550px;} .embeddedOutputsErrorElement .diagnosticMessage-errorType {    overflow: auto;} .embeddedOutputsErrorElement.activeOutput .eoOutputContent {    user-select: text;    -webkit-user-select: text;} .embeddedOutputsErrorElement.activeOutput .eoOutputContent button {    user-select: none;    -webkit-user-select: none;} .embeddedOutputsErrorElement .eoOutputContent ::selection {} .embeddedOutputsErrorElement.inlineElement {} .embeddedOutputsErrorElement.rightPaneElement {} \/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsWarningElement {    min-height: 18px;    max-height: 550px;} .embeddedOutputsWarningElement .diagnosticMessage-warningType {    overflow: auto;} .embeddedOutputsWarningElement.activeOutput .eoOutputContent {    user-select: text;    -webkit-user-select: text;} .embeddedOutputsWarningElement .eoOutputContent ::selection {} .embeddedOutputsWarningElement.inlineElement {} .embeddedOutputsWarningElement.rightPaneElement {} \/* Copyright 2015-2023 The MathWorks, Inc. *\/\/* In this file, styles are not scoped to rtcContainer since they could be in the Dojo Tooltip *\/.diagnosticMessage-wrapper {    font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace;    font-size: 12px;} .diagnosticMessage-wrapper.diagnosticMessage-warningType {    \/*This fallback value will be used for appdesigner warnings*\/    color: var(--rtc-warning-output-color, var(--mw-color-matlabWarning));} .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    \/*This fallback value will be used for appdesigner warnings*\/    color: var(--rtc-warning-output-color, var(--mw-color-matlabWarning));    text-decoration: underline;} .rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: var(--mw-color-matlabWarning) !important;} .diagnosticMessage-wrapper.diagnosticMessage-errorType {    \/*This fallback value will be used in appdesigner error tooltip text*\/    color: var(--rtc-error-output-color, var(--mw-color-matlabErrors));} .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    \/*This fallback value will be used in appdesigner error tooltip text*\/    color: var(--rtc-error-output-color, var(--mw-color-matlabErrors));    text-decoration: underline;} .rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: var(--mw-color-matlabErrors) !important;} .diagnosticMessage-wrapper .diagnosticMessage-messagePart,.diagnosticMessage-wrapper .diagnosticMessage-causePart {    white-space: pre-wrap;} .diagnosticMessage-wrapper .diagnosticMessage-stackPart {    white-space: pre;} .embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {    white-space: pre;    word-wrap:  initial;    min-height: 18px;    max-height: 550px;} .embeddedOutputsTextElement .textElement,.embeddedOutputsVariableStringElement .textElement {    overflow: auto;} .embeddedOutputsTextElement.activeOutput .eoOutputContent,.embeddedOutputsVariableStringElement.activeOutput .eoOutputContent {    user-select: text;    -webkit-user-select: text;} \/*embeddedOutputsTextElement has a different dom structure than embeddedOutputsVariableStringElement.Unlike variableString, the text output has both TEXT nodes and elements as children. Hence we needa selector for each.*\/.embeddedOutputsTextElement .eoOutputContent::selection,.embeddedOutputsTextElement .eoOutputContent ::selection,.embeddedOutputsVariableStringElement .eoOutputContent ::selection {} .textElement,.rtcDataTipElement .textElement {    padding-top: 2px;} .embeddedOutputsTextElement.inlineElement,.embeddedOutputsVariableStringElement.inlineElement {} .inlineElement .textElement {} .embeddedOutputsTextElement.rightPaneElement,.embeddedOutputsVariableStringElement.rightPaneElement {    min-height: 16px;} .rightPaneElement .textElement {    padding-top: 2px;    padding-left: 9px;} .variableValue { width: 100% !important; } .embeddedOutputsMatrixElement,.eoOutputWrapper .matrixElement {    min-height: 18px;    box-sizing: border-box;} .embeddedOutputsMatrixElement .matrixElement,.eoOutputWrapper  .matrixElement,.rtcDataTipElement .matrixElement {    position: relative;} .matrixElement .variableValue,.rtcDataTipElement .matrixElement .variableValue {    white-space: pre;    display: inline-block;    vertical-align: top;    overflow: hidden;} .embeddedOutputsMatrixElement.inlineElement {} .embeddedOutputsMatrixElement.inlineElement .topHeaderWrapper {    display: none;} .embeddedOutputsMatrixElement.inlineElement .veTable .body {    padding-top: 0 !important;    max-height: 100px;} .inlineElement .matrixElement {    max-height: 300px;} .embeddedOutputsMatrixElement.rightPaneElement {} .rightPaneElement .matrixElement,.rtcDataTipElement .matrixElement {    overflow: hidden;    padding-left: 9px;} .rightPaneElement .matrixElement {    margin-bottom: -1px;} .embeddedOutputsMatrixElement .matrixElement .valueContainer,.eoOutputWrapper .matrixElement .valueContainer,.rtcDataTipElement .matrixElement .valueContainer {    white-space: nowrap;    margin-bottom: 3px;} .embeddedOutputsMatrixElement .matrixElement .valueContainer .horizontalEllipsis.hide,.embeddedOutputsMatrixElement .matrixElement .verticalEllipsis.hide,.eoOutputWrapper .matrixElement .valueContainer .horizontalEllipsis.hide,.eoOutputWrapper .matrixElement .verticalEllipsis.hide,.rtcDataTipElement .matrixElement .valueContainer .horizontalEllipsis.hide,.rtcDataTipElement .matrixElement .verticalEllipsis.hide {    display: none;} .embeddedOutputsVariableMatrixElement .matrixElement .valueContainer.hideEllipses .verticalEllipsis, .embeddedOutputsVariableMatrixElement .matrixElement .valueContainer.hideEllipses .horizontalEllipsis {    display:none;} .eoOutputWrapper .embeddedOutputsVariableMatrixElement .matrixElement .valueContainer {    cursor: default !important;} .embeddedOutputsVariableElement {    white-space: pre-wrap;    word-wrap: break-word;    min-height: 18px;    max-height: 250px;    overflow: auto;} .eoOutputWrapper .variableElement {    padding-top: 2px;} .embeddedOutputsVariableElement.inlineElement {} .inlineElement .variableElement {} .embeddedOutputsVariableElement.rightPaneElement {    min-height: 16px;} .rightPaneElement .variableElement {    padding-left: 9px;} .outputsOnRight .embeddedOutputsVariableElement.rightPaneElement .eoOutputContent {    \/* Remove extra space allocated for navigation border *\/    margin-top: 0;    margin-bottom: 0;} .variableNameElement {    margin-bottom: 3px;    display: inline-block;} \/* * Ellipses as base64 for HTML export. *\/.matrixElement .horizontalEllipsis,.rtcDataTipElement .matrixElement .horizontalEllipsis {    display: inline-block;    margin-top: 3px;    \/* base64 encoded version of images-liveeditor\/HEllipsis.png *\/    width: 30px;    height: 12px;    background-repeat: no-repeat;    background-image: url(\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAJCAYAAADO1CeCAAAAJUlEQVR42mP4\/\/8\/A70xw0i29BUDFPxnAEtTW37wWDqakIa4pQDvOOG89lHX2gAAAABJRU5ErkJggg==\");} .matrixElement .verticalEllipsis,.textElement .verticalEllipsis,.rtcDataTipElement .matrixElement .verticalEllipsis,.rtcDataTipElement .textElement .verticalEllipsis {    margin-left: 35px;    \/* base64 encoded version of images-liveeditor\/VEllipsis.png *\/    width: 12px;    height: 30px;    background-repeat: no-repeat;    background-image: url(\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAZCAYAAAAIcL+IAAAALklEQVR42mP4\/\/8\/AzGYgWyFMECMwv8QddRS+P\/\/KyimlmcGUOFoOI6GI\/UVAgDnd8Dd4+NCwgAAAABJRU5ErkJggg==\");}'; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/matlab\/files\/2025\/08\/airfoil_04.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Sparse matrices have been in MATLAB for a long time but, up until now, the only types of sparse matrices you could create were  double or logical sparse matrices.This is no longer the case and one of... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/matlab\/2025\/08\/12\/new-in-matlab-single-precision-sparse-matrices\/\">read more >><\/a><\/p>","protected":false},"author":176,"featured_media":3857,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[68,23,29,20,14,134],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/3851"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/users\/176"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/comments?post=3851"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/3851\/revisions"}],"predecessor-version":[{"id":3863,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/posts\/3851\/revisions\/3863"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media\/3857"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/media?parent=3851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/categories?post=3851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/matlab\/wp-json\/wp\/v2\/tags?post=3851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}