internal MatrixFactorizationPredictor(IHostEnvironment env, SafeTrainingAndModelBuffer buffer, KeyType matrixColumnIndexType, KeyType matrixRowIndexType) { Contracts.CheckValue(env, nameof(env)); _host = env.Register(RegistrationName); _host.Assert(matrixColumnIndexType.RawKind == DataKind.U4); _host.Assert(matrixRowIndexType.RawKind == DataKind.U4); _host.CheckValue(buffer, nameof(buffer)); _host.CheckValue(matrixColumnIndexType, nameof(matrixColumnIndexType)); _host.CheckValue(matrixRowIndexType, nameof(matrixRowIndexType)); buffer.Get(out _numberOfRows, out _numberofColumns, out _approximationRank, out _leftFactorMatrix, out _rightFactorMatrix); _host.Assert(_numberofColumns == matrixColumnIndexType.Count); _host.Assert(_numberOfRows == matrixRowIndexType.Count); _host.Assert(_leftFactorMatrix.Length == _numberOfRows * _approximationRank); _host.Assert(_rightFactorMatrix.Length == _numberofColumns * _approximationRank); MatrixColumnIndexType = matrixColumnIndexType; MatrixRowIndexType = matrixRowIndexType; }
internal MatrixFactorizationModelParameters(IHostEnvironment env, SafeTrainingAndModelBuffer buffer, KeyType matrixColumnIndexType, KeyType matrixRowIndexType) { Contracts.CheckValue(env, nameof(env)); _host = env.Register(RegistrationName); _host.Assert(matrixColumnIndexType.RawType == typeof(uint)); _host.Assert(matrixRowIndexType.RawType == typeof(uint)); _host.CheckValue(buffer, nameof(buffer)); _host.CheckValue(matrixColumnIndexType, nameof(matrixColumnIndexType)); _host.CheckValue(matrixRowIndexType, nameof(matrixRowIndexType)); buffer.Get(out NumberOfRows, out NumberOfColumns, out ApproximationRank, out var leftFactorMatrix, out var rightFactorMatrix); _leftFactorMatrix = leftFactorMatrix; _rightFactorMatrix = rightFactorMatrix; _host.Assert(NumberOfColumns == matrixColumnIndexType.GetCountAsInt32(_host)); _host.Assert(NumberOfRows == matrixRowIndexType.GetCountAsInt32(_host)); _host.Assert(_leftFactorMatrix.Length == NumberOfRows * ApproximationRank); _host.Assert(_rightFactorMatrix.Length == ApproximationRank * NumberOfColumns); MatrixColumnIndexType = matrixColumnIndexType; MatrixRowIndexType = matrixRowIndexType; }