From 4d6bafcaf594ecadfad638bca4da5e97c9cae56f Mon Sep 17 00:00:00 2001 From: David Wehr <dawehr@iastate.edu> Date: Thu, 9 Feb 2017 22:44:04 -0600 Subject: [PATCH] Fixed some minor warnings in the compiler, and linked in the math library --- quad/computation_graph/Makefile | 440 +++++++++--------- quad/computation_graph/src/main.c | 2 +- quad/computation_graph/src/node_accumulator.c | 2 +- quad/computation_graph/src/node_accumulator.h | 2 +- quad/computation_graph/src/node_add.h | 32 +- quad/computation_graph/src/node_constant.h | 30 +- quad/computation_graph/src/node_gain.h | 38 +- quad/computation_graph/src/node_mult.c | 50 +- quad/computation_graph/src/node_mult.h | 34 +- quad/computation_graph/src/node_pow.h | 38 +- 10 files changed, 334 insertions(+), 334 deletions(-) diff --git a/quad/computation_graph/Makefile b/quad/computation_graph/Makefile index bc379cc3c..dd6e7b7e2 100644 --- a/quad/computation_graph/Makefile +++ b/quad/computation_graph/Makefile @@ -1,220 +1,220 @@ -#### PROJECT SETTINGS #### -# The name of the executable to be created -BIN_NAME := computation_graph -# Compiler used -CC ?= gcc -# Extension of source files used in the project -SRC_EXT = c -# Path to the source directory, relative to the makefile -SRC_PATH = ./src -# Space-separated pkg-config libraries used by this project -LIBS = -# General compiler flags -COMPILE_FLAGS = -std=c99 -Wall -Wextra -pedantic -g -# Additional release-specific flags -RCOMPILE_FLAGS = -D NDEBUG -# Additional debug-specific flags -DCOMPILE_FLAGS = -D DEBUG -# Add additional include paths -INCLUDES = -I $(SRC_PATH) -# General linker settings -LINK_FLAGS = -# Additional release-specific linker settings -RLINK_FLAGS = -# Additional debug-specific linker settings -DLINK_FLAGS = -# Destination directory, like a jail or mounted system -DESTDIR = / -# Install path (bin/ is appended automatically) -INSTALL_PREFIX = usr/local -#### END PROJECT SETTINGS #### - -# Generally should not need to edit below this line - -# Obtains the OS type, either 'Darwin' (OS X) or 'Linux' -UNAME_S:=$(shell uname -s) - -# Function used to check variables. Use on the command line: -# make print-VARNAME -# Useful for debugging and adding features -print-%: ; @echo $*=$($*) - -# Shell used in this makefile -# bash is used for 'echo -en' -SHELL = /bin/bash -# Clear built-in rules -.SUFFIXES: -# Programs for installation -INSTALL = install -INSTALL_PROGRAM = $(INSTALL) -INSTALL_DATA = $(INSTALL) -m 644 - -# Append pkg-config specific libraries if need be -ifneq ($(LIBS),) - COMPILE_FLAGS += $(shell pkg-config --cflags $(LIBS)) - LINK_FLAGS += $(shell pkg-config --libs $(LIBS)) -endif - -# Verbose option, to output compile and link commands -export V := false -export CMD_PREFIX := @ -ifeq ($(V),true) - CMD_PREFIX := -endif - -# Combine compiler and linker flags -release: export CFLAGS := $(CFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) -release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS) -debug: export CFLAGS := $(CFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS) -debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS) - -# Build and output paths -release: export BUILD_PATH := build/release -release: export BIN_PATH := bin/release -debug: export BUILD_PATH := build/debug -debug: export BIN_PATH := bin/debug -install: export BIN_PATH := bin/release - -# Find all source files in the source directory, sorted by most -# recently modified -ifeq ($(UNAME_S),Darwin) - SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-) -else - SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' -printf '%T@\t%p\n' \ - | sort -k 1nr | cut -f2-) -endif - -# fallback in case the above fails -rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) \ - $(filter $(subst *,%,$2), $d)) -ifeq ($(SOURCES),) - SOURCES := $(call rwildcard, $(SRC_PATH), *.$(SRC_EXT)) -endif - -# Set the object file names, with the source directory stripped -# from the path, and the build path prepended in its place -OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) -# Set the dependency files that will be used to add header dependencies -DEPS = $(OBJECTS:.o=.d) - -# Macros for timing compilation -ifeq ($(UNAME_S),Darwin) - CUR_TIME = awk 'BEGIN{srand(); print srand()}' - TIME_FILE = $(dir $@).$(notdir $@)_time - START_TIME = $(CUR_TIME) > $(TIME_FILE) - END_TIME = read st < $(TIME_FILE) ; \ - $(RM) $(TIME_FILE) ; \ - st=$$((`$(CUR_TIME)` - $$st)) ; \ - echo $$st -else - TIME_FILE = $(dir $@).$(notdir $@)_time - START_TIME = date '+%s' > $(TIME_FILE) - END_TIME = read st < $(TIME_FILE) ; \ - $(RM) $(TIME_FILE) ; \ - st=$$((`date '+%s'` - $$st - 86400)) ; \ - echo `date -u -d @$$st '+%H:%M:%S'` -endif - -# Version macros -# Comment/remove this section to remove versioning -USE_VERSION := false -# If this isn't a git repo or the repo has no tags, git describe will return non-zero -ifeq ($(shell git describe > /dev/null 2>&1 ; echo $$?), 0) - USE_VERSION := true - VERSION := $(shell git describe --tags --long --dirty --always | \ - sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)-\?.*-\([0-9]*\)-\(.*\)/\1 \2 \3 \4 \5/g') - VERSION_MAJOR := $(word 1, $(VERSION)) - VERSION_MINOR := $(word 2, $(VERSION)) - VERSION_PATCH := $(word 3, $(VERSION)) - VERSION_REVISION := $(word 4, $(VERSION)) - VERSION_HASH := $(word 5, $(VERSION)) - VERSION_STRING := \ - "$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH).$(VERSION_REVISION)-$(VERSION_HASH)" - override CFLAGS := $(CFLAGS) \ - -D VERSION_MAJOR=$(VERSION_MAJOR) \ - -D VERSION_MINOR=$(VERSION_MINOR) \ - -D VERSION_PATCH=$(VERSION_PATCH) \ - -D VERSION_REVISION=$(VERSION_REVISION) \ - -D VERSION_HASH=\"$(VERSION_HASH)\" -endif - -# Standard, non-optimized release build -.PHONY: release -release: dirs -ifeq ($(USE_VERSION), true) - @echo "Beginning release build v$(VERSION_STRING)" -else - @echo "Beginning release build" -endif - @$(START_TIME) - @$(MAKE) all --no-print-directory - @echo -n "Total build time: " - @$(END_TIME) - -# Debug build for gdb debugging -.PHONY: debug -debug: dirs -ifeq ($(USE_VERSION), true) - @echo "Beginning debug build v$(VERSION_STRING)" -else - @echo "Beginning debug build" -endif - @$(START_TIME) - @$(MAKE) all --no-print-directory - @echo -n "Total build time: " - @$(END_TIME) - -# Create the directories used in the build -.PHONY: dirs -dirs: - @echo "Creating directories" - @mkdir -p $(dir $(OBJECTS)) - @mkdir -p $(BIN_PATH) - -# Installs to the set path -.PHONY: install -install: - @echo "Installing to $(DESTDIR)$(INSTALL_PREFIX)/bin" - @$(INSTALL_PROGRAM) $(BIN_PATH)/$(BIN_NAME) $(DESTDIR)$(INSTALL_PREFIX)/bin - -# Uninstalls the program -.PHONY: uninstall -uninstall: - @echo "Removing $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BIN_NAME)" - @$(RM) $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BIN_NAME) - -# Removes all build files -.PHONY: clean -clean: - @echo "Deleting $(BIN_NAME) symlink" - @$(RM) $(BIN_NAME) - @echo "Deleting directories" - @$(RM) -r build - @$(RM) -r bin - -# Main rule, checks the executable and symlinks to the output -all: $(BIN_PATH)/$(BIN_NAME) - @echo "Making symlink: $(BIN_NAME) -> $<" - @$(RM) $(BIN_NAME) - @ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME) - -# Link the executable -$(BIN_PATH)/$(BIN_NAME): $(OBJECTS) - @echo "Linking: $@" - @$(START_TIME) - $(CMD_PREFIX)$(CC) $(OBJECTS) $(LDFLAGS) -o $@ - @echo -en "\t Link time: " - @$(END_TIME) - -# Add dependency files, if they exist --include $(DEPS) - -# Source file rules -# After the first compilation they will be joined with the rules from the -# dependency files to provide header dependencies -$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) - @echo "Compiling: $< -> $@" - @$(START_TIME) - $(CMD_PREFIX)$(CC) $(CFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ - @echo -en "\t Compile time: " - @$(END_TIME) +#### PROJECT SETTINGS #### +# The name of the executable to be created +BIN_NAME := computation_graph +# Compiler used +CC ?= gcc +# Extension of source files used in the project +SRC_EXT = c +# Path to the source directory, relative to the makefile +SRC_PATH = ./src +# Space-separated pkg-config libraries used by this project +LIBS = +# General compiler flags +COMPILE_FLAGS = -std=c99 -Wall -Wextra -pedantic -g +# Additional release-specific flags +RCOMPILE_FLAGS = -D NDEBUG +# Additional debug-specific flags +DCOMPILE_FLAGS = -D DEBUG +# Add additional include paths +INCLUDES = -I $(SRC_PATH) +# General linker settings +LINK_FLAGS = -lm +# Additional release-specific linker settings +RLINK_FLAGS = +# Additional debug-specific linker settings +DLINK_FLAGS = +# Destination directory, like a jail or mounted system +DESTDIR = / +# Install path (bin/ is appended automatically) +INSTALL_PREFIX = usr/local +#### END PROJECT SETTINGS #### + +# Generally should not need to edit below this line + +# Obtains the OS type, either 'Darwin' (OS X) or 'Linux' +UNAME_S:=$(shell uname -s) + +# Function used to check variables. Use on the command line: +# make print-VARNAME +# Useful for debugging and adding features +print-%: ; @echo $*=$($*) + +# Shell used in this makefile +# bash is used for 'echo -en' +SHELL = /bin/bash +# Clear built-in rules +.SUFFIXES: +# Programs for installation +INSTALL = install +INSTALL_PROGRAM = $(INSTALL) +INSTALL_DATA = $(INSTALL) -m 644 + +# Append pkg-config specific libraries if need be +ifneq ($(LIBS),) + COMPILE_FLAGS += $(shell pkg-config --cflags $(LIBS)) + LINK_FLAGS += $(shell pkg-config --libs $(LIBS)) +endif + +# Verbose option, to output compile and link commands +export V := false +export CMD_PREFIX := @ +ifeq ($(V),true) + CMD_PREFIX := +endif + +# Combine compiler and linker flags +release: export CFLAGS := $(CFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) +release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS) +debug: export CFLAGS := $(CFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS) +debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS) + +# Build and output paths +release: export BUILD_PATH := build/release +release: export BIN_PATH := bin/release +debug: export BUILD_PATH := build/debug +debug: export BIN_PATH := bin/debug +install: export BIN_PATH := bin/release + +# Find all source files in the source directory, sorted by most +# recently modified +ifeq ($(UNAME_S),Darwin) + SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-) +else + SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' -printf '%T@\t%p\n' \ + | sort -k 1nr | cut -f2-) +endif + +# fallback in case the above fails +rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) \ + $(filter $(subst *,%,$2), $d)) +ifeq ($(SOURCES),) + SOURCES := $(call rwildcard, $(SRC_PATH), *.$(SRC_EXT)) +endif + +# Set the object file names, with the source directory stripped +# from the path, and the build path prepended in its place +OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) +# Set the dependency files that will be used to add header dependencies +DEPS = $(OBJECTS:.o=.d) + +# Macros for timing compilation +ifeq ($(UNAME_S),Darwin) + CUR_TIME = awk 'BEGIN{srand(); print srand()}' + TIME_FILE = $(dir $@).$(notdir $@)_time + START_TIME = $(CUR_TIME) > $(TIME_FILE) + END_TIME = read st < $(TIME_FILE) ; \ + $(RM) $(TIME_FILE) ; \ + st=$$((`$(CUR_TIME)` - $$st)) ; \ + echo $$st +else + TIME_FILE = $(dir $@).$(notdir $@)_time + START_TIME = date '+%s' > $(TIME_FILE) + END_TIME = read st < $(TIME_FILE) ; \ + $(RM) $(TIME_FILE) ; \ + st=$$((`date '+%s'` - $$st - 86400)) ; \ + echo `date -u -d @$$st '+%H:%M:%S'` +endif + +# Version macros +# Comment/remove this section to remove versioning +USE_VERSION := false +# If this isn't a git repo or the repo has no tags, git describe will return non-zero +ifeq ($(shell git describe > /dev/null 2>&1 ; echo $$?), 0) + USE_VERSION := true + VERSION := $(shell git describe --tags --long --dirty --always | \ + sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)-\?.*-\([0-9]*\)-\(.*\)/\1 \2 \3 \4 \5/g') + VERSION_MAJOR := $(word 1, $(VERSION)) + VERSION_MINOR := $(word 2, $(VERSION)) + VERSION_PATCH := $(word 3, $(VERSION)) + VERSION_REVISION := $(word 4, $(VERSION)) + VERSION_HASH := $(word 5, $(VERSION)) + VERSION_STRING := \ + "$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH).$(VERSION_REVISION)-$(VERSION_HASH)" + override CFLAGS := $(CFLAGS) \ + -D VERSION_MAJOR=$(VERSION_MAJOR) \ + -D VERSION_MINOR=$(VERSION_MINOR) \ + -D VERSION_PATCH=$(VERSION_PATCH) \ + -D VERSION_REVISION=$(VERSION_REVISION) \ + -D VERSION_HASH=\"$(VERSION_HASH)\" +endif + +# Standard, non-optimized release build +.PHONY: release +release: dirs +ifeq ($(USE_VERSION), true) + @echo "Beginning release build v$(VERSION_STRING)" +else + @echo "Beginning release build" +endif + @$(START_TIME) + @$(MAKE) all --no-print-directory + @echo -n "Total build time: " + @$(END_TIME) + +# Debug build for gdb debugging +.PHONY: debug +debug: dirs +ifeq ($(USE_VERSION), true) + @echo "Beginning debug build v$(VERSION_STRING)" +else + @echo "Beginning debug build" +endif + @$(START_TIME) + @$(MAKE) all --no-print-directory + @echo -n "Total build time: " + @$(END_TIME) + +# Create the directories used in the build +.PHONY: dirs +dirs: + @echo "Creating directories" + @mkdir -p $(dir $(OBJECTS)) + @mkdir -p $(BIN_PATH) + +# Installs to the set path +.PHONY: install +install: + @echo "Installing to $(DESTDIR)$(INSTALL_PREFIX)/bin" + @$(INSTALL_PROGRAM) $(BIN_PATH)/$(BIN_NAME) $(DESTDIR)$(INSTALL_PREFIX)/bin + +# Uninstalls the program +.PHONY: uninstall +uninstall: + @echo "Removing $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BIN_NAME)" + @$(RM) $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BIN_NAME) + +# Removes all build files +.PHONY: clean +clean: + @echo "Deleting $(BIN_NAME) symlink" + @$(RM) $(BIN_NAME) + @echo "Deleting directories" + @$(RM) -r build + @$(RM) -r bin + +# Main rule, checks the executable and symlinks to the output +all: $(BIN_PATH)/$(BIN_NAME) + @echo "Making symlink: $(BIN_NAME) -> $<" + @$(RM) $(BIN_NAME) + @ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME) + +# Link the executable +$(BIN_PATH)/$(BIN_NAME): $(OBJECTS) + @echo "Linking: $@" + @$(START_TIME) + $(CMD_PREFIX)$(CC) $(OBJECTS) $(LDFLAGS) -o $@ + @echo -en "\t Link time: " + @$(END_TIME) + +# Add dependency files, if they exist +-include $(DEPS) + +# Source file rules +# After the first compilation they will be joined with the rules from the +# dependency files to provide header dependencies +$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) + @echo "Compiling: $< -> $@" + @$(START_TIME) + $(CMD_PREFIX)$(CC) $(CFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ + @echo -en "\t Compile time: " + @$(END_TIME) diff --git a/quad/computation_graph/src/main.c b/quad/computation_graph/src/main.c index 2f0784f89..c54494acb 100644 --- a/quad/computation_graph/src/main.c +++ b/quad/computation_graph/src/main.c @@ -35,7 +35,7 @@ int main() { // printf("Sum is %f\n", graph_get_output(graph, mult1_id, GAIN_RESULT)); int success = graph_run_tests(); - printf("Success: %s", success == 0 ? "Yes" : "No"); + printf("Success: %s\n", success == 0 ? "Yes" : "No"); fflush(stdout); return 0; } diff --git a/quad/computation_graph/src/node_accumulator.c b/quad/computation_graph/src/node_accumulator.c index 8556ac8cc..17a36ee92 100644 --- a/quad/computation_graph/src/node_accumulator.c +++ b/quad/computation_graph/src/node_accumulator.c @@ -1,7 +1,7 @@ #include "node_accumulator.h" #include <stdlib.h> -static struct accum_state { +struct accum_state { double accumulated; }; diff --git a/quad/computation_graph/src/node_accumulator.h b/quad/computation_graph/src/node_accumulator.h index c9e04db7c..3b34220ad 100644 --- a/quad/computation_graph/src/node_accumulator.h +++ b/quad/computation_graph/src/node_accumulator.h @@ -4,7 +4,7 @@ int graph_add_node_accum(struct computation_graph *graph, const char* name); -const extern struct graph_node_type node_accum_type; +extern const struct graph_node_type node_accum_type; enum graph_node_accum_inputs { ACCUM_IN, diff --git a/quad/computation_graph/src/node_add.h b/quad/computation_graph/src/node_add.h index 5c90ea16c..ac518505f 100644 --- a/quad/computation_graph/src/node_add.h +++ b/quad/computation_graph/src/node_add.h @@ -1,17 +1,17 @@ -#ifndef __NODE_ADD_H__ -#define __NODE_ADD_H__ -#include "computation_graph.h" - -int graph_add_node_add(struct computation_graph *graph, const char* name); - -const extern struct graph_node_type node_add_type; - -enum graph_node_add_inputs { - ADD_SUMMAND1, - ADD_SUMMAND2, -}; - -enum graph_node_add_outputs { - ADD_SUM -}; +#ifndef __NODE_ADD_H__ +#define __NODE_ADD_H__ +#include "computation_graph.h" + +int graph_add_node_add(struct computation_graph *graph, const char* name); + +extern const struct graph_node_type node_add_type; + +enum graph_node_add_inputs { + ADD_SUMMAND1, + ADD_SUMMAND2, +}; + +enum graph_node_add_outputs { + ADD_SUM +}; #endif // __NODE_ADD_H__ \ No newline at end of file diff --git a/quad/computation_graph/src/node_constant.h b/quad/computation_graph/src/node_constant.h index 67acbc2d7..42463a5c5 100644 --- a/quad/computation_graph/src/node_constant.h +++ b/quad/computation_graph/src/node_constant.h @@ -1,16 +1,16 @@ -#ifndef __NODE_CONSTANT_H__ -#define __NODE_CONSTANT_H__ -#include "computation_graph.h" - -int graph_add_node_const(struct computation_graph *graph, const char* name); - -const extern struct graph_node_type node_const_type; - -enum graph_node_const_params { - CONST_SET -}; - -enum graph_node_const_outputs { - CONST_VAL -}; +#ifndef __NODE_CONSTANT_H__ +#define __NODE_CONSTANT_H__ +#include "computation_graph.h" + +int graph_add_node_const(struct computation_graph *graph, const char* name); + +extern const struct graph_node_type node_const_type; + +enum graph_node_const_params { + CONST_SET +}; + +enum graph_node_const_outputs { + CONST_VAL +}; #endif //__NODE_CONSTANT_H__ \ No newline at end of file diff --git a/quad/computation_graph/src/node_gain.h b/quad/computation_graph/src/node_gain.h index dd42d97f5..e20b9a018 100644 --- a/quad/computation_graph/src/node_gain.h +++ b/quad/computation_graph/src/node_gain.h @@ -1,20 +1,20 @@ -#ifndef __NODE_GAIN_H__ -#define __NODE_GAIN_H__ -#include "computation_graph.h" - -int graph_add_node_gain(struct computation_graph *graph, const char* name); - -const extern struct graph_node_type node_gain_type; - -enum graph_node_pow_inputs { - GAIN_INPUT -}; - -enum graph_node_pow_params { - GAIN_GAIN -}; - -enum graph_node_gain_outputs { - GAIN_RESULT -}; +#ifndef __NODE_GAIN_H__ +#define __NODE_GAIN_H__ +#include "computation_graph.h" + +int graph_add_node_gain(struct computation_graph *graph, const char* name); + +extern const struct graph_node_type node_gain_type; + +enum graph_node_pow_inputs { + GAIN_INPUT +}; + +enum graph_node_pow_params { + GAIN_GAIN +}; + +enum graph_node_gain_outputs { + GAIN_RESULT +}; #endif // __NODE_GAIN_H__ \ No newline at end of file diff --git a/quad/computation_graph/src/node_mult.c b/quad/computation_graph/src/node_mult.c index b727249f6..2696719fd 100644 --- a/quad/computation_graph/src/node_mult.c +++ b/quad/computation_graph/src/node_mult.c @@ -1,25 +1,25 @@ -#include "node_mult.h" -#include <stdlib.h> - -static void mult_nodes(void *state, const double* params, const double *inputs, double *outputs) { - outputs[MULT_PRODUCT] = inputs[MULT_MULTIPLICAND1] * inputs[MULT_MULTIPLICAND2]; -} -static void reset(void *state) {} - -static const char* const in_names[2] = {"Multiplicand 1", "Multiplicand 2"}; -static const char* const out_names[1] = {"Product"}; -static const char* const param_names[0] = {}; -const struct graph_node_type node_mult_type = { - .input_names = in_names, - .output_names = out_names, - .param_names = param_names, - .n_inputs = 2, - .n_outputs = 1, - .n_params = 0, - .execute = mult_nodes, - .reset = reset -}; - -int graph_add_node_mult(struct computation_graph *graph, const char* name) { - return graph_add_node(graph, name, &node_mult_type, NULL); -} +#include "node_mult.h" +#include <stdlib.h> + +static void mult_nodes(void *state, const double* params, const double *inputs, double *outputs) { + outputs[MULT_PRODUCT] = inputs[MULT_MULTIPLICAND1] * inputs[MULT_MULTIPLICAND2]; +} +static void reset(void *state) {} + +static const char* const in_names[2] = {"Multiplicand 1", "Multiplicand 2"}; +static const char* const out_names[1] = {"Product"}; +static const char* const param_names[0] = {}; +const struct graph_node_type node_mult_type = { + .input_names = in_names, + .output_names = out_names, + .param_names = param_names, + .n_inputs = 2, + .n_outputs = 1, + .n_params = 0, + .execute = mult_nodes, + .reset = reset +}; + +int graph_add_node_mult(struct computation_graph *graph, const char* name) { + return graph_add_node(graph, name, &node_mult_type, NULL); +} diff --git a/quad/computation_graph/src/node_mult.h b/quad/computation_graph/src/node_mult.h index 39b37cd59..49194353c 100644 --- a/quad/computation_graph/src/node_mult.h +++ b/quad/computation_graph/src/node_mult.h @@ -1,18 +1,18 @@ -#ifndef __NODE_MULT_H__ -#define __NODE_MULT_H__ -#include "computation_graph.h" - -int graph_add_node_mult(struct computation_graph *graph, const char* name); - -const extern struct graph_node_type node_mult_type; - -enum graph_node_mult_inputs { - MULT_MULTIPLICAND1, - MULT_MULTIPLICAND2, -}; - -enum graph_node_mult_outputs { - MULT_PRODUCT -}; - +#ifndef __NODE_MULT_H__ +#define __NODE_MULT_H__ +#include "computation_graph.h" + +int graph_add_node_mult(struct computation_graph *graph, const char* name); + +extern const struct graph_node_type node_mult_type; + +enum graph_node_mult_inputs { + MULT_MULTIPLICAND1, + MULT_MULTIPLICAND2, +}; + +enum graph_node_mult_outputs { + MULT_PRODUCT +}; + #endif // __NODE_MULT_H__ \ No newline at end of file diff --git a/quad/computation_graph/src/node_pow.h b/quad/computation_graph/src/node_pow.h index cfc8959e2..e817defef 100644 --- a/quad/computation_graph/src/node_pow.h +++ b/quad/computation_graph/src/node_pow.h @@ -1,20 +1,20 @@ -#ifndef __NODE_POW_H__ -#define __NODE_POW_H__ -#include "computation_graph.h" - -int graph_add_node_pow(struct computation_graph *graph, const char* name); - -const extern struct graph_node_type node_pow_type; - -enum graph_node_pow_inputs { - POW_BASE -}; - -enum graph_node_pow_params { - POW_EXP -}; - -enum graph_node_pow_outputs { - POW_RESULT -}; +#ifndef __NODE_POW_H__ +#define __NODE_POW_H__ +#include "computation_graph.h" + +int graph_add_node_pow(struct computation_graph *graph, const char* name); + +extern const struct graph_node_type node_pow_type; + +enum graph_node_pow_inputs { + POW_BASE +}; + +enum graph_node_pow_params { + POW_EXP +}; + +enum graph_node_pow_outputs { + POW_RESULT +}; #endif // __NODE_POW_H__ \ No newline at end of file -- GitLab