TTensor


This object has been removed in release 10.0.0. Use NTL objects instead.

Implements multidimentional array object and provide some common for vectors and matrices functionality.

You can find more information in comments below.

// Partial specialization for 1D tensor    template<class TYPE, size_t SIZE>
    class TTensor<TYPE, SIZE>
    {
    public:
        const static size_t size;
        const static size_t total_element_count;
    
        TTensor() = default;
    
        TTensor(const std::initializer_list<TYPE> &values); // Create and fill with specified values 
    
        const TYPE &operator[](const size_t index) const; // Get element 
        TYPE &operator[](const size_t index); // Get/set element 
        bool operator==(const TTensor &other) const; // Compare for equality 
        bool operator!=(const TTensor &other) const; // Compare for unequality 
    
        TTensor operator+(const TYPE value) const; // Add scalar value to each element 
        TTensor operator-(const TYPE value) const; // Subtract scalar value from each element 
        TTensor operator*(const TYPE value) const; // Multiply each element on scalar value 
        TTensor operator/(const TYPE value) const; // Divide each element on scalar value 
        TTensor &operator+=(const TYPE value); // Add scalar value to each element of this tensor 
        TTensor &operator-=(const TYPE value); // Subtract scalar value from each element of this tensor 
        TTensor &operator*=(const TYPE value); // Multiply each element of this tensor on scalar value 
        TTensor &operator/=(const TYPE value); // Divide each element of this tensor on scalar value 
    
        TTensor operator+(const TTensor &other) const; // Add elements of other tensor 
        TTensor operator-(const TTensor &other) const; // Subtract elements of other tensor 
        TTensor operator*(const TTensor &other) const; // Multiply on elements of other tensor 
        TTensor operator/(const TTensor &other) const; // Divide on element of other tensor 
        TTensor &operator+=(const TTensor &other); // Add elements of other tensor to this one 
        TTensor &operator-=(const TTensor &other); // Subtract elements of other tensor from this one 
        TTensor &operator*=(const TTensor &other); // Multiply elements of this tensor on elements of other one 
        TTensor &operator/=(const TTensor &other); // Divide elements of this tensor on elements of other one 
    
        bool is_equal(const TTensor &other, const TYPE tolerance) const; // Check if tensors are equal with specified tolerance 
        bool is_not_equal(const TTensor &other, const TYPE tolerance) const; // Check if tensors are not equal with specified tolerance 
        void fill(const TYPE value); // Populate all elements with specified value 
        template<class FILLER> void fill(FILLER filler); // Populate all elements with values returned by filler function 
        TYPE norm_lmax() const; // Return LMax norm 
        TYPE norm_l1() const; // Return L1 norm 
        TYPE norm_l2() const; // Return L2 norm 
        TYPE norm_l2_2() const; // Return squared L2 norm 
        TYPE distance(const TTensor &other) const; // Return distance from other tensor 
        TYPE distance_2(const TTensor &other) const; // Return squared distance from other tensor 
        void normalize(); // Normalize 
        TTensor normalized() const; // Return normalized tensor 
        template<class DEST_TYPE> TTensor<DEST_TYPE, SIZE> convert() const; // Return tensor with the same elements but different data type 
        template<class DEST_TYPE> void convert(TTensor<DEST_TYPE, SIZE> &dest) const; // Copy elements into the destination tensor converting them to new data type 
    };
    
    // Tensor template 
    template<class TYPE, size_t SIZE, size_t ...Dimentions>
    class TTensor<TYPE, SIZE, Dimentions...>
    {
    public:
        const static size_t size; // Element count 
        const static size_t total_element_count; // Total element count 
    
        TTensor() = default;
    
        TTensor(const std::initializer_list<TTensor<TYPE, Dimentions...>> &values); // Create and populate with specified values 
    
        const TTensor<TYPE, Dimentions...> &operator[](const size_t index) const; // Get element value 
        TTensor<TYPE, Dimentions...> &operator[](const size_t index); // Get/set element value 
        bool operator==(const TTensor &other) const; // Check if tensors are equal 
        bool operator!=(const TTensor &other) const; // Check if tensors are not equal 
    
        TTensor operator+(const TYPE value) const; // Add scalar value to all elements 
        TTensor operator-(const TYPE value) const; // Subtract scalar value from all elements 
        TTensor operator*(const TYPE value) const; // Multiply all elements on scalar value 
        TTensor operator/(const TYPE value) const; // Divide all elements on scalar value 
        TTensor &operator+=(const TYPE value); // Add scalar value to all elements of this tensor 
        TTensor &operator-=(const TYPE value); // Subtract scalar value from all elements of this tensor 
        TTensor &operator*=(const TYPE value); // Multiply all elements of this tensor on scalar value 
        TTensor &operator/=(const TYPE value); // Divide all elements of this tensor on scalar value 
    
        TTensor operator+(const TTensor &other) const; // Add elements from other tensor 
        TTensor operator-(const TTensor &other) const; // Subtract elements of other tensor 
        TTensor operator*(const TTensor &other) const; // Multiply all elements on elements from other tensor 
        TTensor operator/(const TTensor &other) const; // Divide all elements on elements of other tensor 
        TTensor &operator+=(const TTensor &other); // Add all elements of other tensor to this one 
        TTensor &operator-=(const TTensor &other); // Subtract all elements of other tensor from this one 
        TTensor &operator*=(const TTensor &other); // Multiply elements of this tensor on elements of other one 
        TTensor &operator/=(const TTensor &other); // Divide all elements of this tensor on elements of other one 
    
        bool is_equal(const TTensor &other, const TYPE tolerance) const; // Check if tensors are equal with specified tolerance 
        bool is_not_equal(const TTensor &other, const TYPE tolerance) const; // Check if tensors are not equal with specified tolerance 
        void fill(const TYPE value); // Populate all elements with specified value 
        template<class FILLER> void fill(FILLER filler); // Populate all elements with values returned by specified filler function 
        TYPE norm_lmax() const; // Return LMax norm 
        TYPE norm_l1() const; // Return L1 norm 
        TYPE norm_l2() const; // Return L2 norm 
        TYPE norm_l2_2() const; // Return squared L2 norm 
        TYPE distance(const TTensor &other) const; // Return distance from other tensor 
        TYPE distance_2(const TTensor &other) const; // Return squared distance from other tensor 
        void normalize(); // Normalize 
        TTensor normalized() const; // Return normalized tensor 
        template<class DEST_TYPE> TTensor<DEST_TYPE, SIZE> convert() const; // Return tensor with the same elements but different data type 
        template<class DEST_TYPE> void convert(TTensor<DEST_TYPE, SIZE> &dest) const; // Copy elements into the destination tensor converting them to new data type 
    };
    
    // Operators 
    template<class TYPE>
    TTensor<TYPE, 3u> operator^(const TTensor<TYPE, 3u> &a, const TTensor<TYPE, 3u> &b); // Multiply 1D tensors(vectors) 
    
    template<class TYPE>
    TTensor<TYPE, 3u> &operator^=(TTensor<TYPE, 3u> &a, const TTensor<TYPE, 3u> &b); // Multiply 1D tensors(vectors) and store result in first one 
    
    template<class TYPE, size_t ROWS, size_t COLUMNS>
    TTensor<TYPE, ROWS> operator^(const TTensor<TYPE, ROWS, COLUMNS> &m, const TTensor<TYPE, COLUMNS> &v); // Multiply 2D tensor(matrix) by 1D tensor(vector) 
    
    template<class TYPE, size_t ROWS, size_t COLUMNS>
    TTensor<TYPE, COLUMNS> operator^(const TTensor<TYPE, ROWS> &v, const TTensor<TYPE, ROWS, COLUMNS> &m); // Multiply 1D tensor(vector) by 2D tensor(matrix)  
    
    template<class TYPE, size_t ROWS, size_t COLUMNS, size_t COLUMNS_OTHER>
    TTensor<TYPE, ROWS, COLUMNS_OTHER> operator^(const TTensor<TYPE, ROWS, COLUMNS> &a, const TTensor<TYPE, COLUMNS, COLUMNS_OTHER> &b); // Multiply 2D tensors(matrices) 
    
    template<class TYPE, size_t SIZE>
    TTensor<TYPE, SIZE, SIZE> &operator^=(TTensor<TYPE, SIZE, SIZE> &a, const TTensor<TYPE, SIZE, SIZE> &b); // Multiply 2D tensors(matrices) and store result in first one
Namespace: nitisa::math
Include: Nitisa/Modules/Math/Tensor.h