protected TensorDimensionsBase(IImmutableList<int> immutableDimensions) { m_dims = immutableDimensions; // Precompute this since we are immutable. ElementCount = IsEmpty ? 0 : Math.Abs(m_dims.Aggregate(1, (acc, item) => acc * item)); // Tolerate -1s. }
public override int GetHashCode() { if (m_hashCode == -1) { m_hashCode = IsEmpty ? 0 : m_dims.Aggregate(19, (acc, item) => 31 * acc + item); } return(m_hashCode); }
public Dimensions(IImmutableList <int> immutableDimensions) { if (immutableDimensions.Count > MaxDimensions) { throw new InvalidDimensionsException($"Maximum number of dimensions is {MaxDimensions}."); } m_dims = immutableDimensions; // Precompute this since we are immutable. ElementCount = IsEmpty ? 0 : Math.Abs(m_dims.Aggregate(1, (acc, item) => acc * item)); // Tolerate -1s. }