<commit_before>"""
Class with utilities for representing and working with matrices
"""
from numpy import dot, outer, shape, ndarray, add, subtract, multiply, zeros, divide, arange

from thunder.rdds.series import Series


# TODO: right divide and left divide
class RowMatrix(Series):
    """
    Distributed matrix data.

    Backed by an RDD of key-value pairs where the
    key is a tuple identifier, and the value is a one-dimensional array.

    Parameters
    ----------
    rdd : RDD of (tuple, array) pairs
        RDD containing the series data

    index : array-like or one-dimensional list
        Values must be unique, same length as the arrays in the input data.
        Defaults to arange(len(data)) if not provided.

    dims : Dimensions
        Specify the dimensions of the keys (min, max, and count),
        can avoid computation if known in advance

    nrows : int
        Number of rows, will be automatially computed if not provided,
        can save computation to specify if known in advance

    ncols : int
        Number of columns, will be automatically computed if not provided,
        can save computation to specify if known in advance

    """

    _metadata = ['_index', '_dims', '_ncols', '_nrows']

    def __init__(self, rdd, index=None, dims=None, nrows=None, ncols=None):
        super(RowMatrix, self).__init__(rdd)
        self._index = index
        self._dims = dims
        self._nrows = nrows
        self._ncols = ncols

    @property
    def nrows(self):
        if self._nrows is None:
            self._nrows = self.rdd.count()
        return self._nrows

    @property
    def ncols(self):
        if self._ncols is None:
            vec = self.rdd.first()[1]
            if type(vec) is ndarray:
                self._ncols = len(vec)
            else:
                self._ncols = 1
        return self._ncols

    @property
    def _constructor(self):
        return RowMatrix
<commit_msg>Added missing arguments to subclass<commit_after>"""
Class with utilities for representing and working with matrices
"""
from numpy import dot, outer, shape, ndarray, add, subtract, multiply, zeros, divide, arange

from thunder.rdds.series import Series
from thunder.rdds.data import Data


# TODO: right divide and left divide
class RowMatrix(Series):
    """
    Distributed matrix data.

    Backed by an RDD of key-value pairs where the
    key is a tuple identifier, and the value is a one-dimensional array.

    Parameters
    ----------
    rdd : RDD of (tuple, array) pairs
        RDD containing the series data

    index : array-like or one-dimensional list
        Values must be unique, same length as the arrays in the input data.
        Defaults to arange(len(data)) if not provided.

    dims : Dimensions
        Specify the dimensions of the keys (min, max, and count),
        can avoid computation if known in advance

    nrows : int
        Number of rows, will be automatially computed if not provided,
        can save computation to specify if known in advance

    ncols : int
        Number of columns, will be automatically computed if not provided,
        can save computation to specify if known in advance

    """

    _metadata = Data._metadata + ['_index', '_dims', '_ncols', '_nrows']

    def __init__(self, rdd, index=None, dims=None, dtype=None, nrows=None, ncols=None):
        super(RowMatrix, self).__init__(rdd, dtype=dtype)
        self._index = index
        self._dims = dims
        self._nrows = nrows
        self._ncols = ncols

    @property
    def nrows(self):
        if self._nrows is None:
            self._nrows = self.rdd.count()
        return self._nrows

    @property
    def ncols(self):
        if self._ncols is None:
            vec = self.rdd.first()[1]
            if type(vec) is ndarray:
                self._ncols = len(vec)
            else:
                self._ncols = 1
        return self._ncols

    @property
    def _constructor(self):
        return RowMatrix

{'fraction_non_alphanumeric': 0.07867702330243047, 'fraction_numerical': 0.0010022550739163117, 'mean_word_length': 2.3046357615894038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5876978', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1079, 'n_words': 439}