File: SLP.cpp

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (79 lines) | stat: -rw-r--r-- 2,414 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2015 Anton Leykin and Mike Stillman

#include "SLP.hpp"

// SLProgram
SLProgram::SLProgram()
{
  // std::cerr << "in SLProgram::SLProgram" << std::endl;
  inputCounter = 0;
}

SLProgram::~SLProgram()
{
  // std::cerr << "~SLProgram" << std::endl;
}

SLProgram::GATE_POSITION SLProgram::addMSum(const M2_arrayint a)
{
  mNodes.push_back(MSum);
  mNumInputs.push_back(a->len);
  for (int i = 0; i < a->len; i++)
    mInputPositions.push_back(a->array[i] -
                              static_cast<GATE_POSITION>(mNodes.size()) + 1);
  return static_cast<GATE_POSITION>(mNodes.size()) - 1;
}
SLProgram::GATE_POSITION SLProgram::addMProduct(const M2_arrayint a)
{
  mNodes.push_back(MProduct);
  mNumInputs.push_back(a->len);
  for (int i = 0; i < a->len; i++)
    mInputPositions.push_back(a->array[i] -
                              static_cast<GATE_POSITION>(mNodes.size()) + 1);
  return static_cast<GATE_POSITION>(mNodes.size()) - 1;
}
SLProgram::GATE_POSITION SLProgram::addDet(const M2_arrayint a)
{
  mNodes.push_back(Det);
  mNumInputs.push_back(a->len);
  for (int i = 0; i < a->len; i++)
    mInputPositions.push_back(a->array[i] -
                              static_cast<GATE_POSITION>(mNodes.size()) + 1);
  return static_cast<GATE_POSITION>(mNodes.size()) - 1;
}
SLProgram::GATE_POSITION SLProgram::addDivide(const M2_arrayint a)
{
  mNodes.push_back(Divide);
  if (a->len != 2) ERROR("Divide expected two arguments");
  for (int i = 0; i < 2; i++)
    mInputPositions.push_back(a->array[i] -
                              static_cast<GATE_POSITION>(mNodes.size()) + 1);
  return static_cast<GATE_POSITION>(mNodes.size()) - 1;
}
void SLProgram::setOutputPositions(const M2_arrayint a)
{
  for (int i = 0; i < a->len; i++)
    {
      int p = a->array[i];
      if (p < 0 && -p > inputCounter)
        ERROR("input or constant position out of range");
      else if (p >= 0 && p >= mNodes.size())
        ERROR("node position out of range");
      else
        mOutputPositions.push_back(p);
    }
}

void SLProgram::text_out(buffer& o) const
{
  o << "SLProgram (" << newline;
  o << "  consts+vars: " << inputCounter << newline;
  o << "  noninput nodes: " << mNodes.size() << newline;
  o << "  output nodes: " << mOutputPositions.size() << newline;
  o << "  )" << newline;
}

// Local Variables:
// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
// indent-tabs-mode: nil
// End: