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

◆ evaluate() [2/2]

template<typename Field>
void SLP< Field >::evaluate ( int n,
const element_type * values,
element_type * out )

Definition at line 713 of file NAG.cpp.

714{
715 if (n != num_inputs) ERROR("wrong number of inputs");
716
717 element_type* out = nullptr; // used by compiledSLP
718 int out_entries_shift = 0; // position of "out matrix"
719
720 int cur_node = num_consts;
721 int i;
724
725 clock_t start_t = clock(); // clock execution time
726
727 switch (program->array[4])
728 {
729 /* obsolete !!!
730 case slpPREDICTOR:
731 out = nodes+num_consts+num_inputs;
732 predictor();
733 break;
734 case slpCORRECTOR:
735 out = nodes+num_consts+num_inputs;
736 corrector();
737 break;
738 */
739 case slpCOMPILED:
740 // evaluation via dynamically linked function
741 // input: nodes (shifted by number of consts)
742 // output: out
745 break;
746 default: // evaluation by interpretation
749 for (; program->array[i] != slpEND; cur_node++)
750 {
751 switch (program->array[i])
752 {
753 case slpCOPY:
754 nodes[cur_node] = nodes[program->array[(++i)++]];
755 break;
756 case slpMULTIsum:
757 {
758 int n_summands = program->array[i + 1];
759 nodes[cur_node] =
760 (n_summands > 0)
761 ? // create a temp var?
762 nodes[program->array[i + 2]]
763 : element_type(0, 0); // zero if empty sum
764 for (int j = 1; j < n_summands; j++)
765 nodes[cur_node] =
766 nodes[cur_node] + nodes[program->array[i + j + 2]];
767 i += n_summands + 2;
768 }
769 break;
770 case slpPRODUCT:
771 nodes[cur_node] = nodes[program->array[i + 1]] *
772 nodes[program->array[i + 2]];
773 i += 3;
774 break;
775 default:
776 ERROR("unknown SLP operation");
777 return;
778 }
779 }
780 out_entries_shift = i + 1;
781 // end: evaluation by interpretation
782 }
783
784 eval_time += clock() - start_t;
785 n_calls++;
786
787 switch (program->array[4])
788 {
789 case slpPREDICTOR:
790 case slpCOMPILED:
791 // dynamically linked
793 break;
794 default:
795 // interpretation
796 element_type* c = ret;
797 for (i = 0; i < rows_out; i++)
798 for (int j = 0; j < cols_out; j++, c++)
799 *c = nodes[program->array[i * cols_out + j + out_entries_shift]];
800 // end: interpretation
801 }
802}
void copy_complex_array(int n, const typename Field::element_type *a, typename Field::element_type *b)
Definition NAG.hpp:381
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
Definition NAG.hpp:485
const int ERROR
Definition m2-mem.cpp:55

References cols_out, compiled_fn, convert_to_absolute_position(), copy_complex_array(), ERROR, eval_time, n_calls, nodes, num_consts, num_inputs, program, rows_out, SLP_HEADER_LEN, slpCOMPILED, slpCOPY, slpEND, slpMULTIsum, slpPREDICTOR, and slpPRODUCT.

Referenced by StraightLineProgram::evaluate(), StraightLineProgram::evaluate(), and rawEvaluateSLP().