<commit_before># -*- coding: utf-8 -*-
#
import numpy

from .centroid import Centroid
from .dunavant import Dunavant

from .. import helpers


def show(
        scheme,
        triangle=numpy.array([
            [-0.5, 0.0],
            [+0.5, 0.0],
            [0, 0.5 * (numpy.sqrt(3))],
            ]),
        show_axes=False
        ):
    '''Shows the quadrature points on a given triangle. The size of the circles
    around the points coincides with their weights.
    '''
    from matplotlib import pyplot as plt

    plt.plot(triangle[:, 0], triangle[:, 1], '-k')
    plt.plot(
        [triangle[-1, 0], triangle[0, 0]],
        [triangle[-1, 1], triangle[0, 1]],
        '-k'
        )

    if not show_axes:
        plt.gca().set_axis_off()

    transformed_pts = \
        + numpy.outer(
            (1.0 - scheme.points[:, 0] - scheme.points[:, 1]),
            triangle[0]
            ) \
        + numpy.outer(scheme.points[:, 0], triangle[1]) \
        + numpy.outer(scheme.points[:, 1], triangle[2])

    vol = integrate(lambda x: numpy.ones(1), triangle, Centroid())
    helpers.plot_disks(
        plt, transformed_pts, scheme.weights, vol
        )

    plt.axis('equal')
    plt.show()
    return


def _area(triangle):
    # det is the signed volume of the triangle
    J0 = (triangle[1] - triangle[0]).T
    J1 = (triangle[2] - triangle[0]).T
    # The factor 0.5 is the volume of the reference triangle.
    det = J0[0]*J1[1] - J1[0]*J0[1]
    return abs(det)


def integrate(f, triangle, scheme, sumfun=helpers.kahan_sum):
    xi = scheme.points.T
    x = \
        + numpy.multiply.outer(1.0 - xi[0] - xi[1], triangle[0]) \
        + numpy.multiply.outer(xi[0], triangle[1]) \
        + numpy.multiply.outer(xi[1], triangle[2])
    x = x.T
    # The factor 0.5 is the volume of the reference triangle.
    return sumfun(
        numpy.rollaxis(scheme.weights * f(x), -1) * 0.5 * _area(triangle)
        )


def _numpy_all_except(a, axis=-1):
    axes = numpy.arange(a.ndim)
    axes = numpy.delete(axes, axis)
    return numpy.all(a, axis=tuple(axes))


# pylint: disable=too-many-arguments
# pylint: disable=too-many-locals<commit_msg>fix triangle area in n dimensions<commit_after># -*- coding: utf-8 -*-
#
import numpy

from .centroid import Centroid
from .dunavant import Dunavant

from .. import helpers


def show(
        scheme,
        triangle=numpy.array([
            [-0.5, 0.0],
            [+0.5, 0.0],
            [0, 0.5 * (numpy.sqrt(3))],
            ]),
        show_axes=False
        ):
    '''Shows the quadrature points on a given triangle. The size of the circles
    around the points coincides with their weights.
    '''
    from matplotlib import pyplot as plt

    plt.plot(triangle[:, 0], triangle[:, 1], '-k')
    plt.plot(
        [triangle[-1, 0], triangle[0, 0]],
        [triangle[-1, 1], triangle[0, 1]],
        '-k'
        )

    if not show_axes:
        plt.gca().set_axis_off()

    transformed_pts = \
        + numpy.outer(
            (1.0 - scheme.points[:, 0] - scheme.points[:, 1]),
            triangle[0]
            ) \
        + numpy.outer(scheme.points[:, 0], triangle[1]) \
        + numpy.outer(scheme.points[:, 1], triangle[2])

    vol = integrate(lambda x: numpy.ones(1), triangle, Centroid())
    helpers.plot_disks(
        plt, transformed_pts, scheme.weights, vol
        )

    plt.axis('equal')
    plt.show()
    return


def _area(triangle):
    edges = triangle[[1, 2, 0]] - triangle
    ei_dot_ej = numpy.einsum(
            '...k, ...k->...',
            edges[[1, 2, 0]],
            edges[[2, 0, 1]]
            )
    return 0.5 * numpy.sqrt(
        + ei_dot_ej[2] * ei_dot_ej[0]
        + ei_dot_ej[0] * ei_dot_ej[1]
        + ei_dot_ej[1] * ei_dot_ej[2]
        )


def integrate(f, triangle, scheme, sumfun=helpers.kahan_sum):
    xi = scheme.points.T
    x = \
        + numpy.multiply.outer(1.0 - xi[0] - xi[1], triangle[0]) \
        + numpy.multiply.outer(xi[0], triangle[1]) \
        + numpy.multiply.outer(xi[1], triangle[2])
    x = x.T
    # The factor 0.5 is the volume of the reference triangle.
    return sumfun(
        numpy.rollaxis(scheme.weights * f(x), -1) * _area(triangle)
        )


def _numpy_all_except(a, axis=-1):
    axes = numpy.arange(a.ndim)
    axes = numpy.delete(axes, axis)
    return numpy.all(a, axis=tuple(axes))


# pylint: disable=too-many-arguments
# pylint: disable=too-many-locals
{'fraction_non_alphanumeric': 0.15563587079286198, 'fraction_numerical': 0.028687598825389654, 'mean_word_length': 2.1073684210526316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6926060', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1528, 'n_words': 362}