8 – setError() breaks validation and causes an “Allowed memory size of xxx bytes exhausted” error

I’m creating a simple form with the following code.

<?php

namespace Drupalmy_example_moduleForm;

use DrupalCoreFormFormBase;
use DrupalCoreFormFormStateInterface;

/**
 * Class TestForm.
 */
class TestForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'test_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form('name') = (
      '#type' => 'textfield',
      '#title' => $this->t('Name'),
      '#maxlength' => 64,
      '#size' => 64,
      '#weight' => '0',
    );

    $form('submit') = (
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
    );

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $form_state->setErrorByName('name', $this->t('Error'));
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setRebuild(true);
  }

}

When I use setError() or setErrorByName(), I get an Allowed memory size of XXX bytes exhausted error when I submit the form.

I got the same output if I use setRebuild().

The logs gives me thousands of 404 errors for the form page, like it was giving me an infinite loop.

It can happen on any custom form, not specifically this one.

How can I fix this error?

calculus – Roots with same size for polynomials with distinct degrees

I am working on a problem which just arrived at the following question related to roots of polynomials.

Let $f(x)=x^7-2x^6+1$ and $g(x)=x^{10}-2x^9+1$. These polynomials have $x=1$ as their unique common root (because $f(x)/(x-1)$ and $g(x)/(x-1)$ are irreducible).

However, I would like to proof the following: If $alphaneq 1$ and $betaneq 1$ are roots of $f(x)$ and $g(x)$, respectively, then $|alpha|neq |beta|$.

I would be very grateful for any suggestion.

What size lens will give a 2ft by 2 ft view at a range of 2 ft?

The easiest way is put a zoom lens on your camera and figure out what focal length you need empirically.

Since you don’t say what your sensor size or camera model is, you’ll need to do the maths yourself.

Angle of view for your situation is about 2 * arctan(1/2) = 53°.

