MCPcopy
hub / github.com/dmlc/dgl / Frame

Class Frame

python/dgl/frame.py:571–1029  ·  view source on GitHub ↗

The columnar storage for node/edge features. The frame is a dictionary from feature names to feature columns. All columns should have the same number of rows (i.e. the same first dimension). Parameters ---------- data : dict-like, optional The frame data in dictionary.

Source from the content-addressed store, hash-verified

569
570
571class Frame(MutableMapping):
572 """The columnar storage for node/edge features.
573
574 The frame is a dictionary from feature names to feature columns.
575 All columns should have the same number of rows (i.e. the same first dimension).
576
577 Parameters
578 ----------
579 data : dict-like, optional
580 The frame data in dictionary. If the provided data is another frame,
581 this frame will NOT share columns with the given frame. So any out-place
582 update on one will not reflect to the other.
583 num_rows : int, optional
584 The number of rows in this frame. If ``data`` is provided and is not empty,
585 ``num_rows`` will be ignored and inferred from the given data.
586 """
587
588 def __init__(self, data=None, num_rows=None):
589 if data is None:
590 self._columns = dict()
591 self._num_rows = 0 if num_rows is None else num_rows
592 else:
593 assert not isinstance(data, Frame) # sanity check for code refactor
594 # Note that we always create a new column for the given data.
595 # This avoids two frames accidentally sharing the same column.
596 self._columns = {
597 k: v if isinstance(v, LazyFeature) else Column.create(v)
598 for k, v in data.items()
599 }
600 self._num_rows = num_rows
601 # infer num_rows & sanity check
602 for name, col in self._columns.items():
603 if isinstance(col, LazyFeature):
604 continue
605 if self._num_rows is None:
606 self._num_rows = len(col)
607 elif len(col) != self._num_rows:
608 raise DGLError(
609 "Expected all columns to have same # rows (%d), "
610 "got %d on %r." % (self._num_rows, len(col), name)
611 )
612
613 # Initializer for empty values. Initializer is a callable.
614 # If is none, then a warning will be raised
615 # in the first call and zero initializer will be used later.
616 self._initializers = {} # per-column initializers
617 self._default_initializer = None
618
619 def _set_zero_default_initializer(self):
620 """Set the default initializer to be zero initializer."""
621 self._default_initializer = zero_initializer
622
623 def get_initializer(self, column=None):
624 """Get the initializer for empty values for the given column.
625
626 Parameters
627 ----------
628 column : str

Callers 10

invoke_udf_reduceFunction · 0.85
add_rowsMethod · 0.85
appendMethod · 0.85
cloneMethod · 0.85
deepcloneMethod · 0.85
subframeMethod · 0.85
_initMethod · 0.85
combine_framesFunction · 0.85
get_graphMethod · 0.85
_coalesce_edge_frameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected