Skip to content

Linear Algebra operations: Jiang et al - #119

Draft
Tom-Finke wants to merge 20 commits into
resize-vectorsfrom
linalg_jiang-et-al
Draft

Tom-Finke wants to merge 20 commits into
resize-vectorsfrom
linalg_jiang-et-al

Conversation

@Tom-Finke

@Tom-Finke Tom-Finke commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.75630% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/linear_algebra.jl 93.54% 6 Missing ⚠️
src/types.jl 60.00% 4 Missing ⚠️
src/openfhe.jl 87.50% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/SecureArithmetic.jl 100.00% <ø> (ø)
src/arithmetic.jl 100.00% <100.00%> (ø)
src/openfhe.jl 96.06% <87.50%> (+0.01%) ⬆️
src/types.jl 87.50% <60.00%> (-12.50%) ⬇️
src/linear_algebra.jl 93.54% <93.54%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tom-Finke Tom-Finke changed the title Linear Algebra operations derived from work by Jiang et al Linear Algebra operations: Jiang et al Sep 21, 2026
Comment thread src/linear_algebra.jl Resolved
@Tom-Finke

Tom-Finke commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Mat Mul unit test failing with InexactError: Int64(2.321928094887362), originating in

for k in 0:Int(log2(d÷l))-1

The algorithm assumes that d/l is a power of 2, i.e. that the smaller dimension fits a power of 2 times into the bigger dimension. They mention this only in Section 5 Implementation of Homomorphic Matrix Operations:

For simplicity, we assume that d is a power-of-two integer. In general, we can pad zeros at the end of each row to set d as a power of two

Options:

Since we only have to pad the smaller dimension $l$, which is the number of columns, this padding is cheap even for for encrypted matrices in column order. We simply add additional columns by resizing the 1D array representing the matrix.
In the worst case, the the only power of two that divides $d$ is 1 and we would end up calculating a $d \times d * d \times d$ matrix product.
A way around this would be to also pad the left matrix such that $d$ is a power of two, but this is expensive on an encrypted matrix, since we would have to pad both rows and columns, which entails expensive masking and rotations.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results: SecureArithmetic Matrix Multiplication

Warning: Benchmark run exited with status 1.

Summary

