Skip to content

Commit

Permalink
Math: added new block for relational operations of two inputs
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
  • Loading branch information
michallenc committed Jun 9, 2021
1 parent e03acf4 commit 5c7c491
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
53 changes: 53 additions & 0 deletions CodeGen/Common/common_dev/nonlinear.c
Expand Up @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

#include <pyblock.h>
#include <math.h>
#include <string.h>

void absV(int Flag, python_block *block)
{
Expand Down Expand Up @@ -155,4 +156,56 @@ void trigo(int Flag, python_block *block)
break;
}
}

void rel(int Flag, python_block *block)
{
double *y;
double *in1 = block->u[0];
double *in2 = block->u[1];
int u1 = (int) in1[0];
int u2 = (int) in2[0];

y = (double *) block->y[0];

switch(Flag){
case CG_OUT:
case CG_INIT:
case CG_END:
if (strcmp(block->str, "==") == 0)
{
if (u1 == u2) y[0] = 1;
else y[0] = 0;
}
else if((strcmp(block->str, "!=") == 0))
{
if (u1 != u2) y[0] = 1;
else y[0] = 0;
}
else if((strcmp(block->str, ">=") == 0))
{
if (u1 >= u2) y[0] = 1;
else y[0] = 0;
}
else if((strcmp(block->str, "<=") == 0))
{
if (u1 <= u2) y[0] = 1;
else y[0] = 0;
}
else if((strcmp(block->str, ">") == 0))
{
if (u1 > u2) y[0] = 1;
else y[0] = 0;
}
else if((strcmp(block->str, "<") == 0))
{
if (u1 < u2) y[0] = 1;
else y[0] = 0;
}
else
{
y[0] = 0;
}
default:
break;
}
}
13 changes: 13 additions & 0 deletions resources/blocks/Icons/REL.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/blocks/blocks/Math/Rel.xblk
@@ -0,0 +1 @@
{"lib": "math", "name": "Relation Operator", "ip": 2, "op": 1, "stin": 0, "stout": 0, "icon": "REL", "params": "relBlk|operator: '=='"}
26 changes: 26 additions & 0 deletions resources/blocks/rcpBlk/Math/relBlk.py
@@ -0,0 +1,26 @@
from supsisim.RCPblk import RCPblk
from scipy import size

def relBlk(pin, pout, operator):
"""
Call: relBlk(pin, pout)
Parameters
----------
pin: connected input ports
pout: connected output port
operator: math operations to do
Returns
-------
blk : RCPblk
"""

if(size(pout) != 1):
raise ValueError("Block should have 1 output port; received %i." % size(pout))

blk = RCPblk('rel',pin,pout,[0,0],1,[],[], operator)
return blk

9 changes: 9 additions & 0 deletions resources/blocks/rcpBlk/help/relBlk.hlp
@@ -0,0 +1,9 @@
This block performs relational operation on two inputs

Supported operations:
'==' inputs are equal
'!=' inputs are not equal
'>=' input 1 is greater than or equal to input 2
'<=' input 1 is less than or equal to input 2
'>' input 1 is greater than input 2
'<' input 1 is less than input 2

0 comments on commit 5c7c491

Please sign in to comment.