<commit_before>from __future__ import print_function

import os
import sys

import numpy as np


def _deposit_or_erode(layers, n_layers, dz):
    """Add a new layer to the top of a stack.

    Parameters
    ----------
    layers : ndarray of shape `(n_layers, n_nodes)`
        Array of layer thicknesses.
    n_layers : int
        Number of active layers.
    dz : ndarray of shape `(n_nodes, )`
        Thickness of the new layer. Negative thicknesses mean
        erode the top-most layers.

    Examples
    --------
    >>> import numpy as np
    >>> from landlab.layers.eventlayers import _deposit_or_erode

    >>> layers = np.full((4, 3), -1.)
    >>> dz = np.array([1., 2., 3.])
    >>> _deposit_or_erode(layers, 1, dz)
    >>> layers
    array([[ 1.,  2.,  3.],
           [-1., -1., -1.],
           [-1., -1., -1.],
           [-1., -1., -1.]])

    >>> dz = np.array([1., 1., 1.])
    >>> _deposit_or_erode(layers, 2, dz)
    >>> layers
    array([[ 1.,  2.,  3.],
           [ 1.,  1.,  1.],
           [-1., -1., -1.],
           [-1., -1., -1.]])

    >>> _deposit_or_erode(layers, 3, [1., -1., -2.])
    >>> layers
    array([[ 1.,  2.,  2.],
           [ 1.,  0.,  0.],
           [ 1.,  0.,  0.],
           [-1., -1., -1.]])
    """
    from .ext.eventlayers import deposit_or_erode

    layers = layers.reshape((layers.shape[0], -1))
    try:
        dz = dz.reshape((layers.shape[1], ))
    except AttributeError:
        dz = np.broadcast_to(dz, (layers.shape[1], ))
    finally:
        dz = np.asfarray(dz)

    deposit_or_erode(layers, n_layers, dz)
    
    
def _get_surface_index(layers, n_layers, surface_index):
    """Get index within each stack of the topographic surface.

    Parameters
    ----------
    layers : ndarray of shape `(n_layers, n_nodes)`
        Array of layer thicknesses.<commit_msg>Useage with RockBlock needs both types of errors to work this way<commit_after>from __future__ import print_function

import os
import sys

import numpy as np


def _deposit_or_erode(layers, n_layers, dz):
    """Add a new layer to the top of a stack.

    Parameters
    ----------
    layers : ndarray of shape `(n_layers, n_nodes)`
        Array of layer thicknesses.
    n_layers : int
        Number of active layers.
    dz : ndarray of shape `(n_nodes, )`
        Thickness of the new layer. Negative thicknesses mean
        erode the top-most layers.

    Examples
    --------
    >>> import numpy as np
    >>> from landlab.layers.eventlayers import _deposit_or_erode

    >>> layers = np.full((4, 3), -1.)
    >>> dz = np.array([1., 2., 3.])
    >>> _deposit_or_erode(layers, 1, dz)
    >>> layers
    array([[ 1.,  2.,  3.],
           [-1., -1., -1.],
           [-1., -1., -1.],
           [-1., -1., -1.]])

    >>> dz = np.array([1., 1., 1.])
    >>> _deposit_or_erode(layers, 2, dz)
    >>> layers
    array([[ 1.,  2.,  3.],
           [ 1.,  1.,  1.],
           [-1., -1., -1.],
           [-1., -1., -1.]])

    >>> _deposit_or_erode(layers, 3, [1., -1., -2.])
    >>> layers
    array([[ 1.,  2.,  2.],
           [ 1.,  0.,  0.],
           [ 1.,  0.,  0.],
           [-1., -1., -1.]])
    """
    from .ext.eventlayers import deposit_or_erode

    layers = layers.reshape((layers.shape[0], -1))
    try:
        dz = dz.reshape((layers.shape[1], ))
        
    except (AttributeError, ValueError):
        dz = np.broadcast_to(dz, (layers.shape[1], ))
    finally:
        dz = np.asfarray(dz)

    deposit_or_erode(layers, n_layers, dz)
    
    
def _get_surface_index(layers, n_layers, surface_index):
    """Get index within each stack of the topographic surface.

    Parameters
    ----------
    layers : ndarray of shape `(n_layers, n_nodes)`
        Array of layer thicknesses.
{'fraction_non_alphanumeric': 0.1783524393495068, 'fraction_numerical': 0.02932551319648094, 'mean_word_length': 1.8083832335329342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 69, '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': '7633240', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1302, 'n_words': 369}