@@ -11,7 +11,7 @@ use super::super::{FheBackendArray, FheBackendArraySlice, FheBackendArraySliceMu
1111use crate :: array:: traits:: TensorSlice ;
1212use crate :: integer:: BooleanBlock ;
1313use crate :: prelude:: { FheDecrypt , FheTryEncrypt } ;
14- use crate :: { ClientKey , Device } ;
14+ use crate :: { ClientKey , CpuFheBoolArray , Device , FheBool } ;
1515use std:: borrow:: { Borrow , Cow } ;
1616use std:: ops:: RangeBounds ;
1717
@@ -33,6 +33,43 @@ impl ArrayBackend for DynFheBoolArrayBackend {
3333 type Owned = InnerBoolArray ;
3434}
3535
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+
3673impl BitwiseArrayBackend for DynFheBoolArrayBackend {
3774 fn bitand < ' a > (
3875 lhs : TensorSlice < ' _ , Self :: Slice < ' a > > ,
0 commit comments