<commit_before>#!/usr/bin/python
"""
This module contains classes and functions for trigonometric polynomials and
relating operators for homogenization.
"""

import copy
import itertools

from ffthompy.trigpol import Grid, enlarge, get_inverse, decrease, mean_index
import numpy as np
import numpy.fft as fft
import numpy.matlib as npmatlib


class FieldFun():
    """
    General class that provides functions for VecTri and Matrix classes.
    """
    def dN(self):
        return np.hstack([self.d, self.N])

    def ddN(self, M=None):
        if M is None:
            M=self.N
        return np.hstack([self.d, self.d, M])

    def pN(self):
        return np.prod(self.N)

    def pdN(self):
        return np.prod(self.dN())

    def zeros_like(self):
        X=copy.deepcopy(self)
        X.val[:]=0
        return X

    def mean_index(self):
        return mean_index(self.N, fft_form='c')

    def __getitem__(self, i):
        return self.val[i]

    def __repr__(self, full=False):
        ss="Class : %s\n    name : %s\n"%(self.__class__.__name__,
                                              self.name)
        ss+='    Fourier = %s \n'%(self.Fourier)
        ss+='    dimension d = %g \n'%(self.d)
        ss+='    size N = %s \n'%str(self.N)
        ss+='    val.shape  = %s \n'%str(self.val.shape)
        ss+='    norm = %s\n'%str(self.norm())
        ss+='    mean = %s\n'%str(self.mean())
        if full:
            ss+='val = \n'
            ss+=str(self.val)
        return ss


class Scalar():
    """
    Scalar value that is used to multiply VecTri or Matrix classes
    """
    def __init__(self, val=None, name='c'):
        if val is not None:
            self.val=val
        else:
            self.val=1.
        self.name=name

    def __call__(self, x):
        return self*x

    def __repr__(self):
        ss="Class : {0}\n".format(self.__class__.__name__)
        ss+="    val = {0}".format(self.val)
        return ss

    def transpose(self):
        return self


class VecTri(FieldFun, Grid):
    """
    Class representing the trigonometric polynomial using values at grid points
    or using Fourier coefficients

    Parameters
    ----------
    name : str
        name of a vector
    Fourier : boolean
        if True vector is in Fourier space, store Fourier coefficients
    elas : boolean
        if True it regards elasticity (not Implemented yet)
    val : numpy.ndarray of shape = (d, N)
        depending on Fourier, it stores the point values or
        Fourier coefficients of trigonometric polynomials
        the values are stored according to:
        kwargs['val'] : numpy.ndarray of shape (d,N)
        kwargs['macroval'] : numpy.ndarray of shape (d,)
        valtypes : str
            either of 'ones' or 'random'
    """
    def __init__(self, name='?', N=None, d=None, Fourier=False, valtype=None,
                 **kwargs):
        self.Fourier=Fourier

        if 'val' in kwargs:
            self.val=kwargs['val']
            self.N=np.array(self.val.shape[1:])
            self.d=self.val.shape[0]
        else:
            if N is not None:
                self.N=np.array(N, dtype=np.int32)
            else:
                raise ValueError("Parameter N is required!")
            if d is None:
                self.d=self.N.size
            else:
                self.d=d
<commit_msg>depreciation warning for matvec<commit_after>"""
This module contains classes and functions for trigonometric polynomials and
relating operators for homogenization.
"""

import copy
import itertools

from ffthompy.trigpol import Grid, enlarge, get_inverse, decrease, mean_index
import numpy as np
import numpy.fft as fft
import numpy.matlib as npmatlib
from warnings import warn


class FieldFun():
    """
    General class that provides functions for VecTri and Matrix classes.
    """
    def dN(self):
        return np.hstack([self.d, self.N])

    def ddN(self, M=None):
        if M is None:
            M=self.N
        return np.hstack([self.d, self.d, M])

    def pN(self):
        return np.prod(self.N)

    def pdN(self):
        return np.prod(self.dN())

    def zeros_like(self):
        X=copy.deepcopy(self)
        X.val[:]=0
        return X

    def mean_index(self):
        return mean_index(self.N, fft_form='c')

    def __getitem__(self, i):
        return self.val[i]

    def __repr__(self, full=False):
        ss="Class : %s\n    name : %s\n"%(self.__class__.__name__,
                                              self.name)
        ss+='    Fourier = %s \n'%(self.Fourier)
        ss+='    dimension d = %g \n'%(self.d)
        ss+='    size N = %s \n'%str(self.N)
        ss+='    val.shape  = %s \n'%str(self.val.shape)
        ss+='    norm = %s\n'%str(self.norm())
        ss+='    mean = %s\n'%str(self.mean())
        if full:
            ss+='val = \n'
            ss+=str(self.val)
        return ss


class Scalar():
    """
    Scalar value that is used to multiply VecTri or Matrix classes
    """
    def __init__(self, val=None, name='c'):
        if val is not None:
            self.val=val
        else:
            self.val=1.
        self.name=name

    def __call__(self, x):
        return self*x

    def __repr__(self):
        ss="Class : {0}\n".format(self.__class__.__name__)
        ss+="    val = {0}".format(self.val)
        return ss

    def transpose(self):
        return self


class VecTri(FieldFun, Grid):
    """
    Class representing the trigonometric polynomial using values at grid points
    or using Fourier coefficients

    Parameters
    ----------
    name : str
        name of a vector
    Fourier : boolean
        if True vector is in Fourier space, store Fourier coefficients
    elas : boolean
        if True it regards elasticity (not Implemented yet)
    val : numpy.ndarray of shape = (d, N)
        depending on Fourier, it stores the point values or
        Fourier coefficients of trigonometric polynomials
        the values are stored according to:
        kwargs['val'] : numpy.ndarray of shape (d,N)
        kwargs['macroval'] : numpy.ndarray of shape (d,)
        valtypes : str
            either of 'ones' or 'random'
    """
    def __init__(self, name='?', N=None, d=None, Fourier=False, valtype=None,
                 **kwargs):
        self.Fourier=Fourier
        cls_name=self.__class__.__name__
        warn("The class {} will be depreciated. Use ffthompy.tensors.".format(cls_name))

        if 'val' in kwargs:
            self.val=kwargs['val']
            self.N=np.array(self.val.shape[1:])
            self.d=self.val.shape[0]
        else:
            if N is not None:
                self.N=np.array(N, dtype=np.int32)
            else:
                raise ValueError("Parameter N is required!")
            if d is None:
                self.d=self.N.size
            else:
                self.d=d

{'fraction_non_alphanumeric': 0.11715116279069768, 'fraction_numerical': 0.002325581395348837, 'mean_word_length': 1.9021509911429777, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4709775', 'n_tokens_mistral': 2192, 'n_tokens_neox': 2098, 'n_words': 617}