FHE Params Matrix Size Mode Wall Time (ms) Alloc #Mult #Rotate Result Level
d15_n2048 4×4 secure_secure 180.7 623.6 KiB 57 36 4
d15_n2048 4×4 secure_plain 71.4 282.7 KiB 20 12 3
d15_n2048 4×4 plain_secure 121.2 446.4 KiB 41 24 4
d15_n2048 4×4 * 4×1 secure_secure 120.5 450.9 KiB 39 26 7
d15_n2048 4×4 * 4×1 secure_plain 55.7 227.4 KiB 15 10 4
d15_n2048 4×4 * 4×1 plain_secure 93.7 370.2 KiB 29 20 7
d15_n2048 8×8 secure_secure 415.0 1.5 MiB 129 84 4
d15_n2048 8×8 secure_plain 158.5 928.3 KiB 44 28 3
d15_n2048 8×8 plain_secure 277.4 1.1 MiB 93 56 4
d15_n2048 8×8 * 8×1 secure_secure 237.8 962.1 KiB 79 54 9
d15_n2048 8×8 * 8×1 secure_plain 105.5 635.8 KiB 29 20 5
d15_n2048 8×8 * 8×1 plain_secure 176.8 838.3 KiB 57 40 9
d15_n2048 16×16 secure_secure 857.1 3.5 MiB 273 180 4
d15_n2048 16×16 secure_plain 330.1 4.2 MiB 92 60 3
d15_n2048 16×16 plain_secure 575.5 3.4 MiB 197 120 4
d15_n2048 16×16 * 16×1 secure_secure 405.5 2.1 MiB 155 106 11
d15_n2048 16×16 * 16×1 secure_plain 197.5 2.6 MiB 55 38 6
d15_n2048 16×16 * 16×1 plain_secure 289.9 2.3 MiB 109 76 11
d15_n2048 32×32 secure_secure 1021.1 9.9 MiB 189 186 2
d15_n2048 32×32 secure_plain 426.9 27.3 MiB 64 62 1
d15_n2048 32×32 plain_secure 684.2 15.4 MiB 157 124 2
d15_n2048 32×32 * 32×1 secure_secure 526.2 5.7 MiB 97 103 2
d15_n2048 32×32 * 32×1 secure_plain 232.3 16.1 MiB 33 36 1
d15_n2048 32×32 * 32×1 plain_secure 406.6 10.7 MiB 65 72 2
d10_128c 4×4 secure_secure 2164.2 9.0 MiB 57 36 4
d10_128c 4×4 secure_plain 859.3 3.1 MiB 20 12 3
d10_128c 4×4 plain_secure 1458.2 6.1 MiB 41 24 4
d10_128c 4×4 * 4×1 secure_secure 1398.1 6.5 MiB 39 26 7
d10_128c 4×4 * 4×1 secure_plain 660.9 2.6 MiB 15 10 4
d10_128c 4×4 * 4×1 plain_secure 1105.5 5.0 MiB 29 20 7
d10_128c 8×8 secure_secure 4935.2 21.1 MiB 129 84 4
d10_128c 8×8 secure_plain 1957.0 7.5 MiB 44 28 3
d10_128c 8×8 plain_secure 3331.9 14.3 MiB 93 56 4
d10_128c 8×8 * 8×1 secure_secure 2548.5 13.6 MiB 79 54 9
d10_128c 8×8 * 8×1 secure_plain 1264.0 5.3 MiB 29 20 5
d10_128c 8×8 * 8×1 plain_secure 1911.0 10.2 MiB 57 40 9
d10_128c 16×16 secure_secure 10556.1 45.7 MiB 273 180 4
d10_128c 16×16 secure_plain 4223.4 18.3 MiB 92 60 3
d10_128c 16×16 plain_secure 7150.4 31.6 MiB 197 120 4
d10_128c 16×16 * 16×1 secure_plain 2488.7 11.5 MiB 55 38 6
d10_128c 32×32 * 32×1 secure_plain 4775.4 33.0 MiB 105 72 7

Runs Without a Result

4 of 45 runs did not produce a result.

FHE Params Matrix Size Mode Error
d10_128c 16×16 * 16×1 secure_secure SetLevel(): The current multiplicative depth [10] is insufficient; increase it.
d10_128c 16×16 * 16×1 plain_secure SetLevel(): The current multiplicative depth [10] is insufficient; increase it.
d10_128c 32×32 * 32×1 secure_secure SetLevel(): The current multiplicative depth [10] is insufficient; increase it.
d10_128c 32×32 * 32×1 plain_secure SetLevel(): The current multiplicative depth [10] is insufficient; increase it.
Full results (all columns)
fhe_params,matrix_size,mode,status,error,wall_time_s,alloc_bytes,eval_add_count,eval_add_time_s,eval_sub_count,eval_sub_time_s,eval_mult_count,eval_mult_time_s,eval_rotate_count,eval_rotate_time_s,eval_negate_count,eval_negate_time_s,resize_count,resize_time_s,result_level
d15_n2048,4×4,secure_secure,ok,,0.180741597,638576,35,0.003480401,0,0.0,57,0.044468673,36,0.10870433,0,0.0,0,0.0,4
d15_n2048,4×4,secure_plain,ok,,0.071369414,289488,13,0.001840383,0,0.0,20,0.01201881,12,0.036764218,0,0.0,0,0.0,3
d15_n2048,4×4,plain_secure,ok,,0.121215752,457152,25,0.002329129,0,0.0,41,0.025064639,24,0.072361363,0,0.0,0,0.0,4
d15_n2048,4×4 * 4×1,secure_secure,ok,,0.120485046,461760,28,0.004230431,0,0.0,39,0.027586695,26,0.071043298,0,0.0,2,0.000103125,7
d15_n2048,4×4 * 4×1,secure_plain,ok,,0.055730187,232848,11,0.002187073,0,0.0,15,0.00749446,10,0.029910873,0,0.0,2,0.000414617,4
d15_n2048,4×4 * 4×1,plain_secure,ok,,0.093749079,379072,21,0.003220044,0,0.0,29,0.021406869,20,0.051725108,0,0.0,2,9.6877e-5,7
d15_n2048,8×8,secure_secure,ok,,0.415021956,1529648,79,0.005507443,0,0.0,129,0.099143287,84,0.253719082,0,0.0,0,0.0,4
d15_n2048,8×8,secure_plain,ok,,0.158529913,950608,29,0.002520587,0,0.0,44,0.026185425,28,0.083655119,0,0.0,0,0.0,3
d15_n2048,8×8,plain_secure,ok,,0.277373597,1188608,57,0.003711997,0,0.0,93,0.056755064,56,0.168521956,0,0.0,0,0.0,4
d15_n2048,8×8 * 8×1,secure_secure,ok,,0.237771523,985184,56,0.006245954,0,0.0,79,0.051749277,54,0.143453153,0,0.0,2,0.000125259,9
d15_n2048,8×8 * 8×1,secure_plain,ok,,0.105537904,651088,21,0.003069196,0,0.0,29,0.013312289,20,0.057770808,0,0.0,2,0.000387396,5
d15_n2048,8×8 * 8×1,plain_secure,ok,,0.176835784,858400,41,0.004483763,0,0.0,57,0.039859617,40,0.098281573,0,0.0,2,0.000104078,9
d15_n2048,16×16,secure_secure,ok,,0.857067291,3633944,167,0.008802296,0,0.0,273,0.2030537,180,0.527795893,0,0.0,0,0.0,4
d15_n2048,16×16,secure_plain,ok,,0.330119827,4423440,61,0.003550587,0,0.0,92,0.054334271,60,0.174854609,0,0.0,0,0.0,3
d15_n2048,16×16,plain_secure,ok,,0.575517871,3613320,121,0.006029529,0,0.0,197,0.118572789,120,0.349674372,0,0.0,0,0.0,4
d15_n2048,16×16 * 16×1,secure_secure,ok,,0.405514881,2162224,108,0.00788021,0,0.0,155,0.090155761,106,0.237506303,0,0.0,2,0.000170238,11
d15_n2048,16×16 * 16×1,secure_plain,ok,,0.197549804,2734488,39,0.004228329,0,0.0,55,0.02337621,38,0.108989141,0,0.0,2,0.000424953,6
d15_n2048,16×16 * 16×1,plain_secure,ok,,0.289943005,2461760,77,0.005802838,0,0.0,109,0.071071508,76,0.146963086,0,0.0,2,0.000153952,11
d15_n2048,32×32,secure_secure,ok,,1.021148639,10339000,157,0.007861391,0,0.0,189,0.207471223,186,0.568927325,0,0.0,0,0.0,2
d15_n2048,32×32,secure_plain,ok,,0.426857902,28658960,63,0.00287879,0,0.0,64,0.032568035,62,0.1901612,0,0.0,0,0.0,1
d15_n2048,32×32,plain_secure,ok,,0.684217428,16103976,125,0.00600447,0,0.0,157,0.092762325,124,0.378004954,0,0.0,0,0.0,2
d15_n2048,32×32 * 32×1,secure_secure,ok,,0.52615251,5972320,105,0.00498404,0,0.0,97,0.065097199,103,0.320474668,0,0.0,2,0.000156696,2
d15_n2048,32×32 * 32×1,secure_plain,ok,,0.232302645,16894528,37,0.001787262,0,0.0,33,0.004366755,36,0.108861112,0,0.0,2,0.000405223,1
d15_n2048,32×32 * 32×1,plain_secure,ok,,0.406610142,11244016,73,0.0031799,0,0.0,65,0.057389073,72,0.218591504,0,0.0,2,0.000161535,2
d10_128c,4×4,secure_secure,ok,,2.164211516,9485936,35,0.040131469,0,0.0,57,0.54283922,36,1.249257866,0,0.0,0,0.0,4
d10_128c,4×4,secure_plain,ok,,0.859261952,3238608,13,0.020617569,0,0.0,20,0.146636739,12,0.413570652,0,0.0,0,0.0,3
d10_128c,4×4,plain_secure,ok,,1.458176403,6355392,25,0.026419424,0,0.0,41,0.30819818,24,0.832061505,0,0.0,0,0.0,4
d10_128c,4×4 * 4×1,secure_secure,ok,,1.398132727,6851520,28,0.04810795,0,0.0,39,0.324841863,26,0.787540105,0,0.0,2,0.000392814,7
d10_128c,4×4 * 4×1,secure_plain,ok,,0.660857127,2690448,11,0.025722313,0,0.0,15,0.091594392,10,0.325795078,0,0.0,2,0.003896478,4
d10_128c,4×4 * 4×1,plain_secure,ok,,1.105549573,5294272,21,0.036355021,0,0.0,29,0.255985256,20,0.578892086,0,0.0,2,0.000396658,7
d10_128c,8×8,secure_secure,ok,,4.935176355,22173488,79,0.061906284,0,0.0,129,1.189385473,84,2.903323483,0,0.0,0,0.0,4
d10_128c,8×8,secure_plain,ok,,1.957000529,7831888,29,0.027760709,0,0.0,44,0.325688429,28,0.952685759,0,0.0,0,0.0,3
d10_128c,8×8,plain_secure,ok,,3.33186089,14951168,57,0.041496372,0,0.0,93,0.701078348,56,1.915700951,0,0.0,0,0.0,4
d10_128c,8×8 * 8×1,secure_secure,ok,,2.548519902,14256224,56,0.063689677,0,0.0,79,0.577314413,54,1.404289678,0,0.0,2,0.000354786,9
d10_128c,8×8 * 8×1,secure_plain,ok,,1.263985546,5566288,21,0.034161374,0,0.0,29,0.161842167,20,0.636961778,0,0.0,2,0.003809056,5
d10_128c,8×8 * 8×1,plain_secure,ok,,1.910990937,10688800,41,0.047471204,0,0.0,57,0.461214932,40,0.918620787,0,0.0,2,0.000341526,9
d10_128c,16×16,secure_secure,ok,,10.556072734,47918968,167,0.105315549,0,0.0,273,2.500224738,180,6.2264616,0,0.0,0,0.0,4
d10_128c,16×16,secure_plain,ok,,4.223417948,19169040,61,0.043932063,0,0.0,92,0.695028962,60,2.060820962,0,0.0,0,0.0,3
d10_128c,16×16,plain_secure,ok,,7.150380804,33104520,121,0.071180113,0,0.0,197,1.49732676,120,4.105489931,0,0.0,0,0.0,4
d10_128c,16×16 * 16×1,secure_secure,error,SetLevel(): The current multiplicative depth [10] is insufficient; increase it.,0.0,0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-1
d10_128c,16×16 * 16×1,secure_plain,ok,,2.488749176,12073368,39,0.049192957,0,0.0,55,0.301773462,38,1.261234313,0,0.0,2,0.003898589,6
d10_128c,16×16 * 16×1,plain_secure,error,SetLevel(): The current multiplicative depth [10] is insufficient; increase it.,0.0,0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-1
d10_128c,32×32 * 32×1,secure_secure,error,SetLevel(): The current multiplicative depth [10] is insufficient; increase it.,0.0,0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-1
d10_128c,32×32 * 32×1,secure_plain,ok,,4.775395483,34603920,73,0.071106272,0,0.0,105,0.529418345,72,2.441475233,0,0.0,2,0.004060455,7
d10_128c,32×32 * 32×1,plain_secure,error,SetLevel(): The current multiplicative depth [10] is insufficient; increase it.,0.0,0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,-1

Benchmarks run with OMP_NUM_THREADS=1 on ubuntu-latest.

@Tom-Finke Tom-Finke mentioned this pull request Oct 30, 2026
@Tom-Finke
Tom-Finke changed the base branch from main to resize-vectors November 11, 2026 17:24
@Tom-Finke
Tom-Finke added this pull request to stack #133 November 11, 2026 17:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants