Macaulay2 Engine
Loading...
Searching...
No Matches

◆ evaluate() [1/2]

template<class Field>
Matrix * SLP< Field >::evaluate ( const Matrix * vals)

Definition at line 805 of file NAG.cpp.

806{
807 element_type* out = nullptr; // used by compiledSLP
808 int out_entries_shift = 0; // position of "out matrix" in slp->program
809
810 int cur_node = num_consts;
811 int i;
812 if (values->n_cols() != num_inputs)
813 ERROR("different number of inputs expected");
814 for (i = 0; i < num_inputs; i++, cur_node++)
816
817 clock_t start_t = clock(); // clock execution time
818
819 switch (program->array[4])
820 {
821 case slpCOMPILED:
822 // evaluation via dynamically linked function
823 // input: nodes (shifted by number of consts)
824 // output: out
827 break;
828 default: // evaluation by interpretation
831 for (; program->array[i] != slpEND; cur_node++)
832 {
833 switch (program->array[i])
834 {
835 case slpCOPY:
836 nodes[cur_node] = nodes[program->array[(++i)++]];
837 break;
838 case slpMULTIsum:
839 {
840 int n_summands = program->array[i + 1];
841 nodes[cur_node] =
842 (n_summands > 0)
843 ? // create a temp var?
844 nodes[program->array[i + 2]]
845 : element_type(0, 0); // zero if empty sum
846 for (int j = 1; j < n_summands; j++)
847 nodes[cur_node] =
848 nodes[cur_node] + nodes[program->array[i + j + 2]];
849 i += n_summands + 2;
850 }
851 break;
852 case slpPRODUCT:
853 nodes[cur_node] = nodes[program->array[i + 1]] *
854 nodes[program->array[i + 2]];
855 i += 3;
856 break;
857 default:
858 ERROR("unknown SLP operation");
859 return nullptr;
860 }
861 }
862 out_entries_shift = i + 1;
863 // end: evaluation by interpretation
864 }
865
866 eval_time += clock() - start_t;
867 n_calls++;
868
869 const CCC* R = cast_to_CCC(values->get_ring());
870 // CCC* R = CCC::create(53); //values->get_ring();
871 FreeModule* S = R->make_FreeModule(cols_out);
872 FreeModule* T = R->make_FreeModule(rows_out);
874 mpfr_t re, im;
875 mpfr_init(re);
876 mpfr_init(im);
877 switch (program->array[4])
878 {
879 case slpPREDICTOR:
880 case slpCORRECTOR:
881 case slpCOMPILED:
882 {
883 // printf("predictor output: %d by %d\n", rows_out, cols_out);
884 element_type* c = out;
885 for (i = 0; i < rows_out; i++)
886 for (int j = 0; j < cols_out; j++, c++)
887 {
888 // printf("%lf %lf \n", c->getreal(), c->getimaginary());
889 ring_elem e = from_doubles(R, c->getreal(), c->getimaginary());
890
891 mat.set_entry(i, j, e);
892 }
893 }
894 break;
895 default: // interpretation
896 for (i = 0; i < rows_out; i++)
897 for (int j = 0; j < cols_out; j++)
898 {
900 nodes[program->array[i * cols_out + j + out_entries_shift]];
901
902 ring_elem e = from_doubles(R, c.getreal(), c.getimaginary());
903
904 mat.set_entry(i, j, e);
905 }
906 // end: interpretation
907 }
908 mpfr_clear(re);
909 mpfr_clear(im);
910 return mat.to_matrix();
911}
gmp_CC toBigComplex(const CCC *C, ring_elem a)
Definition NAG.hpp:210
ring_elem from_doubles(const CCC *C, double re, double im)
Definition NAG.hpp:201
const CCC * cast_to_CCC(const Ring *R)
Definition NAG.hpp:196
int rows_out
Definition NAG.hpp:502
void convert_to_absolute_position()
Definition NAG.cpp:914
int cols_out
Definition NAG.hpp:502
clock_t eval_time
Definition NAG.hpp:506
M2_arrayint program
Definition NAG.hpp:498
Field::element_type element_type
Definition NAG.hpp:488
int n_calls
Definition NAG.hpp:507
int num_inputs
Definition NAG.hpp:502
element_type * nodes
Definition NAG.hpp:499
void(* compiled_fn)(element_type *, element_type *)
Definition NAG.hpp:505
int num_consts
Definition NAG.hpp:502
const CCC * C
Definition NAG.hpp:491
Definition NAG.hpp:485
const int ERROR
Definition m2-mem.cpp:55

References C, cast_to_CCC(), CCC, cols_out, compiled_fn, convert_to_absolute_position(), Matrix::elem(), ERROR, eval_time, from_doubles(), Matrix::get_ring(), Ring::make_FreeModule(), Matrix, n_calls, Matrix::n_cols(), nodes, num_consts, num_inputs, program, FreeModule::R, rows_out, MatrixConstructor::set_entry(), SLP_HEADER_LEN, slpCOMPILED, slpCOPY, slpCORRECTOR, slpEND, slpMULTIsum, slpPREDICTOR, slpPRODUCT, T, MatrixConstructor::to_matrix(), and toBigComplex().