Exemplo n.º 1
0
            private static IColumn KeyValueMetadataFromMetadata <T>(ISchema schema, int col, string metadataName)
            {
                Contracts.AssertValue(schema);
                Contracts.Assert(0 <= col && col < schema.ColumnCount);
                var type = schema.GetMetadataTypeOrNull(metadataName, col);

                Contracts.AssertValue(type);
                Contracts.Assert(type.RawType == typeof(T));

                ValueGetter <T> getter = (ref T val) => schema.GetMetadata(metadataName, col, ref val);

                return(RowColumnUtils.GetColumn(MetadataUtils.Kinds.KeyValues, type, getter));
            }
Exemplo n.º 2
0
            private BindingsImpl(ISchema input, ISchemaBoundRowMapper mapper, string suffix, string scoreColumnKind,
                                 bool user, int scoreColIndex, ColumnType predColType)
                : base(input, mapper, suffix, user, DefaultColumnNames.PredictedLabel)
            {
                Contracts.AssertNonEmpty(scoreColumnKind);
                Contracts.Assert(DerivedColumnCount == 1);

                ScoreColumnIndex = scoreColIndex;
                ScoreColumnKind  = scoreColumnKind;
                PredColType      = predColType;

                _getScoreColumnKind = GetScoreColumnKind;
                _getScoreValueKind  = GetScoreValueKind;

                // REVIEW: This logic is very specific to multiclass, which is deeply
                // regrettable, but the class structure as designed and the status of this schema
                // bearing object makes pushing the logic into the multiclass scorer almost impossible.
                if (predColType.IsKey)
                {
                    ColumnType scoreSlotsType = mapper.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.SlotNames, scoreColIndex);
                    if (scoreSlotsType != null && scoreSlotsType.IsKnownSizeVector &&
                        scoreSlotsType.VectorSize == predColType.KeyCount)
                    {
                        Contracts.Assert(scoreSlotsType.VectorSize > 0);
                        IColumn col = Utils.MarshalInvoke(KeyValueMetadataFromMetadata <int>,
                                                          scoreSlotsType.RawType, mapper.Schema, scoreColIndex, MetadataUtils.Kinds.SlotNames);
                        _predColMetadata = RowColumnUtils.GetRow(null, col);
                    }
                    else
                    {
                        scoreSlotsType = mapper.Schema.GetMetadataTypeOrNull(MetadataUtils.Kinds.TrainingLabelValues, scoreColIndex);
                        if (scoreSlotsType != null && scoreSlotsType.IsKnownSizeVector &&
                            scoreSlotsType.VectorSize == predColType.KeyCount)
                        {
                            Contracts.Assert(scoreSlotsType.VectorSize > 0);
                            IColumn col = Utils.MarshalInvoke(KeyValueMetadataFromMetadata <int>,
                                                              scoreSlotsType.RawType, mapper.Schema, scoreColIndex, MetadataUtils.Kinds.TrainingLabelValues);
                            _predColMetadata = RowColumnUtils.GetRow(null, col);
                        }
                    }
                }
            }
Exemplo n.º 3
0
 /// <summary>
 /// Returns a row that is a deep in-memory copy of an input row. Note that inactive
 /// columns are allowed in this row, and their activity or inactivity will be reflected
 /// in the output row. Note that the deep copy includes a copy of the metadata as well.
 /// </summary>
 /// <param name="row">The input row</param>
 /// <returns>A deep in-memory copy of the input row</returns>
 public static IRow CloneRow(IRow row)
 {
     Contracts.CheckValue(row, nameof(row));
     return(RowColumnUtils.GetRow(null,
                                  Utils.BuildArray(row.Schema.ColumnCount, c => RowColumnUtils.GetColumn(row, c))));
 }