mirror of
https://github.com/luxfhe/example-ios-demo.git
synced 2026-10-30 18:13:24 +00:00
This app is ZAMA's BSD 3-Clause Clear demo. The license requires its notices to survive redistribution, and a rebrand had replaced every one of them with ours: the LICENSE text, 66 source headers and the app's copyright string. They are back, each with our line beside it for our changes. Co-authored-by: Hanzo Dev <[email protected]>
24 lines
746 B
Swift
24 lines
746 B
Swift
// Copyright © 2025 Zama. All rights reserved.
|
|
// Copyright © 2025 Lux Industries Inc.
|
|
|
|
import TFHE
|
|
|
|
extension FHEUInt16Array {
|
|
func stats() throws -> (min: FHEUInt16, max: FHEUInt16, avg: FHEUInt16) {
|
|
let items = try readItems()
|
|
assert(items.count != 0, "empty array, cannot find min/max/avg")
|
|
var min: FHEUInt16 = items[0]
|
|
var max: FHEUInt16 = items[0]
|
|
var sum: FHEUInt16 = items[0]
|
|
|
|
for num in items[1...] {
|
|
min = try min.min(with: num)
|
|
max = try max.max(with: num)
|
|
sum = try sum.addFHE(int: num) // TODO Optim: use fhe_uint16_sum()
|
|
}
|
|
|
|
let avg = try sum.divScalar(int: items.count)
|
|
return (min, max, avg)
|
|
}
|
|
}
|