<commit_before>/* Copyright (c) FFLAS-FFPACK
* Written by  

* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK is free software: you can redistribute it and/or modify
* it under the terms of the  GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
* ========LICENCE========
*/



/*    ====================================
      |    FFLAS Crash Course Level 1    |
      ====================================

The puspose of this file is to be able to handle the first level
of the linear algebra over finite fields used in fflas.
In this example the finite field will be the Z over 101 Z set.
This set is created using the givaro library.
There had to be a choice between having a clean file and a clean display.
The clean display has been adopted therefore the reader is invited
to pay attention to what lines are used for display and what lines
actually do the work.

 */

// For information on the inclusions check the file 101-fflas.C
#include <fflas-ffpack/fflas/fflas.h>
#include <givaro/modular.h>
#include <givaro/modular-balanced.h>
#include <iostream>

using namespace FFLAS;


void disp_101_string(const char * text)
{
  std::cout << text  << std::endl;
}
void disp_101_vector(const Givaro::Modular<float> F,
	      const char * name,
	      const Givaro::Modular<float>::Element_ptr M,
	      const size_t size,
	      const bool   bracket_display
	      )
{
  write_field(F, std::cout << name <<":=", M, size, 1, 1,bracket_display) << std::endl;
}


int main(int argc, char** argv) {
  std::cout << "" << std::endl;
  
  typedef Givaro::Modular<float> Float_Ring;
  Float_Ring F(120);
  Float_Ring::Element alpha,beta;  // scalars
  Float_Ring::Element_ptr X, Y, Z; // vectors
  const size_t xsize = 2, ysize = 2 , zsize = 2, one = 1, ld = 1;
  
  X = fflas_new(F,xsize,one);
  Y = fflas_new(F,ysize,one);
  Z = fflas_new(F,zsize,one);

  // ===== manual initialisation =====
  
  F.init(*(X+0),  52);               // X[0] = 52
  F.init(  X[1], 183);               // X[1] = 63

  disp_101_string("\nInitialisation");
  disp_101_vector(F,"X",X,xsize,true);
  disp_101_vector(F,"Y",Y,ysize,true);
  

  // ===== initialisation from a vector ===== ???
  /*  finit(F,2,Y,1,X,1);

  write_field(F, std::cout << "X:=", X, 2, 1, 1,true) << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, one,true) << std::endl;
  */

  // ===== modular reduction =====
  disp_101_string("\n=== Modular reductions ===");
  
  typedef Givaro::Modular<float> Ring;
  Ring F2(2);
  freduce(F2,2,Y,1);      // reduce Y modulo F2 inplace

  disp_101_string("\nY mod 2 inplace");
  disp_101_vector(F,"Y", Y, ysize, true);

  freduce(F2,2,X,1,Y,1);  // reduce X modulo F2 and store in Y
  
  disp_101_string("\nY := X mod 2");
  disp_101_vector(F,"Y", Y, ysize, true);


  // ===== negation =====
  fnegin(F,2,X,1);        // X := -X
  fneg(F,2,X,1,Y,1);      // Y := -X

  disp_101_string("\n=== Negations ===");
  disp_101_string("\nX := -X");
  disp_101_vector(F, "X", X, xsize, true);
  disp_101_string("\nY := -X");
  disp_101_vector(F, "Y", Y, ysize, true);
  

  // ===== addition / substraction =====
  // both of these exist inplace with the suffix "in"
  F.init(X[0],3); F.init(X[1],4);       // X := (3;4)
  F.init(Y[0],2); F.assign(Y[1],F.one); // Y := (2;1)

  std::cout << "\n=== Additions / Substractions ===" << std::endl;
  write_field(F, std::cout << "X:=", X, xsize, one, ld,true) << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, ld,true) << std::endl;
  write_field(F, std::cout << "Z:=", Z, zsize, one, ld,true) << std::endl;

  fadd(F,2,X,1,Y,1,Z,1);  // Z := X + Y
  fsub(F,2,Z,1,Y,1,X,1);  // X := Z - Y

  std::cout << "\nZ := X + Y"  << std::endl;
  write_field(F, std::cout << "Z:=", Z, zsize, one, ld,true) << std::endl;
  std::cout << "\nX := Z - Y"  << std::endl;
  write_field(F, std::cout << "X:=", X, xsize, one, ld,true) << std::endl;

  // ===== scalar times vector =====
  F.init(alpha,42); // the scalar is scalar with respect to F<commit_msg>Went back to display with std::cout <<  ... << std::endl;<commit_after>/* Copyright (c) FFLAS-FFPACK
