@@ -11,7 +11,7 @@ use super::super::{FheBackendArray, FheBackendArraySlice, FheBackendArraySliceMu
11
11
use crate :: array:: traits:: TensorSlice ;
12
12
use crate :: integer:: BooleanBlock ;
13
13
use crate :: prelude:: { FheDecrypt , FheTryEncrypt } ;
14
- use crate :: { ClientKey , Device } ;
14
+ use crate :: { ClientKey , CpuFheBoolArray , Device , FheBool } ;
15
15
use std:: borrow:: { Borrow , Cow } ;
16
16
use std:: ops:: RangeBounds ;
17
17
@@ -33,6 +33,43 @@ impl ArrayBackend for DynFheBoolArrayBackend {
33
33
type Owned = InnerBoolArray ;
34
34
}
35
35
36
+ impl TryFrom < Vec < FheBool > > for FheBoolArray {
37
+ type Error = crate :: Error ;
38
+
39
+ fn try_from ( values : Vec < FheBool > ) -> Result < Self , Self :: Error > {
40
+ if values. is_empty ( ) {
41
+ return Ok ( Self :: new ( InnerBoolArray :: Cpu ( vec ! [ ] ) , vec ! [ 0 ] ) ) ;
42
+ }
43
+
44
+ let shape = vec ! [ values. len( ) ] ;
45
+ let device_of_first = values[ 0 ] . current_device ( ) ;
46
+ let inner = match device_of_first {
47
+ Device :: Cpu => {
48
+ let new_values = values
49
+ . into_iter ( )
50
+ . map ( |value| value. ciphertext . into_cpu ( ) )
51
+ . collect :: < Vec < _ > > ( ) ;
52
+
53
+ InnerBoolArray :: Cpu ( new_values)
54
+ }
55
+ #[ cfg( feature = "gpu" ) ]
56
+ Device :: CudaGpu => return crate :: error!( "Array do not support GPU" ) ,
57
+ #[ cfg( feature = "hpu" ) ]
58
+ Device :: Hpu => return crate :: error!( "Array do not support HPU" ) ,
59
+ } ;
60
+
61
+ Ok ( Self :: new ( inner, shape) )
62
+ }
63
+ }
64
+
65
+ impl From < CpuFheBoolArray > for FheBoolArray {
66
+ fn from ( cpu_array : CpuFheBoolArray ) -> Self {
67
+ let CpuFheBoolArray { elems, dims, _id } = cpu_array;
68
+
69
+ Self :: new ( InnerBoolArray :: Cpu ( elems) , dims)
70
+ }
71
+ }
72
+
36
73
impl BitwiseArrayBackend for DynFheBoolArrayBackend {
37
74
fn bitand < ' a > (
38
75
lhs : TensorSlice < ' _ , Self :: Slice < ' a > > ,
0 commit comments