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

◆ jacobian()

template<class Field>
SLP< Field > * SLP< Field >::jacobian ( bool makeHxH,
SLP< Field > *& slpHxH,
bool makeHxtH,
SLP< Field > *& slpHxtH )

!! assume: appending ZERO

Definition at line 612 of file NAG.cpp.

618{
619 if (rows_out != 1)
620 {
621 ERROR("1-row slp expected");
622 return nullptr;
623 };
624
626 int* end_program = program->array + program->len - num_outputs;
627
629 res->C = C;
635
636 // gc_vector<element_type> consts; // !!! use to optimize constants
638 prog.reserve(program->len);
639 for (int i = SLP_HEADER_LEN;
640 i < program->len - num_outputs - 1 /*for slpEND*/;
641 i++)
642 prog.push_back(program->array[i]);
644
646 res->cols_out); // records absolute position of output entries
647
648 for (int j = 0; j < num_outputs; j++)
649 for (int i = 0; i < num_inputs; i++)
650 out_pos[i * res->cols_out + j] =
652 num_inputs /*position of j-th output in prog*/,
653 i,
654 prog); // uses res->num_operations
655 // make program
658 res->program->array[0] = res->num_consts =
659 num_consts + 1;
660 res->program->array[1] = res->num_inputs;
661 res->program->array[2] = res->rows_out;
662 res->program->array[3] = res->cols_out;
663 prog.push_back(slpEND);
664 for (int i = 0; i < num_inputs; i++)
665 for (int j = 0; j < num_outputs; j++)
666 {
667 int t = out_pos[i * res->cols_out + j];
668 prog.push_back((t == ZERO_CONST)
669 ? num_consts /*ref to ZERO*/
670 : t + res->num_consts +
671 num_inputs); // position of the output
672 }
674 prog.data(),
675 sizeof(int) * prog.size());
676
677 // make nodes: [constants, inputs, operations]
680 // memcpy(res->nodes, nodes, num_consts*sizeof(element_type)); // old
681 // constants
682 for (int i = 0; i < num_consts; i++)
683 {
684 res->nodes[i] = nodes[i];
685 }
686
687 res->nodes[num_consts] = element_type(0, 0); // ... plus ZERO
688
689 if (makeHxH)
690 {
691 slpHxH = res->copy();
692 int* c = slpHxH->program->array + slpHxH->program->len - slpHxH->cols_out;
693 for (int j = 0; j < num_outputs; j++, c++)
695 }
696 if (makeHxtH)
697 {
698 slpHxtH = res->copy();
699 slpHxtH->rows_out++;
700 // how to kill M2_arrayint ???
702 memcpy(slpHxtH->program->array,
703 res->program->array,
704 sizeof(int) * res->program->len);
705 int* c = slpHxtH->program->array + res->program->len;
706 for (int j = 0; j < num_outputs; j++, c++)
708 }
709 return res;
710}
int rows_out
Definition NAG.hpp:502
SLP()
Definition NAG.cpp:62
int cols_out
Definition NAG.hpp:502
int num_operations
Definition NAG.hpp:502
M2_arrayint program
Definition NAG.hpp:498
SLP< Field > * copy()
Definition NAG.cpp:168
Field::element_type element_type
Definition NAG.hpp:488
int diffNodeInput(int n, int v, gc_vector< int > &prog)
Definition NAG.cpp:450
static void make_nodes(element_type *&, int size)
Definition NAG.cpp:162
int num_inputs
Definition NAG.hpp:502
element_type * nodes
Definition NAG.hpp:499
int num_consts
Definition NAG.hpp:502
gc_vector< int > node_index
Definition NAG.hpp:500
bool is_relative_position
Definition NAG.hpp:497
const CCC * C
Definition NAG.hpp:491
Definition NAG.hpp:485
const int ERROR
Definition m2-mem.cpp:55
M2_arrayint M2_makearrayint(int n)
Definition m2-types.cpp:6

References C, cols_out, copy(), diffNodeInput(), ERROR, is_relative_position, M2_makearrayint(), make_nodes(), node_index, nodes, num_consts, num_inputs, num_operations, program, rows_out, SLP(), SLP_HEADER_LEN, slpEND, and ZERO_CONST.

Referenced by StraightLineProgram::jacobian().