secretflow.security.compare#
Classes:
The abstract comparator. |
|
|
Comparator based on a device (PYU or SPU). |
|
Plaintext compartator. |
|
Compartator based on SPU. |
- class secretflow.security.compare.Comparator[源代码]#
基类:
ABC
The abstract comparator.
Methods:
min
(data[, axis, reveal])The minimum of array over a given axis.
max
(data[, axis, reveal])The maximum of array over a given axis.
- abstract min(data: List[DeviceObject], axis=None, reveal=False)[源代码]#
The minimum of array over a given axis.
- abstract max(data: List[DeviceObject], axis=None, reveal=False)[源代码]#
The maximum of array over a given axis.
- class secretflow.security.compare.DeviceComparator(device: Union[PYU, SPU])[源代码]#
基类:
Comparator
Comparator based on a device (PYU or SPU).
- device#
a PYU or SPU. The device where the computation hosts.
Attributes:
Methods:
min
(data[, axis])The minimum of array over a given axis.
max
(data[, axis])The maximum of array over a given axis.
__init__
(device)- min(data: List[DeviceObject], axis=None)[源代码]#
The minimum of array over a given axis.
- 参数:
data – array of device objects.
axis – optional. Same as the axis argument of
numpy.amin()
.
- 返回:
a device object holds the minimum.
- max(data: List[DeviceObject], axis=None)[源代码]#
The maximum of array over a given axis.
- 参数:
data – array of device objects.
axis – optional. Same as the axis argument of
numpy.amax()
.
- 返回:
a device object holds the maximum.
- class secretflow.security.compare.PlainComparator(device: Union[PYU, SPU])[源代码]#
-
Plaintext compartator.
The computation will be performed in plaintext.
警告
PlainAggregator is for debugging purpose only. You should not use it in production.
示例
>>> import numpy as np # Alice and bob are both pyu instances. >>> a = alice(lambda : np.random.rand(2, 5))() >>> b = bob(lambda : np.random.rand(2, 5))() >>> comparator = PlainComparator(alice) >>> min_a_b = comparator.min([a, b], axis=0) >>> sf.reveal(min_a_b) array([[0.47092903, 0.77865475, 0.05917433, 0.07155096, 0.16089967], [0.56598 , 0.51047045, 0.35771865, 0.23004009, 0.23400909]], dtype=float32) >>> max_a_b = comparator.max([a, b], axis=0) >>> sf.reveal(max_a_b) array([[0.5939065 , 0.8463326 , 0.14722177, 0.9977698 , 0.6186677 ], [0.65607053, 0.611439 , 0.957074 , 0.6548823 , 0.445968 ]], dtype=float32)
Attributes:
- class secretflow.security.compare.SPUComparator(device: Union[PYU, SPU])[源代码]#
-
Compartator based on SPU.
The computation will be performed on the given SPU device.
示例
>>> import numpy as np # Alice and bob are both pyu instances. >>> a = alice(lambda : np.random.rand(2, 5))() >>> b = bob(lambda : np.random.rand(2, 5))() >>> comparator = SPUComparator(alice) >>> min_a_b = comparator.min([a, b], axis=0) >>> sf.reveal(min_a_b) array([[0.47092903, 0.77865475, 0.05917433, 0.07155096, 0.16089967], [0.56598 , 0.51047045, 0.35771865, 0.23004009, 0.23400909]], dtype=float32) >>> max_a_b = comparator.max([a, b], axis=0) >>> sf.reveal(max_a_b) array([[0.5939065 , 0.8463326 , 0.14722177, 0.9977698 , 0.6186677 ], [0.65607053, 0.611439 , 0.957074 , 0.6548823 , 0.445968 ]], dtype=float32)
Attributes:
secretflow.security.compare.comparator#
Classes:
The abstract comparator. |
- class secretflow.security.compare.comparator.Comparator[源代码]#
基类:
ABC
The abstract comparator.
Methods:
min
(data[, axis, reveal])The minimum of array over a given axis.
max
(data[, axis, reveal])The maximum of array over a given axis.
- abstract min(data: List[DeviceObject], axis=None, reveal=False)[源代码]#
The minimum of array over a given axis.
- abstract max(data: List[DeviceObject], axis=None, reveal=False)[源代码]#
The maximum of array over a given axis.
secretflow.security.compare.device_comparator#
Classes:
|
Comparator based on a device (PYU or SPU). |
- class secretflow.security.compare.device_comparator.DeviceComparator(device: Union[PYU, SPU])[源代码]#
基类:
Comparator
Comparator based on a device (PYU or SPU).
- device#
a PYU or SPU. The device where the computation hosts.
Attributes:
Methods:
min
(data[, axis])The minimum of array over a given axis.
max
(data[, axis])The maximum of array over a given axis.
__init__
(device)- min(data: List[DeviceObject], axis=None)[源代码]#
The minimum of array over a given axis.
- 参数:
data – array of device objects.
axis – optional. Same as the axis argument of
numpy.amin()
.
- 返回:
a device object holds the minimum.
- max(data: List[DeviceObject], axis=None)[源代码]#
The maximum of array over a given axis.
- 参数:
data – array of device objects.
axis – optional. Same as the axis argument of
numpy.amax()
.
- 返回:
a device object holds the maximum.
secretflow.security.compare.plain_comparator#
Classes:
|
Plaintext compartator. |
- class secretflow.security.compare.plain_comparator.PlainComparator(device: Union[PYU, SPU])[源代码]#
-
Plaintext compartator.
The computation will be performed in plaintext.
警告
PlainAggregator is for debugging purpose only. You should not use it in production.
示例
>>> import numpy as np # Alice and bob are both pyu instances. >>> a = alice(lambda : np.random.rand(2, 5))() >>> b = bob(lambda : np.random.rand(2, 5))() >>> comparator = PlainComparator(alice) >>> min_a_b = comparator.min([a, b], axis=0) >>> sf.reveal(min_a_b) array([[0.47092903, 0.77865475, 0.05917433, 0.07155096, 0.16089967], [0.56598 , 0.51047045, 0.35771865, 0.23004009, 0.23400909]], dtype=float32) >>> max_a_b = comparator.max([a, b], axis=0) >>> sf.reveal(max_a_b) array([[0.5939065 , 0.8463326 , 0.14722177, 0.9977698 , 0.6186677 ], [0.65607053, 0.611439 , 0.957074 , 0.6548823 , 0.445968 ]], dtype=float32)
Attributes:
secretflow.security.compare.spu_comparator#
Classes:
|
Compartator based on SPU. |
- class secretflow.security.compare.spu_comparator.SPUComparator(device: Union[PYU, SPU])[源代码]#
-
Compartator based on SPU.
The computation will be performed on the given SPU device.
示例
>>> import numpy as np # Alice and bob are both pyu instances. >>> a = alice(lambda : np.random.rand(2, 5))() >>> b = bob(lambda : np.random.rand(2, 5))() >>> comparator = SPUComparator(alice) >>> min_a_b = comparator.min([a, b], axis=0) >>> sf.reveal(min_a_b) array([[0.47092903, 0.77865475, 0.05917433, 0.07155096, 0.16089967], [0.56598 , 0.51047045, 0.35771865, 0.23004009, 0.23400909]], dtype=float32) >>> max_a_b = comparator.max([a, b], axis=0) >>> sf.reveal(max_a_b) array([[0.5939065 , 0.8463326 , 0.14722177, 0.9977698 , 0.6186677 ], [0.65607053, 0.611439 , 0.957074 , 0.6548823 , 0.445968 ]], dtype=float32)
Attributes: