jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def test_size_metrics(self) -> None:
        """Test the size_metrics method.
        """
        p1 = Parameter()
        p2 = Parameter(3, nonpos=True)
        p3 = Parameter((4, 4), nonneg=True)

        c1 = numpy.random.randn(2, 1)
        c2 = numpy.random.randn(1, 2)
        constants = [2, c2.dot(c1)]

        p = Problem(cp.Minimize(p1), [self.a + p1 <= p2,
                                      self.b <= p3 + p3 + constants[0],
                                      self.c == constants[1]])
        # num_scalar_variables
        n_variables = p.size_metrics.num_scalar_variables
        ref = self.a.size + self.b.size + self.c.size
        self.assertEqual(n_variables, ref)

        # num_scalar_data
        n_data = p.size_metrics.num_scalar_data
        # 2 and c2.dot(c1) are both single scalar constants.
        ref = n.prod(p1.size) + n.prod(p2.size) + n.prod(p3.size) + len(constants)
        self.assertEqual(n_data, ref)

        # num_scalar_eq_constr
        n_eq_constr = p.size_metrics.num_scalar_eq_constr
        ref = c2.dot(c1).size
        self.assertEqual(n_eq_constr, ref)

        # num_scalar_leq_constr
        n_leq_constr = p.size_metrics.num_scalar_leq_constr
        ref = n.prod(p3.size) + n.prod(p2.size)
        self.assertEqual(n_leq_constr, ref)

        # max_data_dimension
        max_data_dim = p.size_metrics.max_data_dimension
        ref = max(p3.shape)
        self.assertEqual(max_data_dim, ref)
//  [python]
def test_size_metrics(self) -> None:
        """Test the size_metrics method.
        """
        p1 = Parameter()
        p2 = Parameter(3, nonpos=True)
        p3 = Parameter((4, 4), nonneg=True)

        c1 = numpy.random.randn(2, 1)
        c2 = numpy.random.randn(1, 2)
        constants = [2, c2.dot(c1)]

        p = Problem(cp.Minimize(p1), [self.a + p1 <= p2,
                                      self.b <= p3 + p3 + constants[0],
                                      self.c == constants[1]])
        # num_scalar_variables
        n_variables = p.size_metrics.num_scalar_variables
        ref = self.a.size + self.b.size + self.c.size
        self.assertEqual(n_variables, ref)

        # num_scalar_data
        n_data = p.size_metrics.num_scalar_data
        # 2 and c2.dot(c1) are both single scalar constants.
        ref = numpy.prod(p1.size) + numpy.prod(p2.size) + numpy.prod(p3.size) + len(constants)
        self.assertEqual(n_data, ref)

        # num_scalar_eq_constr
        n_eq_constr = p.size_metrics.num_scalar_eq_constr
        ref = c2.dot(c1).size
        self.assertEqual(n_eq_constr, ref)

        # num_scalar_leq_constr
        n_leq_constr = p.size_metrics.num_scalar_leq_constr
        ref = numpy.prod(p3.size) + numpy.prod(p2.size)
        self.assertEqual(n_leq_constr, ref)

        # max_data_dimension
        max_data_dim = p.size_metrics.max_data_dimension
        ref = max(p3.shape)
        self.assertEqual(max_data_dim, ref)
//  [python]
def gluon_total_param_num(net):
    return sum([n.prod(v.shape) for v in net.collect_params().values()])
//  [python]
def gluon_total_param_num(net):
    return sum([np.prod(v.shape) for v in net.collect_params().values()])
//  [python]
def gluon_net_info(net, save_path=None):
    info_str = 'Total Param Number: {}\n'.format(gluon_total_param_num(net)) +\
               'Params:\n'
    for k, v in net.collect_params().items():
        info_str += '\t{}: {}, {}\n'.format(k, v.shape, n.prod(v.shape))
    info_str += str(net)
    if save_path is not None:
        with open(save_path, 'w') as f:
            f.write(info_str)
    return info_str
//  [python]
def gluon_net_info(net, save_path=None):
    info_str = 'Total Param Number: {}\n'.format(gluon_total_param_num(net)) +\
               'Params:\n'
    for k, v in net.collect_params().items():
        info_str += '\t{}: {}, {}\n'.format(k, v.shape, np.prod(v.shape))
    info_str += str(net)
    if save_path is not None:
        with open(save_path, 'w') as f:
            f.write(info_str)
    return info_str
//  [python]
def combined_encoding(self, cols, values):
        layer_domains = []
        for col in cols:
            layer_domains.append(len(self.tree_range_lists[col][self.tree_heights[col] - 1]))
        ce_values = np.zeros(len(values))
        for i, col in enumerate(cols):
            factor = int(n.prod(layer_domains[i + 1:]))
            ce_values += values[:, col] * factor
        return ce_values, n.prod(layer_domains)
//  [python]
def combined_encoding(self, cols, values):
        layer_domains = []
        for col in cols:
            layer_domains.append(len(self.tree_range_lists[col][self.tree_heights[col] - 1]))
        ce_values = np.zeros(len(values))
        for i, col in enumerate(cols):
            factor = int(np.prod(layer_domains[i + 1:]))
            ce_values += values[:, col] * factor
        return ce_values, np.prod(layer_domains)
//  [python]
def _read_data(self, fh, byteorder='>'):
        """Return image data from open file as numpy array."""
        fh.seek(len(self.header))
        data = fh.read()
        dtype = 'u1' if self.maxval < 256 else byteorder + 'u2'
        depth = 1 if self.magicnum == b"P7 332" else self.depth
        shape = [-1, self.height, self.width, depth]
        size = self.height * self.width * depth
        if self.magicnum in b"P1P2P3":
            data = numpy.array(data.split(None, size)[:size], dtype)
            data = data.reshape(shape)
        elif self.maxval == 1:
            shape[2] = int(math.ceil(self.width / 8))
            data = numpy.frombuffer(data, dtype).reshape(shape)
            data = numpy.unpackbits(data, axis=-2)[:, :, :self.width, :]
        else:
            data = numpy.frombuffer(data, dtype)
            data = data[:size * (data.size // size)].reshape(shape)
        if data.shape[0] < 2:
            data = data.reshape(data.shape[1:])
        if data.shape[-1] < 2:
            data = data.reshape(data.shape[:-1])
        if self.magicnum == b"P7 332":
            rgb332 = numpy.array(list(numpy.ndindex(8, 8, 4)), numpy.uint8)
            rgb332 *= [36, 36, 85]
            data = numpy.take(rgb332, data, axis=0)
        return data
//  [python]
def _read_data(self, fh, byteorder='>'):
        """Return image data from open file as numpy array."""
        fh.seek(len(self.header))
        data = fh.read()
        dtype = 'u1' if self.maxval < 256 else byteorder + 'u2'
        depth = 1 if self.magicnum == b"P7 332" else self.depth
        shape = [-1, self.height, self.width, depth]
        size = numpy.prod(shape[1:])
        if self.magicnum in b"P1P2P3":
            data = numpy.array(data.split(None, size)[:size], dtype)
            data = data.reshape(shape)
        elif self.maxval == 1:
            shape[2] = int(math.ceil(self.width / 8))
            data = numpy.frombuffer(data, dtype).reshape(shape)
            data = numpy.unpackbits(data, axis=-2)[:, :, :self.width, :]
        else:
            data = numpy.frombuffer(data, dtype)
            data = data[:size * (data.size // size)].reshape(shape)
        if data.shape[0] < 2:
            data = data.reshape(data.shape[1:])
        if data.shape[-1] < 2:
            data = data.reshape(data.shape[:-1])
        if self.magicnum == b"P7 332":
            rgb332 = numpy.array(list(numpy.ndindex(8, 8, 4)), numpy.uint8)
            rgb332 *= [36, 36, 85]
            data = numpy.take(rgb332, data, axis=0)
        return data
//  [python]
def sparsify_tensor(tensor, card):
    """Zeros out all elements in the `tensor` except `card` elements with maximum absolute values.

    Parameters
    ----------
    tensor : ndarray
    card : int
        Desired number of non-zero elements in the `tensor`

    Returns
    -------
    ndarray of shape tensor.shape
    """
    if card >= n.prod(tensor.shape):
        return tensor
    bound = tl.sort(tl.abs(tensor), axis=None)[-card]

    return tl.where(
        tl.abs(tensor) < bound, tl.zeros(tensor.shape, **tl.context(tensor)), tensor
    )
//  [python]
def sparsify_tensor(tensor, card):
    """Zeros out all elements in the `tensor` except `card` elements with maximum absolute values.

    Parameters
    ----------
    tensor : ndarray
    card : int
        Desired number of non-zero elements in the `tensor`

    Returns
    -------
    ndarray of shape tensor.shape
    """
    if card >= np.prod(tensor.shape):
        return tensor
    bound = tl.sort(tl.abs(tensor), axis=None)[-card]

    return tl.where(
        tl.abs(tensor) < bound, tl.zeros(tensor.shape, **tl.context(tensor)), tensor
    )
//  [python]
def test_probability(X, alphas):
	x = [[0.0], [2.0], [8.0], [0.0], [1.9]]
	y = [1.0, 0.0, 0.0, 1.0, 0.0]

	d1 = DiracDelta([1.0])

	_test_predictions(x, y, d1.probability(x), torch.float32)

	x = [[1.0, 2.0, 4],
	     [0.0, 0.0, 0.0]]
	y = [0.0, n.prod(alphas)]

	d1 = DiracDelta(alphas)
	d2 = DiracDelta(numpy.array(alphas, dtype=numpy.float64))

	_test_predictions(x, y, d1.probability(x), torch.float32)
	_test_predictions(x, y, d2.probability(x), torch.float64)

	p = [1, 2, 4]
	x = [[1, 2, 1],
	     [2, 2, 1],
	     [0, 0, 0],
	     [0, 0, 2]]
	y = [0.0, 0.0, n.prod(p), 0.0]

	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))

	_test_predictions(x, y, d1.probability(x), torch.float32)
	_test_predictions(x, y, d2.probability(x), torch.float64)

	p = [1.0, 2.0, 4.0]
	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))
	_test_predictions(x, y, d1.probability(x), torch.float32)
	_test_predictions(x, y, d2.probability(x), torch.float64)
//  [python]
def test_probability(X, alphas):
	x = [[0.0], [2.0], [8.0], [0.0], [1.9]]
	y = [1.0, 0.0, 0.0, 1.0, 0.0]

	d1 = DiracDelta([1.0])

	_test_predictions(x, y, d1.probability(x), torch.float32)

	x = [[1.0, 2.0, 4],
	     [0.0, 0.0, 0.0]]
	y = [0.0, numpy.prod(alphas)]

	d1 = DiracDelta(alphas)
	d2 = DiracDelta(numpy.array(alphas, dtype=numpy.float64))

	_test_predictions(x, y, d1.probability(x), torch.float32)
	_test_predictions(x, y, d2.probability(x), torch.float64)

	p = [1, 2, 4]
	x = [[1, 2, 1],
	     [2, 2, 1],
	     [0, 0, 0],
	     [0, 0, 2]]
	y = [0.0, 0.0, numpy.prod(p), 0.0]

	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))

	_test_predictions(x, y, d1.probability(x), torch.float32)
	_test_predictions(x, y, d2.probability(x), torch.float64)

	p = [1.0, 2.0, 4.0]
	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))
	_test_predictions(x, y, d1.probability(x), torch.float32)
	_test_predictions(x, y, d2.probability(x), torch.float64)
//  [python]
def cdf(self, x_data):
        """
        Cumulative distribution function.

        Note that chaospy only supports cumulative distribution functions for
        stochastically independent distributions.

        Args:
            x_data (numpy.ndarray):
                Location for the distribution function. Assumes that
                ``len(x_data) == len(distribution)``.

        Returns:
            (numpy.ndarray):
                Evaluated distribution function values, where output has shape
                ``x_data.shape`` in one dimension and ``x_data.shape[1:]`` in
                higher dimensions.
        """
        check_dependencies(self)
        if self.stochastic_dependent:
            raise chaospy.StochasticallyDependentError(
                "Cumulative distribution does not support dependencies."
            )
        x_data = numpy.asarray(x_data)
        if self.interpret_as_integer:
            x_data = x_data + 0.5
        q_data = self.fwd(x_data)
        if len(self) > 1:
            q_data = n.prod(q_data, 0)
        return q_data
//  [python]
def cdf(self, x_data):
        """
        Cumulative distribution function.

        Note that chaospy only supports cumulative distribution functions for
        stochastically independent distributions.

        Args:
            x_data (numpy.ndarray):
                Location for the distribution function. Assumes that
                ``len(x_data) == len(distribution)``.

        Returns:
            (numpy.ndarray):
                Evaluated distribution function values, where output has shape
                ``x_data.shape`` in one dimension and ``x_data.shape[1:]`` in
                higher dimensions.
        """
        check_dependencies(self)
        if self.stochastic_dependent:
            raise chaospy.StochasticallyDependentError(
                "Cumulative distribution does not support dependencies."
            )
        x_data = numpy.asarray(x_data)
        if self.interpret_as_integer:
            x_data = x_data + 0.5
        q_data = self.fwd(x_data)
        if len(self) > 1:
            q_data = numpy.prod(q_data, 0)
        return q_data
//  [python]
def update(self):
        '''
        calc outputDim, 
        '''
        if len(self._inputDim) > 2:
            self._inputDim = (self._inputDim[0],n.prod(self._inputDim[1:]))
        self._outputDim = (self._inputDim[0],self._nOutputs)
        self.checkOutputDim()
//  [python]
def update(self):
        '''
        calc outputDim, 
        '''
        if len(self._inputDim) > 2:
            self._inputDim = (self._inputDim[0],numpy.prod(self._inputDim[1:]))
        self._outputDim = (self._inputDim[0],self._nOutputs)
        self.checkOutputDim()
//  [python]
def test_log_probability(X, alphas):
	x = [[0.0], [2.0], [8.0], [0.0], [1.9]]
	y = [0.0, NEGINF, NEGINF, 0.0, NEGINF]

	d1 = DiracDelta([1.0])

	_test_predictions(x, y, d1.log_probability(x), torch.float32)

	x = [[1.0, 2.0, 4],
	     [0.0, 0.0, 0.0]]
	y = [NEGINF, numpy.log(n.prod(alphas))]

	d1 = DiracDelta(alphas)
	d2 = DiracDelta(numpy.array(alphas, dtype=numpy.float64))

	_test_predictions(x, y, d1.log_probability(x), torch.float32)
	_test_predictions(x, y, d2.log_probability(x), torch.float64)

	p = [1, 2, 4]
	x = [[1, 2, 1],
	     [2, 2, 1],
	     [0, 0, 0],
	     [0, 0, 2]]
	y = [NEGINF, NEGINF, numpy.log(n.prod(p)), NEGINF]

	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))

	_test_predictions(x, y, d1.log_probability(x), torch.float32)
	_test_predictions(x, y, d2.log_probability(x), torch.float64)

	p = [1.0, 2.0, 4.0]
	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))
	_test_predictions(x, y, d1.log_probability(x), torch.float32)
	_test_predictions(x, y, d2.log_probability(x), torch.float64)
//  [python]
def test_log_probability(X, alphas):
	x = [[0.0], [2.0], [8.0], [0.0], [1.9]]
	y = [0.0, NEGINF, NEGINF, 0.0, NEGINF]

	d1 = DiracDelta([1.0])

	_test_predictions(x, y, d1.log_probability(x), torch.float32)

	x = [[1.0, 2.0, 4],
	     [0.0, 0.0, 0.0]]
	y = [NEGINF, numpy.log(numpy.prod(alphas))]

	d1 = DiracDelta(alphas)
	d2 = DiracDelta(numpy.array(alphas, dtype=numpy.float64))

	_test_predictions(x, y, d1.log_probability(x), torch.float32)
	_test_predictions(x, y, d2.log_probability(x), torch.float64)

	p = [1, 2, 4]
	x = [[1, 2, 1],
	     [2, 2, 1],
	     [0, 0, 0],
	     [0, 0, 2]]
	y = [NEGINF, NEGINF, numpy.log(numpy.prod(p)), NEGINF]

	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))

	_test_predictions(x, y, d1.log_probability(x), torch.float32)
	_test_predictions(x, y, d2.log_probability(x), torch.float64)

	p = [1.0, 2.0, 4.0]
	d1 = DiracDelta(p)
	d2 = DiracDelta(numpy.array(p, dtype=numpy.float64))
	_test_predictions(x, y, d1.log_probability(x), torch.float32)
	_test_predictions(x, y, d2.log_probability(x), torch.float64)
//  [python]
def test_geo_mean(self) -> None:
        import numpy as np

        x = Variable(2)
        cost = cp.geo_mean(x)
        prob = Problem(cp.Maximize(cost), [x <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        self.assertAlmostEqual(prob.value, 1)

        prob = Problem(cp.Maximize(cost), [cp.sum(x) <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        self.assertItemsAlmostEqual(x.value, [.5, .5])

        x = Variable((3, 3))
        self.assertRaises(ValueError, cp.geo_mean, x)

        x = Variable((3, 1))
        g = cp.geo_mean(x)
        self.assertSequenceEqual(g.w, [Fraction(1, 3)]*3)

        x = Variable((1, 5))
        g = cp.geo_mean(x)
        self.assertSequenceEqual(g.w, [Fraction(1, 5)]*5)

        # check that we get the right answer for
        # max geo_mean(x) s.t. sum(x) <= 1
        p = np.array([.07, .12, .23, .19, .39])

        def short_geo_mean(x, p):
            p = np.array(p)/sum(p)
            x = np.array(x)
            return n.prod(x**p)

        x = Variable(5)
        prob = Problem(cp.Maximize(cp.geo_mean(x, p)), [cp.sum(x) <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        x = np.array(x.value).flatten()
        x_true = p/sum(p)

        self.assertTrue(np.allclose(prob.value, cp.geo_mean(list(x), p).value))
        self.assertTrue(np.allclose(prob.value, short_geo_mean(x, p)))
        self.assertTrue(np.allclose(x, x_true, 1e-3))

        # check that we get the right answer for
        # max geo_mean(x) s.t. norm(x) <= 1
        x = Variable(5)
        prob = Problem(cp.Maximize(cp.geo_mean(x, p)), [cp.norm(x) <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        x = np.array(x.value).flatten()
        x_true = np.sqrt(p/sum(p))

        self.assertTrue(np.allclose(prob.value, cp.geo_mean(list(x), p).value))
        self.assertTrue(np.allclose(prob.value, short_geo_mean(x, p)))
        self.assertTrue(np.allclose(x, x_true, 1e-3))

        # the following 3 tests check vstack and hstack input to geo_mean
        # the following 3 formulations should be equivalent
        n = 5
        x_true = np.ones(n)
        x = Variable(n)

        Problem(cp.Maximize(cp.geo_mean(x)), [x <= 1]).solve(solver=cp.SCS)
        xval = np.array(x.value).flatten()
        self.assertTrue(np.allclose(xval, x_true, 1e-3))

        y = cp.vstack([x[i] for i in range(n)])
        Problem(cp.Maximize(cp.geo_mean(y)), [x <= 1]).solve(solver=cp.SCS)
        xval = np.array(x.value).flatten()
        self.assertTrue(np.allclose(xval, x_true, 1e-3))

        y = cp.hstack([x[i] for i in range(n)])
        Problem(cp.Maximize(cp.geo_mean(y)), [x <= 1]).solve(solver=cp.SCS)
        xval = np.array(x.value).flatten()
        self.assertTrue(np.allclose(xval, x_true, 1e-3))
//  [python]
def test_geo_mean(self) -> None:
        import numpy as np

        x = Variable(2)
        cost = cp.geo_mean(x)
        prob = Problem(cp.Maximize(cost), [x <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        self.assertAlmostEqual(prob.value, 1)

        prob = Problem(cp.Maximize(cost), [cp.sum(x) <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        self.assertItemsAlmostEqual(x.value, [.5, .5])

        x = Variable((3, 3))
        self.assertRaises(ValueError, cp.geo_mean, x)

        x = Variable((3, 1))
        g = cp.geo_mean(x)
        self.assertSequenceEqual(g.w, [Fraction(1, 3)]*3)

        x = Variable((1, 5))
        g = cp.geo_mean(x)
        self.assertSequenceEqual(g.w, [Fraction(1, 5)]*5)

        # check that we get the right answer for
        # max geo_mean(x) s.t. sum(x) <= 1
        p = np.array([.07, .12, .23, .19, .39])

        def short_geo_mean(x, p):
            p = np.array(p)/sum(p)
            x = np.array(x)
            return np.prod(x**p)

        x = Variable(5)
        prob = Problem(cp.Maximize(cp.geo_mean(x, p)), [cp.sum(x) <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        x = np.array(x.value).flatten()
        x_true = p/sum(p)

        self.assertTrue(np.allclose(prob.value, cp.geo_mean(list(x), p).value))
        self.assertTrue(np.allclose(prob.value, short_geo_mean(x, p)))
        self.assertTrue(np.allclose(x, x_true, 1e-3))

        # check that we get the right answer for
        # max geo_mean(x) s.t. norm(x) <= 1
        x = Variable(5)
        prob = Problem(cp.Maximize(cp.geo_mean(x, p)), [cp.norm(x) <= 1])
        prob.solve(solver=cp.SCS, eps=1e-5)
        x = np.array(x.value).flatten()
        x_true = np.sqrt(p/sum(p))

        self.assertTrue(np.allclose(prob.value, cp.geo_mean(list(x), p).value))
        self.assertTrue(np.allclose(prob.value, short_geo_mean(x, p)))
        self.assertTrue(np.allclose(x, x_true, 1e-3))

        # the following 3 tests check vstack and hstack input to geo_mean
        # the following 3 formulations should be equivalent
        n = 5
        x_true = np.ones(n)
        x = Variable(n)

        Problem(cp.Maximize(cp.geo_mean(x)), [x <= 1]).solve(solver=cp.SCS)
        xval = np.array(x.value).flatten()
        self.assertTrue(np.allclose(xval, x_true, 1e-3))

        y = cp.vstack([x[i] for i in range(n)])
        Problem(cp.Maximize(cp.geo_mean(y)), [x <= 1]).solve(solver=cp.SCS)
        xval = np.array(x.value).flatten()
        self.assertTrue(np.allclose(xval, x_true, 1e-3))

        y = cp.hstack([x[i] for i in range(n)])
        Problem(cp.Maximize(cp.geo_mean(y)), [x <= 1]).solve(solver=cp.SCS)
        xval = np.array(x.value).flatten()
        self.assertTrue(np.allclose(xval, x_true, 1e-3))
//  [python]
def _impl_v1(cls, inputs, attr, params):
        axis = attr.get("axis", 1)
        in_shape = infer_shape(inputs[0])
        ndim = len(in_shape)
        if axis < 0:
            axis += ndim
        if axis == 0:
            reshape_shape = [-1]
        else:
            axis_val = [in_shape[i] for i in range(axis)]
            reshape_shape = [n.prod(axis_val)] + [-1]
        data_reshape = _op.reshape(inputs[0], newshape=reshape_shape)
        out = _op.nn.softmax(data_reshape, axis=-1)
        out = _op.reshape(out, newshape=in_shape)
        return out
//  [python]
def _impl_v1(cls, inputs, attr, params):
        axis = attr.get("axis", 1)
        in_shape = infer_shape(inputs[0])
        ndim = len(in_shape)
        if axis < 0:
            axis += ndim
        if axis == 0:
            reshape_shape = [-1]
        else:
            axis_val = [in_shape[i] for i in range(axis)]
            reshape_shape = [np.prod(axis_val)] + [-1]
        data_reshape = _op.reshape(inputs[0], newshape=reshape_shape)
        out = _op.nn.softmax(data_reshape, axis=-1)
        out = _op.reshape(out, newshape=in_shape)
        return out
//  [python]
def isStructuredData(self):
        """Returns True if data as an array-like structure.

        :rtype: bool
        """
        if self.values is None or self.axes is None:
            return False

        if numpy.prod([len(axis) for axis in self.axes]) == self.values.size:
            return True
        else:
            # Make sure there is the right number of value in axes
            for axis in self.axes:
                assert len(axis) == self.values.size
            return False
//  [python]
def size(self) -> int:
        # TODO: SNOW-1119855: Modin upgrade - modin.pandas.base.BasePandasDataset
        return np.prod(self.shape)
//  [python]
def allocate_hexagon_array(
    dev, tensor_shape=None, dtype=None, data=None, axis_separators=None, mem_scope=None
):
    if tensor_shape is None:
        assert data is not None, "Must provide either tensor shape or numpy data array"
        tensor_shape = data.shape
    elif data is not None:
        assert (
            tensor_shape == data.shape
        ), "Mismatch between provided tensor shape and numpy data array shape"

    if dtype is None:
        assert data is not None, "Must provide either dtype or numpy data array"
        dtype = data.dtype.name
    elif data is not None:
        assert dtype == data.dtype, "Mismatch between provided dtype and numpy data array dtype"

    if axis_separators is None:
        axis_separators = []

    boundaries = [0, *axis_separators, len(tensor_shape)]
    physical_shape = [
        numpy.prod(tensor_shape[dim_i:dim_f])
        for dim_i, dim_f in zip(boundaries[:-1], boundaries[1:])
    ]

    arr = tvm.nd.empty(physical_shape, dtype=dtype, device=dev)

    if data is not None:
        arr.copyfrom(data.reshape(physical_shape))

    return arr._create_view(tensor_shape)
//  [python]
global_bounds = [5,20,45,180]
    
max_id = (num_trans_per_type+1)*len(clouds)-1
id_len = len(str(max_id))
id = 0
for cloud in tqdm.tqdm(clouds):
    pcd = overlap_fast.open_pcd(cloud)
    ov = overlap_fast.overlap(pcd,box_map,max_dist)
    problem =[cloud, map_name, ov]
    
    source_cloud = open3d.io.read_point_cloud(cloud)

    

    for i in range(num_trans_per_type):
        trans, rot = pair_sampling.random_transform(*bounds)
        
        centroid, covariance = source_cloud.compute_mean_and_covariance()
        eigenvalues, _ = numpy.linalg.eig(covariance)
        scale = numpy.prod(numpy.abs(eigenvalues))    
        matrix = pair_sampling.generate_transformation(centroid, rot, trans)
        out_file_local.write(str(base_id)+format(id,'0'+str(id_len))+" "+pair_sampling.pair_to_str(problem, scale, matrix)+"\n")
        
        id = id +1
    trans, rot = pair_sampling.random_transform(*global_bounds)
    centroid, covariance = source_cloud.compute_mean_and_covariance()
    eigenvalues, _ = numpy.linalg.eig(covariance)
    scale = numpy.prod(numpy.abs(eigenvalues))    
    matrix = pair_sampling.generate_transformation(centroid, rot, trans)
    
    out_file_global.write(str(base_id)+format(id,'0'+str(id_len))+ " "+pair_sampling.pair_to_str(problem, scale, matrix)+"\n")
    id = id +1
//  [python]
def _GenerateTestData(matrix_shape, num_rhs):
  batch_shape = matrix_shape[:-2]
  matrix_shape = matrix_shape[-2:]
  m = matrix_shape[-2]
  np.random.seed(1)
  matrix = np.random.uniform(
      low=-1.0, high=1.0,
      size=np.multiply.reduce(matrix_shape)).reshape(matrix_shape).astype(np.float32)
  rhs = np.ones([m, num_rhs]).astype(np.float32)
  matrix = variables.Variable(
      np.tile(matrix, batch_shape + (1, 1)), trainable=False)
  rhs = variables.Variable(np.tile(rhs, batch_shape + (1, 1)), trainable=False)
  return matrix, rhs
//  [python]
def _GenerateTestData(matrix_shape, num_rhs):
  batch_shape = matrix_shape[:-2]
  matrix_shape = matrix_shape[-2:]
  m = matrix_shape[-2]
  np.random.seed(1)
  matrix = np.random.uniform(
      low=-1.0, high=1.0,
      size=np.prod(matrix_shape)).reshape(matrix_shape).astype(np.float32)
  rhs = np.ones([m, num_rhs]).astype(np.float32)
  matrix = variables.Variable(
      np.tile(matrix, batch_shape + (1, 1)), trainable=False)
  rhs = variables.Variable(np.tile(rhs, batch_shape + (1, 1)), trainable=False)
  return matrix, rhs
//  [python]
def rands_array(nchars, size: int) -> np.ndarray:
    chars = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
    retval = (
        np.random.default_rng(2)
        .choice(chars, size=nchars * np.prod(size), replace=True)
        .view((np.str_, nchars))
        .reshape(size)
    )
    return retval.astype("O")
//  [python]
def test(self):
        """Test correct broadcasting when the array atom is not scalar."""

        array_shape = (2, 3)
        element_shape = (3,)

        dtype = numpy.dtype((numpy.int, element_shape))
        atom = Atom.from_dtype(dtype)
        h5arr = self.h5file.create_array(self.h5file.root, 'array',
                                          atom=atom, shape=array_shape)

        size = n.prod(element_shape)
        nparr = numpy.arange(size).reshape(element_shape)

        h5arr[0] = nparr
        self.assertTrue(numpy.all(h5arr[0] == nparr))
//  [python]
def test(self):
        """Test correct broadcasting when the array atom is not scalar."""

        array_shape = (2, 3)
        element_shape = (3,)

        dtype = numpy.dtype((numpy.int, element_shape))
        atom = Atom.from_dtype(dtype)
        h5arr = self.h5file.create_array(self.h5file.root, 'array',
                                          atom=atom, shape=array_shape)

        size = numpy.prod(element_shape)
        nparr = numpy.arange(size).reshape(element_shape)

        h5arr[0] = nparr
        self.assertTrue(numpy.all(h5arr[0] == nparr))
//  [python]
def cheb2ap(N, rs):
    """
    Return (z,p,k) for Nth-order Chebyshev type II analog lowpass filter.

    The returned filter prototype has attenuation of at least ``rs`` decibels
    in the stopband.

    The filter's angular (e.g. rad/s) cutoff frequency is normalized to 1,
    defined as the point at which the attenuation first reaches ``rs``.

    See Also
    --------
    cheby2 : Filter design function using this prototype

    """
    if abs(int(N)) != N:
        raise ValueError("Filter order must be a nonnegative integer")
    elif N == 0:
        # Avoid divide-by-zero warning
        return numpy.array([]), numpy.array([]), 1

    # Ripple factor (epsilon)
    de = 1.0 / sqrt(10 ** (0.1 * rs) - 1)
    mu = arcsinh(1.0 / de) / N

    if N % 2:
        m = numpy.concatenate((numpy.arange(-N+1, 0, 2),
                               numpy.arange(2, N, 2)))
    else:
        m = numpy.arange(-N+1, N, 2)

    z = -conjugate(1j / sin(m * pi / (2.0 * N)))

    # Poles around the unit circle like Butterworth
    p = -exp(1j * pi * numpy.arange(-N+1, N, 2) / (2 * N))
    # Warp into Chebyshev II
    p = sinh(mu) * p.real + 1j * cosh(mu) * p.imag
    p = 1.0 / p

    k = (n.prod(-p, axis=0) / n.prod(-z, axis=0)).real
    return z, p, k
//  [python]
def cheb2ap(N, rs):
    """
    Return (z,p,k) for Nth-order Chebyshev type II analog lowpass filter.

    The returned filter prototype has attenuation of at least ``rs`` decibels
    in the stopband.

    The filter's angular (e.g. rad/s) cutoff frequency is normalized to 1,
    defined as the point at which the attenuation first reaches ``rs``.

    See Also
    --------
    cheby2 : Filter design function using this prototype

    """
    if abs(int(N)) != N:
        raise ValueError("Filter order must be a nonnegative integer")
    elif N == 0:
        # Avoid divide-by-zero warning
        return numpy.array([]), numpy.array([]), 1

    # Ripple factor (epsilon)
    de = 1.0 / sqrt(10 ** (0.1 * rs) - 1)
    mu = arcsinh(1.0 / de) / N

    if N % 2:
        m = numpy.concatenate((numpy.arange(-N+1, 0, 2),
                               numpy.arange(2, N, 2)))
    else:
        m = numpy.arange(-N+1, N, 2)

    z = -conjugate(1j / sin(m * pi / (2.0 * N)))

    # Poles around the unit circle like Butterworth
    p = -exp(1j * pi * numpy.arange(-N+1, N, 2) / (2 * N))
    # Warp into Chebyshev II
    p = sinh(mu) * p.real + 1j * cosh(mu) * p.imag
    p = 1.0 / p

    k = (numpy.prod(-p, axis=0) / numpy.prod(-z, axis=0)).real
    return z, p, k
//  [python]
def convolve_sep_approx(data, h, Nsep=2):
    if data.ndim == 2:
        sep_func = convolve_sep2
    elif data.ndim == 3:
        sep_func = convolve_sep3
    else:
        raise NotImplementedError("data has to 2 or 3 dimensional!")

    hs = separable_series(h + 1.e-40, Nsep)
    res = np.zeros(data.shape, np.float32)

    for i, h in enumerate(hs):
        print("sep blur %s/%s   (%s)" % (i + 1, len(hs), n.prod([np.sum(_h) for _h in h])))
        res += sep_func(data, *h[::-1])

    return res
//  [python]
def convolve_sep_approx(data, h, Nsep=2):
    if data.ndim == 2:
        sep_func = convolve_sep2
    elif data.ndim == 3:
        sep_func = convolve_sep3
    else:
        raise NotImplementedError("data has to 2 or 3 dimensional!")

    hs = separable_series(h + 1.e-40, Nsep)
    res = np.zeros(data.shape, np.float32)

    for i, h in enumerate(hs):
        print("sep blur %s/%s   (%s)" % (i + 1, len(hs), np.prod([np.sum(_h) for _h in h])))
        res += sep_func(data, *h[::-1])

    return res
//  [python]
def create_weight_variable(self, name, shape, l2, tower_setup, trainable=True, initializer=None):
    with tf.device(tower_setup.variable_device):
      if initializer is None:
        # He initialization
        initializer = tf.contrib.layers.variance_scaling_initializer(factor=2.0, mode='FAN_IN', uniform=False)
      self.n_params += numpy.prod(shape)
      W = tf.get_variable(name, shape, tower_setup.dtype, initializer, trainable=trainable)
      if l2 > 0.0:
        self.regularizers.append(l2 * tf.nn.l2_loss(W))
      if tower_setup.use_weight_summaries:
        summ = tf.summary.histogram(name, W)
        self.summaries.append(summ)
        self.add_scalar_summary(tf.reduce_max(tf.abs(W)), name + "/W_abs_max")
      return W
//  [python]
def create_transposed_conv_weight_variable(self, name, shape, l2, tower_setup, trainable=True):
    with tf.device(tower_setup.variable_device):
      weights = create_bilinear_upsampling_weights(shape)
      initializer = tf.constant_initializer(value=weights, dtype=tf.float32)
      self.n_params += numpy.prod(shape)
      W = tf.get_variable(name, shape, tower_setup.dtype, initializer,trainable=trainable)
      if l2 > 0.0:
        self.regularizers.append(l2 * tf.nn.l2_loss(W))
      if tower_setup.use_weight_summaries:
        summ = tf.summary.histogram(name, W)
        self.summaries.append(summ)
        self.add_scalar_summary(tf.reduce_max(tf.abs(W)), name + "/W_abs_max")
      return W
//  [python]
def create_bias_variable(self, name, shape, tower_setup, trainable=True, initializer=None):
    with tf.device(tower_setup.variable_device):
      if initializer is None:
        initializer = tf.constant_initializer(0.0, dtype=tower_setup.dtype)
      self.n_params += numpy.prod(shape)
      b = tf.get_variable(name, shape, tower_setup.dtype, initializer, trainable=trainable)
      if tower_setup.use_weight_summaries:
        summ = tf.summary.histogram(name, b)
        self.summaries.append(summ)
        self.add_scalar_summary(tf.reduce_max(tf.abs(b)), name + "/b_abs_max")
      return b
//  [python]
def set_flattened_params_to_model(self, model, flat_params):
        prev_ind = 0
        for param in model.parameters():
            flat_size = int(n.prod(list(param.size())))
            param.data.copy_(flat_params[prev_ind:prev_ind + flat_size].view(param.size()))
            prev_ind += flat_size
//  [python]
def set_flattened_params_to_model(self, model, flat_params):
        prev_ind = 0
        for param in model.parameters():
            flat_size = int(np.prod(list(param.size())))
            param.data.copy_(flat_params[prev_ind:prev_ind + flat_size].view(param.size()))
            prev_ind += flat_size
//  [python]
def _GetLargeMatrixSolveLsOpTests(dtype, use_placeholder, fast, l2_regularizer):

  def LargeBatchSquare(self):
    np.random.seed(1)
    num_rhs = 1
    matrix_shape = (127, 127)
    matrix = np.random.uniform(
        low=-1.0, high=1.0,
        size=np.prod(matrix_shape)).reshape(matrix_shape).astype(np.float32)
    rhs = np.ones([matrix_shape[0], num_rhs]).astype(np.float32)
    self._verifySolve(
        matrix,
        rhs,
        dtype,
        use_placeholder,
        fast,
        l2_regularizer,
        batch_shape=(16, 8))

  def LargeBatchOverdetermined(self):
    np.random.seed(1)
    num_rhs = 1
    matrix_shape = (127, 64)
    matrix = np.random.uniform(
        low=-1.0, high=1.0,
        size=np.prod(matrix_shape)).reshape(matrix_shape).astype(np.float32)
    rhs = np.ones([matrix_shape[0], num_rhs]).astype(np.float32)
    self._verifySolve(
        matrix,
        rhs,
        dtype,
        use_placeholder,
        fast,
        l2_regularizer,
        batch_shape=(16, 8))

  def LargeBatchUnderdetermined(self):
    np.random.seed(1)
    num_rhs = 1
    matrix_shape = (64, 127)
    matrix = np.random.uniform(
        low=-1.0, high=1.0,
        size=np.prod(matrix_shape)).reshape(matrix_shape).astype(np.float32)
    rhs = np.ones([matrix_shape[0], num_rhs]).astype(np.float32)
    self._verifySolve(
        matrix,
        rhs,
        dtype,
        use_placeholder,
        fast,
        l2_regularizer,
        batch_shape=(16, 8))

  return (LargeBatchSquare, LargeBatchOverdetermined, LargeBatchUnderdetermined)
//  [python]
def num_experiments(self):
        return int(n.prod([len(values) for name, values in self.ranges]))
//  [python]
def num_experiments(self):
        return int(np.prod([len(values) for name, values in self.ranges]))
//  [python]
def setUp(self):
        self.e1_shape = (self.batch_size,) + self.in_shapes[0]
        self.e2_shape = (self.batch_size,) + self.in_shapes[1]
        self.e1_size = n.prod(self.in_shapes[0])
        self.e2_size = n.prod(self.in_shapes[1])

        self.check_backward_options = {
            'atol': 1e-5, 'rtol': 1e-4}
        self.check_double_backward_options = {
            'atol': 1e-4, 'rtol': 1e-3}
//  [python]
def setUp(self):
        self.e1_shape = (self.batch_size,) + self.in_shapes[0]
        self.e2_shape = (self.batch_size,) + self.in_shapes[1]
        self.e1_size = numpy.prod(self.in_shapes[0])
        self.e2_size = numpy.prod(self.in_shapes[1])

        self.check_backward_options = {
            'atol': 1e-5, 'rtol': 1e-4}
        self.check_double_backward_options = {
            'atol': 1e-4, 'rtol': 1e-3}
//  [python]
def size(self) -> int:
        """Number of dimension of the tensor"""
        shape = self.shape
        if None in shape:
            raise ValueError("No size information in not fully specified arrays")
        return np.prod(cast(List[int], shape)).astype(int).item()
//  [python]
def test_decompress(self, dtype, shape):
        """
        Tests the byte offset decompression on GPU with various configuration
        """
        ref, raw = self._create_test_data(shape=shape, dtype=dtype)
        bs = BitshuffleLz4(len(raw), n.prod(shape), dtype=dtype)
        res = bs.decompress(raw).get()
        assert numpy.array_equal(res, ref.ravel()), "Checks decompression works"
//  [python]
def test_decompress(self, dtype, shape):
        """
        Tests the byte offset decompression on GPU with various configuration
        """
        ref, raw = self._create_test_data(shape=shape, dtype=dtype)
        bs = BitshuffleLz4(len(raw), numpy.prod(shape), dtype=dtype)
        res = bs.decompress(raw).get()
        assert numpy.array_equal(res, ref.ravel()), "Checks decompression works"
//  [python]
def test_decompress_from_buffer(self, dtype, shape):
        """Test reading compressed data from pyopencl Buffer"""
        ref, raw = self._create_test_data(shape=shape, dtype=dtype)

        bs = BitshuffleLz4(0, n.prod(shape), dtype=dtype)

        buffer = pyopencl.Buffer(
            bs.ctx,
            flags=pyopencl.mem_flags.COPY_HOST_PTR | pyopencl.mem_flags.READ_ONLY,
            hostbuf=raw,
        )

        res = bs.decompress(buffer).get()
        assert numpy.array_equal(res, ref.ravel()), "Checks decompression works"
//  [python]
def test_decompress_from_buffer(self, dtype, shape):
        """Test reading compressed data from pyopencl Buffer"""
        ref, raw = self._create_test_data(shape=shape, dtype=dtype)

        bs = BitshuffleLz4(0, numpy.prod(shape), dtype=dtype)

        buffer = pyopencl.Buffer(
            bs.ctx,
            flags=pyopencl.mem_flags.COPY_HOST_PTR | pyopencl.mem_flags.READ_ONLY,
            hostbuf=raw,
        )

        res = bs.decompress(buffer).get()
        assert numpy.array_equal(res, ref.ravel()), "Checks decompression works"
//  [python]
def test_decompress_from_array(self, dtype, shape):
        """Test reading compressed data from pyopencl Array"""
        ref, raw = self._create_test_data(shape=shape, dtype=dtype)

        bs = BitshuffleLz4(0, n.prod(shape), dtype=dtype)

        array = pyopencl.array.to_device(
            bs.queue,
            numpy.frombuffer(raw, dtype=numpy.uint8),
            array_queue=bs.queue,
        )

        res = bs.decompress(array).get()
        assert numpy.array_equal(res, ref.ravel()), "Checks decompression works"
//  [python]
def test_decompress_from_array(self, dtype, shape):
        """Test reading compressed data from pyopencl Array"""
        ref, raw = self._create_test_data(shape=shape, dtype=dtype)

        bs = BitshuffleLz4(0, numpy.prod(shape), dtype=dtype)

        array = pyopencl.array.to_device(
            bs.queue,
            numpy.frombuffer(raw, dtype=numpy.uint8),
            array_queue=bs.queue,
        )

        res = bs.decompress(array).get()
        assert numpy.array_equal(res, ref.ravel()), "Checks decompression works"
//  [python]
def setUp(self):
        self.x = np.random.uniform(-1, 1, self.x_shape).astype(np.float32)
        self.a = np.random.uniform(0.1, 10, self.x_shape).astype(np.float32)
        self.size = int(np.multiply.reduce(self.x_shape))
        self.c = np.arange(self.size).reshape(self.c_shape).astype(np.float32)
//  [python]
def setUp(self):
        self.x = np.random.uniform(-1, 1, self.x_shape).astype(np.float32)
        self.a = np.random.uniform(0.1, 10, self.x_shape).astype(np.float32)
        self.size = int(np.prod(self.x_shape))
        self.c = np.arange(self.size).reshape(self.c_shape).astype(np.float32)
//  [python]
def estimate_sr_single_1d(perturbed_datas, fos, all_digits):
        n = len(perturbed_datas)
        dimension = len(all_digits)
        result = OrderedDict()

        for d in range(1, dimension + 1):

            result[d] = OrderedDict()
            attr_sets = itertools.combinations(range(dimension), d)

            for attr_set in attr_sets:
                digits = [all_digits[x] for x in attr_set]
                result[d][attr_set] = OrderedDict()

                same_count = 0
                for i in range(n):
                    same = True
                    for j in range(len(attr_set)):
                        if not fos[attr_set[j]].support_sr(perturbed_datas[i][attr_set[j]], digits[j]):
                            same = False
                            break
                    same_count += same

                minus_count = n * n.prod([fos[x].q for x in attr_set])
                for d_ in range(1, d):
                    count_d_ = 0
                    chosen_sets_ = itertools.combinations(range(d), d_)
                    for chosen_set_ in chosen_sets_:
                        coeff = n.prod([fos[d].q for d in attr_set])
                        coeff *= n.prod(
                            [(fos[attr_set[x]].p / fos[attr_set[x]].q - 1) for x in chosen_set_])

                        attr_set_ = tuple([attr_set[chosen_set_[k]] for k in range(d_)])
                        digits_ = tuple([digits[chosen_set_[k]] for k in range(d_)])

                        count_d_ += result[d_][attr_set_][digits_] * coeff
                    minus_count += count_d_

                est = (same_count - minus_count) / n.prod([(fos[x].p - fos[x].q) for x in attr_set])
                result[d][attr_set][tuple(digits)] = est

        return result[dimension][tuple(range(dimension))][tuple(all_digits)]
//  [python]
def estimate_sr_single_1d(perturbed_datas, fos, all_digits):
        n = len(perturbed_datas)
        dimension = len(all_digits)
        result = OrderedDict()

        for d in range(1, dimension + 1):

            result[d] = OrderedDict()
            attr_sets = itertools.combinations(range(dimension), d)

            for attr_set in attr_sets:
                digits = [all_digits[x] for x in attr_set]
                result[d][attr_set] = OrderedDict()

                same_count = 0
                for i in range(n):
                    same = True
                    for j in range(len(attr_set)):
                        if not fos[attr_set[j]].support_sr(perturbed_datas[i][attr_set[j]], digits[j]):
                            same = False
                            break
                    same_count += same

                minus_count = n * np.prod([fos[x].q for x in attr_set])
                for d_ in range(1, d):
                    count_d_ = 0
                    chosen_sets_ = itertools.combinations(range(d), d_)
                    for chosen_set_ in chosen_sets_:
                        coeff = np.prod([fos[d].q for d in attr_set])
                        coeff *= np.prod(
                            [(fos[attr_set[x]].p / fos[attr_set[x]].q - 1) for x in chosen_set_])

                        attr_set_ = tuple([attr_set[chosen_set_[k]] for k in range(d_)])
                        digits_ = tuple([digits[chosen_set_[k]] for k in range(d_)])

                        count_d_ += result[d_][attr_set_][digits_] * coeff
                    minus_count += count_d_

                est = (same_count - minus_count) / np.prod([(fos[x].p - fos[x].q) for x in attr_set])
                result[d][attr_set][tuple(digits)] = est

        return result[dimension][tuple(range(dimension))][tuple(all_digits)]
//  [python]
def test_data_item_with_numpy_bool_to_data_element_produces_json_compatible_dict(self):
        data_item = DataItem.DataItem(numpy.zeros((16, 16)))
        data_item.large_format = numpy.prod((2,3,4), dtype=numpy.int64) > 10  # produces a numpy.bool_
        with contextlib.closing(data_item):
            data_element = ImportExportManager.create_data_element_from_data_item(data_item, include_data=False)
            json.dumps(data_element)
//  [python]
def __init__(self, name, inputs, tower_setup, n_convs=2, n_features=None, dilations=None, strides=None,
               filter_size=None, activation="relu", dropout=0.0, batch_norm_decay=BATCH_NORM_DECAY_DEFAULT,
               l2=L2_DEFAULT):
    super(ResidualUnit2, self).__init__()
    curr, n_features_inp = prepare_input(inputs)
    res = curr
    assert n_convs >= 1, n_convs

    if dilations is not None:
      assert strides is None
    elif strides is None:
      strides = [[1, 1]] * n_convs
    if filter_size is None:
      filter_size = [[3, 3]] * n_convs
    if n_features is None:
      n_features = n_features_inp
    if not isinstance(n_features, list):
      n_features = [n_features] * n_convs

    with tf.variable_scope(name):
      curr = self.create_and_apply_batch_norm(curr, n_features_inp, batch_norm_decay, tower_setup, "bn0")
      curr = get_activation(activation)(curr)
      curr = apply_dropout(curr, dropout)

      if strides is None:
        strides_res = [1, 1]
      else:
        strides_res = n.prod(strides, axis=0).tolist()
      if (n_features[-1] != n_features_inp) or (strides_res != [1, 1]):
        W0 = self.create_weight_variable("W0", [1, 1] + [n_features_inp, n_features[-1]], l2, tower_setup)
        if dilations is None:
          res = conv2d(curr, W0, strides_res)
        else:
          res = conv2d(curr, W0)

      W1 = self.create_weight_variable("W1", filter_size[0] + [n_features_inp, n_features[0]], l2, tower_setup)
      if dilations is None:
        curr = conv2d(curr, W1, strides[0])
      else:
        curr = conv2d_dilated(curr, W1, dilations[0])
      for idx in range(1, n_convs):
        curr = self.create_and_apply_batch_norm(curr, n_features[idx - 1], batch_norm_decay,
                                                tower_setup, "bn" + str(idx + 1))
        curr = get_activation(activation)(curr)
        Wi = self.create_weight_variable("W" + str(idx + 1), filter_size[idx] + [n_features[idx - 1], n_features[idx]],
                                         l2, tower_setup)
        if dilations is None:
          curr = conv2d(curr, Wi, strides[idx])
        else:
          curr = conv2d_dilated(curr, Wi, dilations[idx])

    curr += res
    self.outputs = [curr]