From a Wikipedia article: angle of view = 2 * arctan(d/(2*f)
Where: d = distance; f = focal length
d, in your case, is 610mm = 2 feet.

Solving for f: focal length = d/(2 * tan({angle of view}/2))
For a full frame sensor and using the 24mm dimension, you’ll need a focal length of 24mm.
For an APS-C sensor, 16mm.

Some caveats:

  • distance is measured from the film (sensor) plane to object. Decent cameras have a marking on the body where the film plane is located.
  • The equation for finding focal length is for a simple lens. Camera lenses aren’t simple, especially when shooting close up.
  • When focusing at closer ranges, the magnification of your lens will change. Unless you calibrate your lens, you’ll be slightly off from the equation.

mac – Using ZP505 and getting paper size oe width and height

mac – Using ZP505 and getting paper size oe width and height – Ask Different

computer vision – Number of pixels on an object and minimum size to identify an object

I want to find out how many pixels will cover a specific object in an image at a set distance.

My plan is to use the known objects height and distance to calculate the angle it subtends from the optical axis – on both axes.

Then assuming a pinhole model I will use the lenses focal point and the angle to find the height of the object’s image on the sensor.

I would then divide that by the pitch of the sensors pixels to find the number of pixels covering the object – rounding where necessary.

My questions are:

  1. is this a reasonable way to calculate the number of pixels?
  2. Does the pinhole model assumption break down for wide angle lenses?
  3. And, what is accepted as the minimum number of pixels to identify something?

Upload local folder structure (size upto 25GB) to SharePoint 2013 on premise document library

I want to migrate local folder which has upto 25GB of data (including documents and media files). Is there any free tool/script which I can use to upload data into SharePoint document library?

why is reported screen size smaller than display size with GLFW full screen window

I’m using GLFW to create a full screen GL application. I’m running it on my Ubuntu 20.04 laptop that has a typical 1920:1080 display, at least that’s the screen resolution reported under Settings->Displays. When I run the following code:

int monitor_x = 0;
int monitor_y = 0;
int monitor_width = 0;
int monitor_height = 0;

    GLFWmonitor *monitor = glfwGetPrimaryMonitor();
    glfwGetMonitorWorkarea(monitor, &monitor_x, &monitor_y, &monitor_width, &monitor_height);
    printf("before monitor %d, %d, %d, %dn", monitor_x, monitor_y, monitor_width, monitor_height);
    window = glfwCreateWindow(1920, 1080, "OpenGL", glfwGetPrimaryMonitor(), nullptr); // Fullscreen
    glfwGetMonitorWorkarea(monitor, &monitor_x, &monitor_y, &monitor_width, &monitor_height);
    printf("after monitor %d, %d, %d, %dn", monitor_x, monitor_y, monitor_width, monitor_height);

When I run the code, get the following output on stdout:

before monitor 72, 27, 1848, 1053
after monitor 72, 27, 1848, 1053

Also, it seems as if there’s a horizontal band at the top and a vertical band at the right of the full screen that remains the background color, no matter what my application attempts to write to those areas.

So 72 + 1848 = 1920 and 27 + 1053 = 1080, but it seems that the system is reserving these horizontal and vertical bands for something else that I assume has something to do with that 72 and 27.

Is there some hint or some such thing that i need to specify in order to make the entire 1920 by 1080 of the screen available for rendering?

Thanks

c++11 – template Matrix class with Static or dynamic size

I started implementing the folowing Matrix class in order to get a better understanding of templates classes in general. For now, it lacks a lot of features, it does very basic things:

  • addition
  • multiplication (only matrix X matrix multiplication is available here)
  • transpose
  • conversion to a string

Here are some points i think might be interesting

  • The dimensions of the matrices can either be “static” or “dynamic”. By static, i mean the number of rows / columns is not allowed to change even if the data is stored in an std::vector

  • When adding two matrices together, the resulting matrix’s dimension is static if at least one of the two operands is static.

  • When multiplying two matrices together, the resulting matrix’s dimension depends on the rows of the left hand side and the columns of the right hand side of the “*”.

  • The type of data contained in the returned matrix corresponds to the implicit cast of the types of the left and right sides of the expression. If the user decided to multiply a matrix of Foos, with a matrix of Bars, it’s on him.

  • The “changeSize” methode, when called on a static matrix will only throw if the requested change is different from the matrix size.

  • I did not bother for now with the type of exception i used as this is more of an exercise than something that i will use in a real application.

  • The reason i made it possible to instanciate Static or dynamic matrices is because i want it to be able to manage Vector X Matrix operations. As a vector is just a special case of matrices, i choose to made them into a single class. (in the style of Eigen, which my code is inspired from a used inteface point of view).

Is my use of the rvalues references and move semantics correct? (that is a notion i learned about last week, any advice can help)

What do you think could be improved about my code?

Is there any notion i should learn before continuing?

Were any design choices in terme of template parameters good or bad?

#ifndef UTILS_MATRIX_H_
#define UTILS_MATRIX_H_

#include <vector>
#include <stdexcept>
#include <sstream>
#include <iomanip>

namespace mat
{

  constexpr size_t DYNAMIC = static_cast<size_t>(-1); // (-) No matrix can be of this size... right?

  template<typename TYPE, size_t NBROWS, size_t NBCOLS>
  class Matrix
  {
    private:

      std::vector<std::vector<TYPE>> matrixData;             // (-) Contents of the Matrix as a 2D array
      static constexpr bool isRowStatic = NBROWS != DYNAMIC; // (-) Is the number of rows of this matrix editable at run time
      static constexpr bool isColStatic = NBCOLS != DYNAMIC; // (-) Is the number of columns of this matrix editable at run time

    public:

      /** @brief Default constructor
       *
       *  @return Void.
       */
      Matrix() :
          matrixData()
      {
        if ((NBROWS <= 0 and NBROWS != DYNAMIC) or (NBCOLS <= 0 and NBCOLS != DYNAMIC))
          throw std::runtime_error("The number of rows and columns of a static matrix must be positive integers");

        // In case of a dynamic shape, the matrix should not be instanciated
        if(isRowStatic and isColStatic)
          internalChangeSize(NBROWS, NBCOLS);
      }

      /** @brief Consutuctor for the static size matrix
       *  @param i_DefaultValue IN : Default value used to fill
       *         the matrix
       *
       *  @return Void.
       */
      Matrix(const TYPE &i_DefaultValue) :
          matrixData()
      {
        // error handling
        if (not isRowStatic or not isColStatic)
          throw std::runtime_error("The default value constructor can not be called on a Matrix with at least one dynamic component");

        if ((NBROWS <= 0 and NBROWS != DYNAMIC) or (NBCOLS <= 0 and NBCOLS != DYNAMIC))
          throw std::runtime_error("The number of rows and columns of a static matrix must be positive integers");

        internalChangeSize(NBROWS, NBCOLS, i_DefaultValue);
      }

      /** @brief Consutuctor for the dynamic size matrix without default value
       *
       *  @param i_Nbrows       IN : Number of rows of the matrix
       *  @param i_Nbcols       IN : Number of columns of the matrix
       *
       *  @return Void.
       */
      Matrix(const size_t i_Nbrows,
             const size_t i_Nbcols) :
          matrixData()
      {
        // error handling
        if (i_Nbrows <= 0 or i_Nbcols <= 0)
          throw std::runtime_error("The number or rows and columns has to be a positive integer");

        // If one dimension is static, ignore the related constructor parameters
        size_t NbRows = i_Nbrows;
        size_t NbCols = i_Nbcols;
        if(isRowStatic)
          NbRows = NBROWS;
        if(isColStatic)
          NbCols = NBCOLS;

        internalChangeSize(NbRows, NbCols, TYPE());
      }

      /** @brief Consutuctor for the dynamic size matrix with default value
       *
       *  @param i_Nbrows       IN : Number of rows of the matrix
       *  @param i_Nbcols       IN : Number of columns of the matrix
       *  @param i_DefaultValue IN : Default value used to fill the
       *                             matrix
       *
       *  @return Void.
       */
      Matrix(const size_t i_Nbrows,
             const size_t i_Nbcols,
             const TYPE &i_DefaultValue) :
          matrixData()
      {
        // error handling
        if (i_Nbrows <= 0 or i_Nbcols <= 0)
          throw std::runtime_error("The number or rows and columns has to be a positive integer");

        // If one dimension is static, ignore the related constructor parameters
        size_t NbRows = i_Nbrows;
        size_t NbCols = i_Nbcols;
        if(isRowStatic)
          NbRows = NBROWS;
        if(isColStatic)
          NbCols = NBCOLS;

        internalChangeSize(NbRows, NbCols, i_DefaultValue);
      }

      /** @brief Copy constructor
       *
       *  @param i_otherMatrix IN : Matrix to be copied
       *
       *  @return Void.
       */
      Matrix(const Matrix<TYPE, NBROWS, NBCOLS>& i_otherMatrix):
          matrixData()
      {
        if(not i_otherMatrix.isEmpty())
          {
          changeSize(i_otherMatrix.getNbRows(), i_otherMatrix.getNbCols());
          matrixData = i_otherMatrix.matrixData;
          }
      }

      /** @brief Move constructor
       *
       *  @param i_otherMatrix IN : Matrix to be moved
       *
       *  @return Void.
       */
      Matrix(Matrix<TYPE, NBROWS, NBCOLS>&& i_otherMatrix):
          matrixData()
      {
        matrixData = std::move(i_otherMatrix.matrixData);
      }

      /** @brief getter for the matrix data vector
       *
       *  @return std::vector<std::vector<TYPE>>&.
       */
      const std::vector<std::vector<TYPE>>& getMatrixData() const
      {
        return matrixData;
      }

      /** @brief getter for the number or rows
       *
       *  @return size_t
       */
      size_t getNbRows() const
      {
        return matrixData.size();
      }

      /** @brief getter for the number or columns
        *
        *  @return size_t
        */
      size_t getNbCols() const
      {
        if(matrixData.size() > 0)
          return matrixData(0).size();
        else
          return 0;
      }

      /** @brief is the Matrix is empty
        *
        *  @return bool
        */
      bool isEmpty() const
      {
        return getNbRows() == 0 or getNbCols() == 0;
      }

      /** @brief function used to retrieve the shape of the matrix
       *  @param o_NbRows OUT : Number of rows of the matrix
       *  @param o_NbCols OUT : Number of columns of the matrix
       *
       *  @return Void.
       */
      std::pair<size_t, size_t> shape() const
      {
        return std::pair<size_t, size_t>(getNbRows(), getNbCols());
      }

      /** @brief function used to print the contents of the
       *         matrix formatted into a string
       *
       *  @return std::string
       */
      std::string toString(int i_Precision = 10) const
      {
        std::ostringstream SS;

        // if 0 lines representation is an empty bracket
        if(matrixData.size() == 0)
          SS << "| |" << std::endl;

        // This will align the floating point numbers
        SS << std::showpoint;
        SS << std::setprecision(i_Precision);
        for(auto& Row : matrixData)
        {
          SS << "|";
          for(auto& Value : Row)
          {
            SS << " " << Value << " ";
          }
          SS << "|" << std::endl;
        }
        return SS.str();
      }

      /** @brief function used to change the size of the matrix
       *         This method does not require a default value,
       *         hence it is default initialized
       *
       *  @param i_NbRows IN : New number of rows of the matrix
       *  @param o_NbCols IN : New number of columns of the matrix
       *
       *  @return Void.
       */
      void changeSize(const size_t i_NbRows, const size_t i_NbCols)
      {
        // Error handling
        if (i_NbRows <= 0 or i_NbCols <= 0)
          throw std::runtime_error("The number or rows and columns has to be a positive integer");

        if (isRowStatic and NBROWS != i_NbRows)
          throw std::runtime_error("You cannot change the number of rows, the matrix row size is static.");

        if(isColStatic and NBCOLS != i_NbCols)
          throw std::runtime_error("You cannot change the number of columns, the matrix columns size is static.");

        internalChangeSize(i_NbRows, i_NbCols);
      }

      /** @brief function used to change the size of the matrix
       *         This method does not require a default value,
       *         hence it is default initialized
       *
       *  @param i_NewShape IN : New shape of the matrix
       *
       *  @return Void.
       */
      void changeSize(const std::pair<size_t, size_t>& i_NewShape)
      {
        changeSize(i_NewShape.first, i_NewShape.second);
      }

      /** @brief function used to change the size of the matrix
       *         This method requires a default value for filling
       *         any new row / column.
       *
       *  @param i_NbRows     IN : New number of rows of the matrix
       *  @param o_NbCols     IN : New number of columns of the matrix
       *  @param DefaultValue IN : Default value used to fill the matrix
       *
       *  @return Void.
       */
      void changeSize(const size_t i_NbRows, const size_t i_NbCols, const TYPE &DefaultValue)
      {
        // error handling
        if (i_NbRows <= 0 or i_NbCols <= 0)
          throw std::runtime_error("The number or rows and columns has to be a positive integer");

        if (isRowStatic and NBROWS != i_NbRows)
          throw std::runtime_error("You cannot change the number of rows, the matrix columns size is static.");

        if(isColStatic and NBCOLS != i_NbCols)
          throw std::runtime_error("You cannot change the number of columns, the matrix columns size is static.");

        internalChangeSize(i_NbRows, i_NbCols, DefaultValue);
      }

      /** @brief function used to change the size of the matrix
       *         This method requires a default value for filling
       *         any new row / column.
       *
       *  @param i_NewShape   IN : New shape of the matrix
       *  @param DefaultValue IN : Default value used to fill the matrix
       *
       *  @return Void.
       */
      void changeSize(const std::pair<size_t, size_t>& i_NewShape, const TYPE &DefaultValue)
      {

        changeSize(i_NewShape.first, i_NewShape.second, DefaultValue);
      }

      /** @brief function used to transpose the current matrix.
       *         If the matrix is dynamically allocated, it's shape
       *         might be changed by the function
       *
       *  @return Void.
       */
      void transpose()
      {
        // Error handlingmatrixData
        if (isEmpty())
          throw std::runtime_error("The transpose function can not be called on an empty matrix");

        if ((isRowStatic or isColStatic) and getNbRows() != getNbCols())
          throw std::runtime_error("The transpose function can not be called on a non square matrix with at least one static component");

        // The transposed Matrix is built and replaces the old data
        std::vector<std::vector<TYPE>> newData(getNbCols(), std::vector<TYPE>(getNbRows(), (*this)(0,0)));

        for (size_t i = 0 ; i < getNbCols() ; i += 1)
          for (size_t j = 0 ; j < getNbRows() ; j += 1)
            newData(i)(j) = (*this)(i,j);

        matrixData = std::move(newData);
      }

      /** @brief () operator. returns a reference to
       *         the value at row i, column j
       *
       *  @return const TYPE&
       */
      const TYPE& operator()(size_t i_Row, size_t i_Col) const
      {
        try
        {
          return matrixData.at(i_Row).at(i_Col);
        }
        catch(std::out_of_range& e)
        {
          const auto MatrixShape = this->shape();
          std::ostringstream SS;
          SS << "Indexes : (" << i_Row << ", " << i_Col << ") are out of bounds of the Matrix : " << "(" << MatrixShape.first << ", " << MatrixShape.second << ")";
          throw std::runtime_error(SS.str());
        }
      }

      /** @brief () operator. returns a reference to
       *         the value at row i, column j
       *
       *  @return const TYPE&
       */
      TYPE& operator()(size_t i_Row, size_t i_Col)
      {
        try
        {
          return matrixData.at(i_Row).at(i_Col);
        }
        catch(std::out_of_range& e)
        {
          const auto MatrixShape = this->shape();
          std::ostringstream SS;
          SS << "Indexes : (" << i_Row << ", " << i_Col << ") are out of bounds of the Matrix : " << "(" << MatrixShape.first << ", " << MatrixShape.second << ")";
          throw std::runtime_error(SS.str());
        }
      }

      /** @brief = operator. It copies the right hand side
       *         into the left hand size Matrix. If the sizes are
       *         different and the left hand side is static, the copy
       *         fails
       *  @param rhs  IN : Right hand side matrix
       *
       *  @return Void.
       */
      template<typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
      Matrix<TYPE, NBROWS, NBCOLS>& operator=(const Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS> &rhs)
      {
        const auto LhsShape = this->shape();
        const auto RhsShape = rhs.shape();

        // Error handling
        if ((isRowStatic and (this->getNbRows() != rhs.getNbRows())) or
            (isColStatic and (this->getNbCols() != rhs.getNbCols())))
        {
          std::ostringstream SS;
          SS << "Impossible to fit data from a matrix of size (" << rhs.getNbRows() << ", " << rhs.getNbCols() << ") into"
                " a static matrix of size (" << this->getNbRows() << ", " << this->getNbCols() << ")";
          throw std::runtime_error(SS.str());
        }

        // If both matrices are empty, we dont need to do anything
        if(not(isEmpty() and rhs.isEmpty()))
        {
          // else, change the size only if necessary, taking a default value in one of the non empty matrices in order not to call the default constructor
          if (LhsShape != RhsShape )
          {
            if(not isEmpty())
            {
              changeSize(RhsShape, (*this)(0,0));
            }
            else if(not rhs.isEmpty())
            {
              changeSize(RhsShape, rhs(0,0));
            }
          }
        }

        matrixData = rhs.getMatrixData();
        return *this;
      }

      /** @brief move = operator. It moves the right hand side
       *         into the left hand size Matrix. If the sizes are
       *         different and the left hand side is static, the copy
       *         fails
       *  @param rhs  IN : Right hand side matrix
       *
       *  @return Void.
       */
      template<typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
      Matrix<TYPE, NBROWS, NBCOLS>& operator=(Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS>&& rhs)
      {
        const auto LhsShape = this->shape();
        const auto RhsShape = rhs.shape();

        // Error handling
        if ((isRowStatic and (this->getNbRows() != rhs.getNbRows())) or
            (isColStatic and (this->getNbCols() != rhs.getNbCols())))
        {
          std::ostringstream SS;
          SS << "Impossible to fit data from a matrix of size (" << rhs.getNbRows() << ", " << rhs.getNbCols() << ") into"
                " a static matrix of size (" << this->getNbRows() << ", " << this->getNbCols() << ")";
          throw std::runtime_error(SS.str());
        }

        // If both matrices are empty, we dont need to resize anything
        if(not(isEmpty() and rhs.isEmpty()))
        {
          // else, change the size only if necessary, taking a default value in one of the non empty matrices in order not to call the default constructor
          if (LhsShape != RhsShape )
          {
            if(not isEmpty())
            {
              changeSize(RhsShape, (*this)(0,0));
            }
            else if(not rhs.isEmpty())
            {
              changeSize(RhsShape, rhs(0,0));
            }
          }
        }

        matrixData = std::move(rhs.matrixData);
        return *this;
      }

      /** @brief += operator. It adds the right hand side
       *         into the left hand size Matrix. If the sizes are
       *         different the operator fails
       *
       *  @param i_NbRows  IN : New number of rows of the matrix
       *  @param o_NbCols  IN : New number of columns of the matrix
       *  @param io_Matrix IN : Matrix which size will be reduced
       *
       *  @return Void.
       */
      template<typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
      Matrix<TYPE, NBROWS, NBCOLS>& operator+=(const Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS> &rhs)
      {
        // Error handling
        if(this->isEmpty() or rhs.isEmpty())
          throw std::runtime_error("Adding empty matrices is forbidden");

        if (rhs.shape() != this->shape())
          throw std::runtime_error("Adding matrices of different shapes is forbidden");

        for(size_t i = 0; i < getNbRows()  ; i += 1)
          for(size_t j = 0 ; j < getNbCols() ; j += 1)
            matrixData(i)(j) += rhs(i,j);

        return *this;
      }


      /** @brief + operator. It adds both sides of the "+" sign
       *         and returns a static size matrix. Both sides
       *         have to be of the same shape, otherwise the
       *         operator fails.
       *
       *  @param rhs IN : Matrix, right side of the equation
       *
       *  @return Matrix<decltype(rhs(0,0) + (*this)(0,0)), NBROWS, NBCOLS, true>.
       */
      template<typename LHSTYPE, size_t LHSNBROWS, size_t LHSNBCOLS, typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
      friend auto operator+(const Matrix<LHSTYPE, LHSNBROWS, LHSNBCOLS> &lhs, const Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS> &rhs) ->
             Matrix<decltype(lhs(0,0) + rhs(0,0)), LHSNBROWS == DYNAMIC ? RHSNBROWS : DYNAMIC,
                                                   LHSNBCOLS == DYNAMIC ? RHSNBCOLS : DYNAMIC>;

      /** @brief operator* It multiplies both sides of the "*" sign
       *         and returns a static size matrix. Both sides
       *         have to have compatible sizes, (lhs.columns == rhs.cols)
       *         otherwise, the operator fails.
       *
       *  @param rhs IN : Matrix, right side of the equation
       *
       *  @return Matrix<decltype(rhs(0,0) * (*this)(0,0)), this->getNbRows(), rhs.getNbCols(), true>
       */
      template<typename LHSTYPE, size_t LHSNBROWS, size_t LHSNBCOLS, typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
      friend auto operator*(const Matrix<LHSTYPE, LHSNBROWS, LHSNBCOLS> &lhs, const Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS> &rhs) -> Matrix<decltype(rhs(0,0) * lhs(0,0)), LHSNBROWS, RHSNBCOLS>;


    private:
      /** @brief function used to change the size of the matrix
       *         This method does not require a default value,
       *         hence it is default initialized. It does not check if the matrix is static or not
       *
       *  @param i_NbRows IN : New number of rows of the matrix
       *  @param o_NbCols IN : New number of columns of the matrix
       *
       *  @return Void.
       */
      void internalChangeSize(const size_t i_NbRows, const size_t i_NbCols)
      {
        // Error handling
        if (i_NbRows <= 0 or i_NbCols <= 0)
          throw std::runtime_error("The number or rows and columns should be a positive integer");

        matrixData.resize(i_NbRows, std::vector<TYPE>(i_NbCols, TYPE()));
        for (auto& row : matrixData)
          row.resize(i_NbCols, TYPE());
      }

      /** @brief function used to change the size of the matrix
       *         This method requires a default value for filling
       *         any new row / column. It does not check if the matrix is static or not
       *
       *  @param i_NbRows     IN : New number of rows of the matrix
       *  @param o_NbCols     IN : New number of columns of the matrix
       *  @param DefaultValue IN : Default value used to fill the matrix
       *
       *  @return Void.
       */
      void internalChangeSize(const size_t i_NbRows, const size_t i_NbCols, const TYPE &DefaultValue)
      {
        // error handling
        if (i_NbRows <= 0 or i_NbCols <= 0)
          throw std::runtime_error("The number or rows and columns has to be a positive integer");

        matrixData.resize(i_NbRows, std::vector<TYPE>(i_NbCols, DefaultValue));
        for (auto& row : matrixData)
          row.resize(i_NbCols, DefaultValue);
      }
    };

  /** @brief + operator. It adds both sides of the "+" sign
   *         and returns a static size matrix. Both sides
   *         have to be of the same shape, otherwise the
   *         operator fails.
   *
   *  @param rhs IN : Matrix, right side of the equation
   *
   *  @return Matrix<decltype(rhs(0,0) + (*this)(0,0)), NBROWS, NBCOLS, true>.
   */
  template<typename LHSTYPE, size_t LHSNBROWS, size_t LHSNBCOLS, typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
    auto operator+(const Matrix<LHSTYPE, LHSNBROWS, LHSNBCOLS> &lhs, const Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS> &rhs) ->
      Matrix<decltype(lhs(0,0) + rhs(0,0)), LHSNBROWS == DYNAMIC ? RHSNBROWS : DYNAMIC,
                                            LHSNBCOLS == DYNAMIC ? RHSNBCOLS : DYNAMIC>
    {
      // Error handling
      if(lhs.isEmpty() or rhs.isEmpty())
        throw std::runtime_error("Adding empty matrices is forbidden");

      if (rhs.shape() != lhs.shape())
        throw std::runtime_error("Adding matrices of different shapes is forbidden");

      Matrix<decltype(lhs(0,0) + rhs(0,0)), LHSNBROWS == DYNAMIC ? RHSNBROWS : DYNAMIC,
                                            LHSNBCOLS == DYNAMIC ? RHSNBCOLS : DYNAMIC> newMatrix(lhs.getNbRows(), lhs.getNbCols(), lhs(0,0));

      for(size_t i = 0 ; i < rhs.getNbRows() ; i += 1)
        for(size_t j = 0 ; j < rhs.getNbCols() ; j += 1)
          newMatrix(i, j) = lhs(i,j) + rhs(i,j);

      return newMatrix;
    }

  /** @brief operator* It multiplies both sides of the "*" sign
   *         and returns a static size matrix. Both sides
   *         have to have compatible sizes, (lhs.columns == rhs.cols)
   *         otherwise, the operator fails.
   *
   *  @param rhs IN : Matrix, right side of the equation
   *
   *  @return Matrix<decltype(rhs(0,0) * (*this)(0,0)), this->getNbRows(), rhs.getNbCols(), true>
   */
  template<typename LHSTYPE, size_t LHSNBROWS, size_t LHSNBCOLS, typename RHSTYPE, size_t RHSNBROWS, size_t RHSNBCOLS>
  auto operator*(const Matrix<LHSTYPE, LHSNBROWS, LHSNBCOLS> &lhs, const Matrix<RHSTYPE, RHSNBROWS, RHSNBCOLS> &rhs) -> Matrix<decltype(rhs(0,0) * lhs(0,0)), LHSNBROWS, RHSNBCOLS>
  {
    // error handling
    if(lhs.isEmpty() or rhs.isEmpty())
      throw std::runtime_error("Multiplying empty matrices is forbidden");

    if(lhs.getNbCols() != rhs.getNbRows())
      throw std::runtime_error("The size of the matrices is incompatible with matrix multiplication");

    Matrix<decltype(rhs(0,0) * lhs(0,0)), LHSNBROWS, RHSNBCOLS> newMatrix(lhs.getNbRows(), rhs.getNbCols(), lhs(0,0));

    for(size_t i = 0 ; i < lhs.getNbRows() ; i += 1)
    {
      for(size_t j = 0 ; j < rhs.getNbCols(); j += 1)
      {
        decltype(rhs(0,0) * lhs(0,0)) sum = lhs(i,0) * rhs(0,j); // Compute the first element of the sum in order not to call the default constructor
        for(size_t k = 1 ; k < lhs.getNbRows() ; k += 1)
        {
          sum += lhs(i,k) * rhs(k,j);
        }
        newMatrix(i, j) = std::move(sum);
      }
    }
    return newMatrix;
  }

  /** @brief operator<< outputs the Matrix into a stream
   *
   *  @param i_Matrix IN  : Matrix to output
   *  @param o_OS     OUT : Stream in which the matrix must be fitted
   *
   *  @return std::ostream&
   */
  template <typename TYPE, size_t NBROWS, size_t NBCOLS>
  std::ostream& operator<<(std::ostream& o_OS, const Matrix<TYPE, NBROWS, NBCOLS>& i_Matrix)
  {
      return o_OS << i_Matrix.toString();
  }
} /* namespace Mat */

8 – Form Set Error breaks validation – Allowed memory size of xxx bytes exhausted

I’m creating a simple form :

class UserRegisterForm extends FormBase {

    /**
    * {@inheritdoc}
    */
    public function getFormId() {
    return 'user_register_form';
    }

    /**
    * {@inheritdoc}
    */
    public function buildForm(array $form, FormStateInterface $form_state) {
        ...

        return $form;
    }

    /**
    * {@inheritdoc}
    */
    public function validateForm(array &$form, FormStateInterface $form_state) {
        $form_state->setError($form, $this->t('The password must contain at least 12 characters, including 1 lowercase, 1 uppercase and 1 special character.'));
    }

    /**
    * {@inheritdoc}
    */
    public function submitForm(array &$form, FormStateInterface $form_state) {}

}

But when I use the setError() or setErrorByName() methods, I get a “Allowed memory size of XXX bytes exhausted” error when I submit the form.

The logs gives me thousands of 404 Page Not Found errors on my form page, like it was giving me an infinite loop.

Any ideas ?

gui design – Decrease the font size or break to a new line with multiple languages?

Languages that have accents in their alphabet will benefit from an increase in line-height. When you have a lot of accents they can get ‘caught’ with descenders of the glyphs above.

Second of all, some languages that are not latin based, for instance Arabic will benefit from a slightly bigger font size. This will then dictate your line-height.

Remember the so called typographic triangle where the measure (the number of characters per line) competes with the font size and it’s line-height. Plus you have to take into account the typographic hierarchy; so headers (H1-H6), paragraphs, lists etc.

Finally when you have a responsive website it gets even more complicated with device width. Smartphones will benefit from a slightly bigger font than desktop so this will feed into the measure and line height. There are lots of solutions out there, mostly SASS/SCSS based but it takes some work.

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies 5000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Buy Cheap Private Proxies; Best Quality USA Private Proxies