* Written by  

* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK is free software: you can redistribute it and/or modify
* it under the terms of the  GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
* ========LICENCE========
*/



/*    ====================================
      |    FFLAS Crash Course Level 1    |
      ====================================

The puspose of this file is to be able to handle the first level
of the linear algebra over finite fields used in fflas.
In this example the finite field will be the Z over 101 Z set.
This set is created using the givaro library.
There had to be a choice between having a clean file and a clean display.
The clean display has been adopted therefore the reader is invited
to pay attention to what lines are used for display and what lines
actually do the work.

 */

// For information on the inclusions check the file 101-fflas.C
#include <fflas-ffpack/fflas/fflas.h>
#include <givaro/modular.h>
#include <givaro/modular-balanced.h>
#include <iostream>

using namespace FFLAS;

int main(int argc, char** argv) {
  std::cout << "" << std::endl;
  
  typedef Givaro::Modular<float> Float_Ring;
  Float_Ring F(120);
  Float_Ring::Element alpha,beta;  // scalars
  Float_Ring::Element_ptr X, Y, Z; // vectors
  const size_t xsize = 2, ysize = 2 , zsize = 2, one = 1, ld = 1;
  
  X = fflas_new(F,xsize,one);
  Y = fflas_new(F,ysize,one);
  Z = fflas_new(F,zsize,one);

  // ===== manual initialisation =====
  
  F.init(*(X+0),  52);               // X[0] = 52
  F.init(  X[1], 183);               // X[1] = 63

  std::cout <<"\nInitialisation" << std::endl;
  write_field(F, std::cout << "X:=", X, xsize, one, ld,true) << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, ld,true) << std::endl;

  // ===== initialisation from a vector ===== ???
  /*  finit(F,2,Y,1,X,1);

      write_field(F, std::cout << "X:=", X, 2, 1, 1,true) << std::endl;
      write_field(F, std::cout << "Y:=", Y, ysize, one, one,true) << std::endl;
  */

  // ===== modular reduction =====
  std::cout << "\n=== Modular reductions ===" << std::endl;
  
  typedef Givaro::Modular<float> Ring;
  Ring F2(2);
  freduce(F2,2,Y,1);      // reduce Y modulo F2 inplace

  std::cout << "\nY mod 2 inplace" << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, ld,true) << std::endl;

  freduce(F2,2,X,1,Y,1);  // reduce X modulo F2 and store in Y
  
  std::cout << "\nY := X mod 2" << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, ld,true) << std::endl;


  // ===== negation =====
  fnegin(F,2,X,1);        // X := -X
  fneg(F,2,X,1,Y,1);      // Y := -X

  std::cout << "\n=== Negations ===" << std::endl;
  std::cout << "\nX := -X" << std::endl;
  write_field(F, std::cout << "X:=", X, xsize, one, ld,true) << std::endl;
  std::cout << "\nY := -X" << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, ld,true) << std::endl;
  

  // ===== addition / substraction =====
  // both of these exist inplace with the suffix "in"
  F.init(X[0],3); F.init(X[1],4);       // X := (3;4)
  F.init(Y[0],2); F.assign(Y[1],F.one); // Y := (2;1)

  std::cout << "\n=== Additions / Substractions ===" << std::endl;
  write_field(F, std::cout << "X:=", X, xsize, one, ld,true) << std::endl;
  write_field(F, std::cout << "Y:=", Y, ysize, one, ld,true) << std::endl;
  write_field(F, std::cout << "Z:=", Z, zsize, one, ld,true) << std::endl;

  fadd(F,2,X,1,Y,1,Z,1);  // Z := X + Y
  fsub(F,2,Z,1,Y,1,X,1);  // X := Z - Y

  std::cout << "\nZ := X + Y"  << std::endl;
  write_field(F, std::cout << "Z:=", Z, zsize, one, ld,true) << std::endl;
  std::cout << "\nX := Z - Y"  << std::endl;
  write_field(F, std::cout << "X:=", X, xsize, one, ld,true) << std::endl;

  // ===== scalar times vector =====
  F.init(alpha,42); // the scalar is scalar with respect to F
{'fraction_non_alphanumeric': 0.19849492856363835, 'fraction_numerical': 0.023884829316174066, 'mean_word_length': 3.4950980392156863, 'pattern_counts': {'":': 1, '<': 171, '<?xml version=': 0, '>': 17, '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': '3595005', 'n_tokens_mistral': 3520, 'n_tokens_neox': 3311, 'n_words': 1030}