public IMatrix GetEncryptedMatrix(Matrix <double> m, EMatrixFormat format, double scale) { IMatrix res = null; Utils.ProcessInEnv((env) => { EncryptedSealBfvVector[] vecs = null; if (format == EMatrixFormat.ColumnMajor) { vecs = new EncryptedSealBfvVector[m.ColumnCount]; Utils.ParallelProcessInEnv(vecs.Length, env, (penv, taskIndex, k) => { vecs[k] = new EncryptedSealBfvVector(m.Column(k), penv, scale, Format: EVectorFormat.dense, EncryptData: true); }); } else { vecs = new EncryptedSealBfvVector[m.RowCount]; Utils.ParallelProcessInEnv(vecs.Length, env, (penv, taskIndex, k) => { vecs[k] = new EncryptedSealBfvVector(m.Row(k), penv, scale, Format: EVectorFormat.dense, EncryptData: true); }); } res = new EncryptedSealBfvMatrix(vecs, env) { Format = format }; foreach (var v in vecs) { v.Dispose(); } }, this); return(res); }
public IMatrix GetMatrix(IVector[] vectors, EMatrixFormat format, bool CopyVectors = true) { IMatrix mat = null; Utils.ProcessInEnv((env) => { mat = new EncryptedSealBfvMatrix(Array.ConvertAll(vectors, v => (EncryptedSealBfvVector)v), env, CopyVectors: CopyVectors) { Format = format }; }, this); return(mat); }
public IMatrix GetPlainMatrix(Matrix <double> m, EMatrixFormat format, double scale) { IMatrix res = null; Utils.ProcessInEnv((env) => { EncryptedSealBfvVector[] vecs = (format == EMatrixFormat.ColumnMajor) ? m.EnumerateColumns().Select(v => new EncryptedSealBfvVector(v, env, scale, Format: EVectorFormat.dense, EncryptData: false)).ToArray() : m.EnumerateRows().Select(v => new EncryptedSealBfvVector(v, env, scale, Format: EVectorFormat.dense, EncryptData: false)).ToArray(); res = new EncryptedSealBfvMatrix(vecs, env) { Format = format }; foreach (var v in vecs) { v.Dispose(); } }, this); return(res); }
public static EncryptedSealBfvMatrix Read(StreamReader str, EncryptedSealBfvEnvironment env) { var mtx = new EncryptedSealBfvMatrix(); var line = str.ReadLine(); if (line != "<Start LargeEncryptedMatrix>") { throw new Exception("Bad stream format."); } mtx.Format = (EMatrixFormat)Enum.Parse(mtx.Format.GetType(), str.ReadLine()); mtx.leVectors = new EncryptedSealBfvVector[int.Parse(str.ReadLine())]; for (int i = 0; i < mtx.leVectors.Length; i++) { mtx.leVectors[i] = EncryptedSealBfvVector.Read(str, env); } line = str.ReadLine(); if (line != "<End LargeEncryptedMatrix>") { throw new Exception("Bad stream format."); } return(mtx); }
public IMatrix LoadMatrix(StreamReader str) { return(Utils.ProcessInEnv(env => EncryptedSealBfvMatrix.Read(str, env as EncryptedSealBfvEnvironment), this)); }