add some tests in permutation dir
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
BSD 2-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2023, fanasina
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ypermutation_t
|
||||||
|
|
||||||
|
Implement some functions on permutations.
|
||||||
|
|
||||||
|
Uses set theoretics.
|
||||||
|
|
||||||
|
## Bijection
|
||||||
|
Implement a bijection between an integer and a permutation (and its inverse)
|
||||||
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TEST=is_good
|
||||||
|
CC=gcc
|
||||||
|
ROOT_DIR=$(PWD)
|
||||||
|
TOOLDIR=$(PWD)/../ytools_t
|
||||||
|
|
||||||
|
INCLUDE_DIR=$(ROOT_DIR)/src
|
||||||
|
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include
|
||||||
|
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||||
|
|
||||||
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
SRC=$(wildcard **/**/*.c)
|
||||||
|
#HEADS=$(OBJS:.o=.h)
|
||||||
|
TEST_DIR=$(PWD)
|
||||||
|
EXECSRC=$(NAME_TEST).c
|
||||||
|
EXEC=launch_$(NAME_TEST)_m
|
||||||
|
PERMSRC=src/permutation_t/permutation_t.c
|
||||||
|
PERMSRC_O=$(PERMSRC:.c=.o)
|
||||||
|
SETTSRC=src/set_theoric_t/set_theoric_t.c
|
||||||
|
SETTSRC_O=$(SETTSRC:.c=.o)
|
||||||
|
TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||||
|
TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||||
|
|
||||||
|
OBJ=$(SRC:.c=.o) $(TOOLSRC_O)
|
||||||
|
|
||||||
|
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||||
|
|
||||||
|
all: $(EXEC) $(LIB_YTEST)
|
||||||
|
|
||||||
|
$(EXEC): $(EXECSRC) $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
$(PERMSRC_O): $(PERMSRC) $(SETTSRC_O)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
$(TOOLSRC_O): $(TOOLSRC)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean mrproper
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(EXEC)
|
||||||
|
|
||||||
|
run: $(EXEC)
|
||||||
|
$(EXEC) -h
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TEST=is_good
|
||||||
|
CC=gcc
|
||||||
|
ROOT_DIR=$(PWD)
|
||||||
|
YTESTDIR=$(PWD)/../../../../ytest_t
|
||||||
|
|
||||||
|
INCLUDE_DIR=$(PWD)/../../../src
|
||||||
|
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include
|
||||||
|
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||||
|
|
||||||
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
SRC=$(wildcard **/**/*.c)
|
||||||
|
#HEADS=$(OBJS:.o=.h)
|
||||||
|
TEST_DIR=$(PWD)
|
||||||
|
EXECSRC=$(NAME_TEST).c
|
||||||
|
EXEC=launch_$(NAME_TEST)_m
|
||||||
|
|
||||||
|
PERMDIR=$(PWD)/../../..
|
||||||
|
|
||||||
|
PERMSRC_O=$(PERMDIR)/src/permutation_t/permutation_t.o
|
||||||
|
|
||||||
|
TOPTARGETS := all clean
|
||||||
|
|
||||||
|
DEPS=$(PERMDIR) $(YTESTDIR)
|
||||||
|
|
||||||
|
$(TOPTARGETS): $(DEPS)
|
||||||
|
|
||||||
|
$(DEPS):
|
||||||
|
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||||
|
|
||||||
|
|
||||||
|
#PERMSRC_O=$(PERMSRC:.c=.o)
|
||||||
|
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
|
||||||
|
#SETTSRC_O=$(SETTSRC:.c=.o)
|
||||||
|
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||||
|
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||||
|
|
||||||
|
OBJ=$(SRC:.c=.o) $(PERMSRC_O)
|
||||||
|
|
||||||
|
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||||
|
|
||||||
|
all: $(EXEC) $(LIB_YTEST)
|
||||||
|
|
||||||
|
$(EXEC): $(EXECSRC) $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean mrproper
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(EXEC)
|
||||||
|
|
||||||
|
run: $(EXEC)
|
||||||
|
$(EXEC) -h
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$#" -le 0 ] ; then
|
||||||
|
echo "Usage: $0 \"compile flags or prepossession \" " >&2
|
||||||
|
echo " we can add more option for example '-D DEBUG=1' to have debug print, '-D HK' to have gtest like prompt, od '-g' to gbd" >&2
|
||||||
|
echo "for example: $0 \"-D DEBUG=1 -D HK -g\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
ddot=../..
|
||||||
|
tdot=../../..
|
||||||
|
|
||||||
|
src=$PWD/$tdot/src
|
||||||
|
|
||||||
|
ytestdir=$PWD/$ddot/$ddot/ytest_t
|
||||||
|
|
||||||
|
#echo "gcc -o launch_is_good_c $1 -L../../$src/ $2 -lytest -I../../$src/include_ytest/include $src/permutation_t/permutation_t.c $src/set_theoric_t/set_theoric_t.c -I$src "
|
||||||
|
echo "gcc -o launch_is_good_c is_good.c -L$ytestdir $1 -lytest -I$ytestdir/include_ytest/include $src/permutation_t/permutation_t.c $src/set_theoric_t/set_theoric_t.c -I$src"
|
||||||
|
gcc -o launch_is_good_c is_good.c -L$ytestdir $1 -lytest -I$ytestdir/include_ytest/include $src/permutation_t/permutation_t.c $src/set_theoric_t/set_theoric_t.c -I$src
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
objdump -d -M intel $1 > $1_intel.asm
|
||||||
|
|
||||||
|
# AT&T syntax
|
||||||
|
objdump -d $1 > $1_.asm
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// for sleep !
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ftest/ftest.h"
|
||||||
|
#include "fmock/fmock.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "permutation_t/permutation_t.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(size_permutation)
|
||||||
|
{
|
||||||
|
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, 3);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(permutation_t_float_trans)
|
||||||
|
{
|
||||||
|
int n =6;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.1;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_SIZE_T *translate_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_FLOAT(p);
|
||||||
|
|
||||||
|
size_t expect[]={0,2,1,3,4,4};
|
||||||
|
|
||||||
|
for(size_t i= 0; i<translate_p->size; ++i){
|
||||||
|
EXPECT_EQ(translate_p->perm[i], expect[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < translate_p->size; ++i) PRINTF(" ([%d] %ld) ,",i,translate_p->perm[i]);
|
||||||
|
PRINTF("\n");
|
||||||
|
for(int i = 0; i < p->size; ++i) PRINTF(" (%d: %f) ,",i,p->perm[i]);
|
||||||
|
PRINTF("\n");
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(not_permutation_)
|
||||||
|
{
|
||||||
|
int n =8;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.1;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
EXPECT_FALSE(IS_PERMUTATION_TYPE_FLOAT(p));
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(is_permutation_)
|
||||||
|
{
|
||||||
|
int n =6;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.2;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
EXPECT_TRUE(IS_PERMUTATION_TYPE_FLOAT(p));
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(){
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_CHAR *p_char = CREATE_PERMUTATION_TYPE_CHAR(6);
|
||||||
|
p_char->perm[0]='B';
|
||||||
|
p_char->perm[1]='A';
|
||||||
|
p_char->perm[2]='Y';
|
||||||
|
p_char->perm[3]='C';
|
||||||
|
p_char->perm[4]='B';
|
||||||
|
p_char->perm[5]='Z';
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_SIZE_T *tr_p_char = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_CHAR(p_char);
|
||||||
|
|
||||||
|
for(int i = 0; i < tr_p_char->size; ++i) PRINTF(" [%d ]%ld ,",i,tr_p_char->perm[i]);
|
||||||
|
PRINTF("p_char == %s\n",p_char->perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
//run_all_tests();
|
||||||
|
//run_all_tests_parallel(4);
|
||||||
|
|
||||||
|
run_all_tests_args(argc, argv);
|
||||||
|
|
||||||
|
//purge_tests();
|
||||||
|
//run_some_tests(8, 1, 2, 2, 3, 3, 0, 4, 1);
|
||||||
|
//run_some_tests(8, 5, 7, 1, 1, 1, 1, 1, 1);
|
||||||
|
//run_some_tests_one_by_one(3, 1, 2, 2);
|
||||||
|
//run_all_tests_exept(2, 1, 3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TEST=is_good
|
||||||
|
CC=gcc
|
||||||
|
ROOT_DIR=$(PWD)
|
||||||
|
INCLUDE_DIR=$(ROOT_DIR)/src
|
||||||
|
|
||||||
|
YTESTDIR=$(PWD)/../../ytest_t
|
||||||
|
|
||||||
|
CFLAGS=-I$(INCLUDE_DIR) -I../include_ytest/include
|
||||||
|
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||||
|
|
||||||
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
SRCDIR=$(PWD)/../src
|
||||||
|
#SRC=$(wildcard **/**/*.c)
|
||||||
|
#OBJ=$(SRC:.c=.o)
|
||||||
|
#HEADS=$(OBJS:.o=.h)
|
||||||
|
TEST_DIR=$(PWD)
|
||||||
|
EXECSRC=$(NAME_TEST).c
|
||||||
|
EXEC=launch_$(NAME_TEST)_m
|
||||||
|
PERMSRC=$(SRCDIR)/permutation_t/permutation_t.c
|
||||||
|
PERMSRC_O=$(PERMSRC:.c=.o)
|
||||||
|
SETTSRC=$(SRCDIR)/set_theoric_t/set_theoric_t.c
|
||||||
|
SETTSRC_O=$(SETTSRC:.c=.o)
|
||||||
|
#TOOLSRC=../ytools_t/src/tools_t/tools_t.c
|
||||||
|
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||||
|
|
||||||
|
|
||||||
|
TOOLDIR=$(PWD)/../../ytools
|
||||||
|
TOOLSRC_O=$(TOOLDIR)/src/tools_t/tools_t.o
|
||||||
|
|
||||||
|
|
||||||
|
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||||
|
|
||||||
|
DEPS=$(YTESTDIR) $(TOOLDIR)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: $(EXEC) $(LIB_YTEST)
|
||||||
|
|
||||||
|
$(EXEC): $(EXECSRC) $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
$(PERMSRC_O): $(PERMSRC) $(SETTSRC_O)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
#$(TOOLSRC_O): $(TOOLSRC)
|
||||||
|
# $(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean mrproper
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(EXEC)
|
||||||
|
|
||||||
|
run: $(EXEC)
|
||||||
|
$(EXEC) -h
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
LD_LIBRARY_PATH=../../../.. ./launch_is_good_c $1
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TEST=is_good
|
||||||
|
CC=gcc
|
||||||
|
ROOT_DIR=$(PWD)
|
||||||
|
YTESTDIR=$(PWD)/../../ytest_t
|
||||||
|
|
||||||
|
INCLUDE_DIR=$(PWD)/../src
|
||||||
|
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include
|
||||||
|
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||||
|
|
||||||
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
SRC=$(wildcard **/**/*.c)
|
||||||
|
#HEADS=$(OBJS:.o=.h)
|
||||||
|
TEST_DIR=$(PWD)
|
||||||
|
EXECSRC=$(NAME_TEST).c
|
||||||
|
EXEC=launch_$(NAME_TEST)_m
|
||||||
|
|
||||||
|
PERMDIR=$(PWD)/..
|
||||||
|
|
||||||
|
PERMSRC_O=$(PERMDIR)/src/permutation_t/permutation_t.o
|
||||||
|
|
||||||
|
TOPTARGETS := all clean
|
||||||
|
|
||||||
|
DEPS=$(PERMDIR) $(YTESTDIR)
|
||||||
|
|
||||||
|
$(TOPTARGETS): $(DEPS)
|
||||||
|
|
||||||
|
$(DEPS):
|
||||||
|
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||||
|
|
||||||
|
|
||||||
|
#PERMSRC_O=$(PERMSRC:.c=.o)
|
||||||
|
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
|
||||||
|
#SETTSRC_O=$(SETTSRC:.c=.o)
|
||||||
|
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||||
|
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||||
|
|
||||||
|
OBJ=$(SRC:.c=.o) $(PERMSRC_O)
|
||||||
|
|
||||||
|
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||||
|
|
||||||
|
all: $(EXEC) $(LIB_YTEST)
|
||||||
|
|
||||||
|
$(EXEC): $(EXECSRC) $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean mrproper
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(EXEC)
|
||||||
|
|
||||||
|
run: $(EXEC)
|
||||||
|
$(EXEC) -h
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$#" -le 0 ] ; then
|
||||||
|
echo "Usage: $0 is_good.c" >&2
|
||||||
|
echo "for example to compile: is_good.c" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "$#" -le 1 ] ; then
|
||||||
|
echo "Usage: $0 $1" >&2
|
||||||
|
echo " we can add more option for example '-D DEBUG=1' to have debug print, '-D HK' to have gtest like prompt, od '-g' to gbd" >&2
|
||||||
|
echo "for example: $0 $1 \"-D DEBUG=1 -D HK -g\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
DIR_YTEST=$PWD/../../ytest_t
|
||||||
|
SRC=../src
|
||||||
|
|
||||||
|
gcc -o launch_is_good_c $1 -L$DIR_YTEST $2 -lytest -I$DIR_YTEST/include_ytest/include $SRC/permutation_t/permutation_t.c $SRC/set_theoric_t/set_theoric_t.c -I$SRC
|
||||||
|
#gcc -o launch_is_good_c $1 $2 -lytest -I../include_ytest src/permutation_t/permutation_t.o src/set_theoric_t/set_theoric_t.o -I./src
|
||||||
|
|
||||||
|
export LD_LIBRARY_PATH=$DIR_YTEST/:LD_LIBRARY_PATH
|
||||||
|
|
||||||
|
|
||||||
|
#gcc $1 src/ftest/ftest.c src/fmock/fmock.c src/tools_t/tools_t.c src/bar_progress/bar_progress.c src/permutation_t/permutation_t.c src/set_theoric_t/set_theoric_t.c -I./include $2 -o launch_is_good_c -lpthread
|
||||||
@@ -0,0 +1,426 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// for sleep !
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ftest/ftest.h"
|
||||||
|
#include "fmock/fmock.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "permutation_t/permutation_t.h"
|
||||||
|
|
||||||
|
|
||||||
|
TEST(size_permutation)
|
||||||
|
{
|
||||||
|
PERMUTATION_TYPE_CHAR *p = CREATE_PERMUTATION_TYPE_CHAR(3);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, 3);
|
||||||
|
|
||||||
|
PRINTF("test size_permutation2\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(permutation_t_float_trans)
|
||||||
|
{
|
||||||
|
int n =8;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.1;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_SIZE_T *translate_p = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_FLOAT(p);
|
||||||
|
|
||||||
|
for(int i = 0; i < translate_p->size; ++i) PRINTF(" ([%d] %ld) ,",i,translate_p->perm[i]);
|
||||||
|
PRINTF("\n");
|
||||||
|
for(int i = 0; i < p->size; ++i) PRINTF(" (%d: %f) ,",i,p->perm[i]);
|
||||||
|
PRINTF("\n");
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(not_permutation_)
|
||||||
|
{
|
||||||
|
int n =8;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.00101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.1;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
EXPECT_FALSE(IS_PERMUTATION_TYPE_FLOAT(p));
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(is_permutation_)
|
||||||
|
{
|
||||||
|
int n =6;
|
||||||
|
PERMUTATION_TYPE_FLOAT *p = CREATE_PERMUTATION_TYPE_FLOAT(n);
|
||||||
|
|
||||||
|
PRINTF(" size = %lu \n",p->size);
|
||||||
|
EXPECT_EQ(p->size, n);
|
||||||
|
|
||||||
|
p->perm[0]=0.001;
|
||||||
|
p->perm[1]=0.01;
|
||||||
|
p->perm[2]=0.1101;
|
||||||
|
p->perm[3]=0.02;
|
||||||
|
p->perm[4]=0.2;
|
||||||
|
p->perm[5]=0.1;
|
||||||
|
|
||||||
|
EXPECT_TRUE(IS_PERMUTATION_TYPE_FLOAT(p));
|
||||||
|
|
||||||
|
|
||||||
|
// sleep(n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(float_equal){
|
||||||
|
PRINTF("another size_permutation2 float\n");
|
||||||
|
ASSERT_TRUE(true);
|
||||||
|
float a = 1.00001f;
|
||||||
|
float b = 1.00001001f;
|
||||||
|
ASSERT_EQ_TYPE_FLOAT(a,b);
|
||||||
|
b=1.0000010001f;
|
||||||
|
ASSERT_EQ_TYPE_FLOAT(1.000001000,b);
|
||||||
|
}
|
||||||
|
TEST(double_equal){
|
||||||
|
PRINTF("another size_permutation2 double\n");
|
||||||
|
ASSERT_TRUE(true);
|
||||||
|
double a = 1.00000001;
|
||||||
|
double b = 1.00000001;
|
||||||
|
ASSERT_EQ_TYPE_DOUBLE(a,b);
|
||||||
|
b=1.00000001000000001;
|
||||||
|
ASSERT_EQ_TYPE_DOUBLE(a,b);
|
||||||
|
ASSERT_EQ_TYPE_DOUBLE(1.0000000100000002,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(){
|
||||||
|
int a = 5;
|
||||||
|
long b = 5;
|
||||||
|
ASSERT_EQ(a,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(expect){
|
||||||
|
// SKIP();
|
||||||
|
SKIP("%s\n","on skip eq string");
|
||||||
|
EXPECT_EQ_TYPE_STRING("hello","hello");
|
||||||
|
float f1 = 1.00019999, f2=1.00019999;
|
||||||
|
EXPECT_EQ_TYPE_FLOAT(f1,f2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(){
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_CHAR *p_char = CREATE_PERMUTATION_TYPE_CHAR(6);
|
||||||
|
p_char->perm[0]='B';
|
||||||
|
p_char->perm[1]='A';
|
||||||
|
p_char->perm[2]='Y';
|
||||||
|
p_char->perm[3]='C';
|
||||||
|
p_char->perm[4]='D';
|
||||||
|
p_char->perm[5]='Z';
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_SIZE_T *tr_p_char = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_CHAR(p_char);
|
||||||
|
|
||||||
|
for(int i = 0; i < tr_p_char->size; ++i) PRINTF(" [%d ]%ld ,",i,tr_p_char->perm[i]);
|
||||||
|
PRINTF("p_char == %s\n",p_char->perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(){
|
||||||
|
|
||||||
|
PERMUTATION_TYPE_CHAR *p_char = CREATE_PERMUTATION_TYPE_CHAR(6);
|
||||||
|
p_char->perm[0]='B';
|
||||||
|
p_char->perm[1]='A';
|
||||||
|
p_char->perm[2]='Y';
|
||||||
|
p_char->perm[3]='C';
|
||||||
|
p_char->perm[4]='D';
|
||||||
|
p_char->perm[5]='Z';
|
||||||
|
|
||||||
|
|
||||||
|
PRINTF("init :%s \n",p_char->perm);
|
||||||
|
PERMUTATION_TYPE_SIZE_T *tab_45 = TRANSLATE_TO_SET_THEORIC_SIZE_T_TYPE_CHAR(p_char);
|
||||||
|
for(size_t i=0; i<p_char->size; ++i) PRINTF(" %ld: %ld \n",i, tab_45->perm[i]);
|
||||||
|
|
||||||
|
size_t pl = TabToPlaceAlgo_TYPE_CHAR(p_char);
|
||||||
|
//size_t pl = TabToPlaceOpt1_TYPE_CHAR(p_char);
|
||||||
|
PRINTF("sa place est :%ld \n", pl);
|
||||||
|
|
||||||
|
tab_45 = PlaceToTab_TYPE_CHAR(p_char, pl+1);
|
||||||
|
|
||||||
|
for(size_t i=0; i<p_char->size; ++i) PRINTF(" %ld: %ld \n",i, tab_45->perm[i]);
|
||||||
|
/* tab_45 = PlaceToTab_TYPE_CHAR(p_char,45);
|
||||||
|
|
||||||
|
PRINTF("ret :%s \n",p_char->perm);
|
||||||
|
for(size_t i=0; i<sz; ++i) PRINTF(" %ld: %ld \n",i, tab_45->perm[i]);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
TEST(lessThan){
|
||||||
|
long int a=1,b=2;
|
||||||
|
EXPECT_LT(a,b);
|
||||||
|
EXPECT_LT(b,a);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
TEST(sleep){sleep(2);}
|
||||||
|
TEST(sleep){sleep(2);}
|
||||||
|
TEST(sleep){sleep(2);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
TEST(sleep){sleep(1);}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f_mock, (), ())
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int,f_mock, (),false, 2) {
|
||||||
|
EXPECT_EQ_IN_MOCKF(21,21,f_mock);
|
||||||
|
EXPECT_EQ(1,3);
|
||||||
|
EXPECT_EQ(4,4);
|
||||||
|
EXPECT_EQ_IN_MOCKF(23,24,f_mock); return 12;}
|
||||||
|
EXPECT_MOCK_CALL(int,f_mock, (),1, 1) { EXPECT_EQ_IN_MOCKF(23,21,f_mock);return 10;}
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int,f_mock, (),1==2||2<1, 1) {return 18;}
|
||||||
|
EXPECT_MOCK_CALL(int,f_mock, (),1, INFINITY) {return -18;}
|
||||||
|
|
||||||
|
TEST(mockf1){
|
||||||
|
INIT_CALLER_MOCK(f_mock);
|
||||||
|
|
||||||
|
for(int i = 0; i<8; ++i){
|
||||||
|
|
||||||
|
LOG("call f_mock:%d: ret:%d\n",i,f_mock());
|
||||||
|
// int val=f_mock();
|
||||||
|
//PRINTF("call f_mock:%d: ret:%d\n",i,val);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f2_mock,(int a,int b),(a,b))
|
||||||
|
|
||||||
|
STR_PRINT_CUR_VAR(f2_mock, (int a,int b),(a,b)){
|
||||||
|
char *ret=malloc(150);
|
||||||
|
//char ret[150];
|
||||||
|
sprintf(ret,"(int)a: %d, (int)b: %d",a,b);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a<b), 3){
|
||||||
|
return a+b;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), ((a<b)&&(b<100)), 1){
|
||||||
|
return a*b;
|
||||||
|
}
|
||||||
|
|
||||||
|
WILL_MOCK_CALL(int, f2_mock, (int a,int b), (a!=b), 6){
|
||||||
|
return a/b;
|
||||||
|
}
|
||||||
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a==b), 1){
|
||||||
|
return a/b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f3_mock,(int a,int b),(a,b))
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f3_mock, (int a,int b), (a<b), 2){
|
||||||
|
return a+b;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), ((a<b)&&(b<100)), 1){
|
||||||
|
return a*b;
|
||||||
|
}
|
||||||
|
|
||||||
|
WILL_MOCK_CALL(int, f2_mock, (int a,int b), (a!=b), 6){
|
||||||
|
return a/b;
|
||||||
|
}
|
||||||
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a==b), 1){
|
||||||
|
return a/b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (1), INFINITY){
|
||||||
|
return a*b;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(f2mock_test){
|
||||||
|
INIT_CALLER_MOCK(f2_mock);
|
||||||
|
//LOG("--------------------------- > call f2_mock:%d: %d\n",0,f2_mock(1,4));
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0; i<8; ++i){
|
||||||
|
|
||||||
|
if(i<2) {
|
||||||
|
//int val = f2_mock(i,4);
|
||||||
|
//LOG("call f2_mock:%d: %d\n",i,val);
|
||||||
|
LOG("call f2_mock:%d: %d\n",i,f2_mock(i,4));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(i<4) LOG("call:%d: %d\n",i,f2_mock(i,3));
|
||||||
|
else LOG("call:%d:%d\n",i,f2_mock(i,i*i));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(f3_mock_test){
|
||||||
|
INIT_CALLER_MOCK(f3_mock);
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0; i<7; ++i){
|
||||||
|
|
||||||
|
if(i<1) {
|
||||||
|
LOG("call f3_mock:%d: %d\n",i,f3_mock(1,i));
|
||||||
|
|
||||||
|
}
|
||||||
|
else LOG("call:%d:%d\n",i,f3_mock(i,i*i));
|
||||||
|
}
|
||||||
|
for(int i=COLOR_SZ-1; i>=0; --i)
|
||||||
|
LOG("%s colors_fld\n",colors_f[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f4_mock,(int a,int b),(a,b))
|
||||||
|
STR_PRINT_CUR_VAR(f4_mock, (int a,int b),(a,b)){
|
||||||
|
char *ret=malloc(150);
|
||||||
|
//char ret[150];
|
||||||
|
sprintf(ret,"(int)a: %d, (int)b: %d",a,b);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(f4_mock_test){
|
||||||
|
//EXPECT_EQ(1,f4_mock(1,1));
|
||||||
|
PRINTF("f4 no excepted create ret: %d\n",f4_mock(1,1));
|
||||||
|
PRINTF("second call f4 : %d\n",f4_mock(2,0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f5_mock,(int a,int b, int c),(a,b,c))
|
||||||
|
|
||||||
|
TEST(f5__mock){
|
||||||
|
LOG("f5 ???:%d\n",f5_mock(1,2,3));
|
||||||
|
LOG("f5 !!!:%d\n",f5_mock(2,5,3));
|
||||||
|
}
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f6_mock,(int a,int b, int c),(a,b,c))
|
||||||
|
STR_PRINT_CUR_VAR(f6_mock,(int a,int b, int c),(a,b,c)){
|
||||||
|
char *ret=malloc(150);
|
||||||
|
sprintf(ret,"(%d,%d,%d)",a,b,c);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f6_mock,(int a, int b, int c),((a<b)&&(b<c)),1){
|
||||||
|
return a+b+c;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(f6__mock){
|
||||||
|
LOG("f6 6?:%d\n",f6_mock(1,2,3));
|
||||||
|
LOG("f6 0?:%d\n",f6_mock(2,5,4));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MOCK_FUNC(int, f7_mock,(int a,int b),(a,b))
|
||||||
|
STR_PRINT_CUR_VAR(f7_mock, (int a,int b),(a,b)){
|
||||||
|
char *ret=malloc(150);
|
||||||
|
//char ret[150];
|
||||||
|
sprintf(ret,"(int)a: %d, (int)b: %d",a,b);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_MOCK_CALL(int, f7_mock,(int a, int b),(a>b),2){
|
||||||
|
return a*b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(f7_mock_test){
|
||||||
|
int v0=f7_mock(1,1);
|
||||||
|
PRINTF("f7 ret: %d\n",v0);
|
||||||
|
int v1=f7_mock(2,0);
|
||||||
|
PRINTF("second call f7 : %d\n",v1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
|
||||||
|
//run_all_tests();
|
||||||
|
//run_all_tests_parallel(4);
|
||||||
|
|
||||||
|
run_all_tests_args(argc, argv);
|
||||||
|
|
||||||
|
//purge_tests();
|
||||||
|
//run_some_tests(8, 1, 2, 2, 3, 3, 0, 4, 1);
|
||||||
|
//run_some_tests(8, 5, 7, 1, 1, 1, 1, 1, 1);
|
||||||
|
//run_some_tests_one_by_one(3, 1, 2, 2);
|
||||||
|
//run_all_tests_exept(2, 1, 3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,652 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tens0neD/tens0neD.h"
|
||||||
|
#include "src/tensor/tens0neD/tens0neD.h"
|
||||||
|
//#include "cudatensor.h"
|
||||||
|
//#include "/home/fanasina/progr_/ptens0neD/src/tensor/tensCuda/tensCuda.h"
|
||||||
|
#include "src/tensor/tensCuda/tensCuda.h"
|
||||||
|
/*TEST(LineraCoodTransform, check_print) {
|
||||||
|
int t3[] = { [0] = 2,[1] = 4,[2] = 3 };
|
||||||
|
|
||||||
|
struct dimension D0(3, t3);
|
||||||
|
int coor0[3] = { 1,3,2 };
|
||||||
|
int* coor1 = new int[3];
|
||||||
|
|
||||||
|
int l0 = D0.CoordToLinear(coor0);
|
||||||
|
|
||||||
|
D0.print();
|
||||||
|
|
||||||
|
D0.LinearToCoord(coor1, l0);
|
||||||
|
|
||||||
|
for (int i = 0; i < D0.rank; i++) {
|
||||||
|
EXPECT_EQ(coor0[i], coor1[i]) << " coor0: " << coor0[i] << " coor1: " << coor1[i] << " i: " << i;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
TEST(subArray, concatArray) {
|
||||||
|
int t[] = { 1,5,6,2,3 };
|
||||||
|
int t0[] = { 1,5,6 };
|
||||||
|
int t1[] = { 2,3 };
|
||||||
|
int n = 5;
|
||||||
|
int s0[3];
|
||||||
|
int s1[2];
|
||||||
|
int s[n];
|
||||||
|
|
||||||
|
subArray(s0, t, 0, 3, 0);
|
||||||
|
subArray(s1, t, 0, 2, 3);
|
||||||
|
ASSERT_EQ(0, memcmp(t0, s0, sizeof(int) * 3));
|
||||||
|
ASSERT_EQ(0, memcmp(t1, s1, sizeof(int) * 2));
|
||||||
|
|
||||||
|
concatArray(s, s0, s1, 0, 0, 3, 0, 2);
|
||||||
|
ASSERT_EQ(0, memcmp(t, s, sizeof(int) * 5));
|
||||||
|
|
||||||
|
}
|
||||||
|
TEST(tensorProdpetit, floatTemp) {
|
||||||
|
|
||||||
|
/*int t3[] = { 2, 4, 3 };
|
||||||
|
|
||||||
|
int t4[] = { 2, 4, 3, 2 };*/
|
||||||
|
int t3[] = { 3, 6, 5 };
|
||||||
|
|
||||||
|
int t4[] = { 3, 5, 8, 4 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<float> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(3.0f); // M3.print();
|
||||||
|
M4.initVal(2.0f); // M4.print();
|
||||||
|
|
||||||
|
tensorProd<float>(M, M3, M4);
|
||||||
|
//tensorProd(M, M4, M3);
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
d = M.Dim;
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
for (int i = 0; i < d3.rank; i++) coord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < d4.rank; i++) coord4[i] = idx4[i];
|
||||||
|
|
||||||
|
concatArray(coord, coord3, coord4, 0, 0, d3.rank, 0, d4.rank);
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
|
||||||
|
//ASSERT_FLOAT_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
ASSERT_FLOAT_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
//ASSERT_NEAR(M.elements[lin], M3.elements[lin3] * M4.elements[lin4], 0.0001) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tensorProd, doubleTemp) {
|
||||||
|
|
||||||
|
int t3[] = { 2, 4, 3 };
|
||||||
|
|
||||||
|
int t4[] = { 4, 3, 2,3 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<double> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(3.0f); // M3.print();
|
||||||
|
M4.initVal(2.0f); // M4.print();
|
||||||
|
|
||||||
|
tensorProd(M, M3, M4);
|
||||||
|
//tensorProd(M, M4, M3);
|
||||||
|
d = M.Dim;
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
for (int i = 0; i < d3.rank; i++) coord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < d4.rank; i++) coord4[i] = idx4[i];
|
||||||
|
|
||||||
|
concatArray(coord, coord3, coord4, 0, 0, d3.rank, 0, d4.rank);
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
|
||||||
|
//ASSERT_FLOAT_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]);
|
||||||
|
ASSERT_DOUBLE_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]);
|
||||||
|
//ASSERT_NEAR(M.elements[lin], M3.elements[lin3] * M4.elements[lin4], 0.001) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void printArray(int* t, int sz) {
|
||||||
|
for (int i = 0; i < sz;i++) printf(" %d ", t[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tensorContractnProd, floatTemp) {
|
||||||
|
|
||||||
|
int t3[] = { 2, 4, 3 };
|
||||||
|
|
||||||
|
int t4[] = { 4, 3, 2, 3 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<float> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(3.0f); // M3.print();
|
||||||
|
M4.initVal(2.0f); // M4.print();
|
||||||
|
|
||||||
|
int dee = 2;
|
||||||
|
|
||||||
|
try {
|
||||||
|
//tensorContractnProd(M, M3, M4, dee);
|
||||||
|
tensorContractnProd(M, M3, M4, dee);
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument& e) {
|
||||||
|
printf("bye from test tensorContractnProd floatTemp invalid arg! deep:\n");
|
||||||
|
dimension dM;
|
||||||
|
extractDimNestingDepth(dM, d3, d4, dee);
|
||||||
|
dM.print();
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int l0, l1;
|
||||||
|
l0 = M3.Dim.rank - dee;
|
||||||
|
l1 = M4.Dim.rank - dee;
|
||||||
|
int pcoord3[l0];
|
||||||
|
int pcoord4[l1];
|
||||||
|
int r[dee];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
d = M.Dim;
|
||||||
|
d.print();
|
||||||
|
|
||||||
|
Tensor<float> Msum(d);
|
||||||
|
//for (size_t idx = 0; idx < d.size; idx++) Msum.elements[idx] = 0.0f;
|
||||||
|
|
||||||
|
//Msum.print();
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
|
||||||
|
for (int i = 0; i < l0; i++) pcoord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < l1; i++) pcoord4[i] = idx4[i + dee];
|
||||||
|
concatArray(coord, pcoord3, pcoord4, 0, 0, l0, 0, l1);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
Msum.elements[lin] = 0.0f;
|
||||||
|
//for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
//for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < dee; i++) r[i] = idx4[i];
|
||||||
|
|
||||||
|
concatArray(coord3, pcoord3, r, 0, 0, l0, 0, dee);
|
||||||
|
concatArray(coord4, r, pcoord4, 0, 0, dee, 0, l1);
|
||||||
|
//printf("[");printArray(coord3, M3.Dim.rank); printf("]["); printArray(coord4, M4.Dim.rank);printf("] =*= ("); printArray(coord, Msum.Dim.rank); printf(") |||");
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
|
||||||
|
Msum.elements[lin] += (M3.elements[lin3] * M4.elements[lin4]);
|
||||||
|
//printf("lin:%d lin3:%d lin4:%d el+:%f\n", lin, lin3, lin4, Msum.elements[lin]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(Msum.elements[lin], M.elements[lin]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tensorContractnProdD, doubleTemp) {
|
||||||
|
|
||||||
|
int t3[] = { 2, 3, 4 };
|
||||||
|
|
||||||
|
int t4[] = { 3, 4, 2, 3 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<double> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(3.0f); // M3.print();
|
||||||
|
M4.initVal(2.0f); // M4.print();
|
||||||
|
|
||||||
|
int dee = 2;
|
||||||
|
|
||||||
|
try {
|
||||||
|
//tensorContractnProd(M, M3, M4, dee);
|
||||||
|
tensorContractnProd(M, M3, M4, dee);
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument& e) {
|
||||||
|
printf("bye from test tensorContractnProd floatTemp invalid arg! deep:\n");
|
||||||
|
dimension dM;
|
||||||
|
extractDimNestingDepth(dM, d3, d4, dee);
|
||||||
|
dM.print();
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int l0, l1;
|
||||||
|
l0 = M3.Dim.rank - dee;
|
||||||
|
l1 = M4.Dim.rank - dee;
|
||||||
|
int pcoord3[l0];
|
||||||
|
int pcoord4[l1];
|
||||||
|
int r[dee];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
d = M.Dim;
|
||||||
|
d.print();
|
||||||
|
|
||||||
|
Tensor<double> Msum(d);
|
||||||
|
//for (size_t idx = 0; idx < d.size; idx++) Msum.elements[idx] = 0.0f;
|
||||||
|
|
||||||
|
//Msum.print();
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
|
||||||
|
for (int i = 0; i < l0; i++) pcoord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < l1; i++) pcoord4[i] = idx4[i + dee];
|
||||||
|
concatArray(coord, pcoord3, pcoord4, 0, 0, l0, 0, l1);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
Msum.elements[lin] = 0.0f;
|
||||||
|
//for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
//for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < dee; i++) r[i] = idx4[i];
|
||||||
|
|
||||||
|
concatArray(coord3, pcoord3, r, 0, 0, l0, 0, dee);
|
||||||
|
concatArray(coord4, r, pcoord4, 0, 0, dee, 0, l1);
|
||||||
|
//printf("[");printArray(coord3, M3.Dim.rank); printf("]["); printArray(coord4, M4.Dim.rank);printf("] =*= ("); printArray(coord, Msum.Dim.rank); printf(") |||");
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
|
||||||
|
Msum.elements[lin] += (M3.elements[lin3] * M4.elements[lin4]);
|
||||||
|
//printf("lin:%d lin3:%d lin4:%d el+:%f\n", lin, lin3, lin4, Msum.elements[lin]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_DOUBLE_EQ(Msum.elements[lin], M.elements[lin]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(reverseArray, innt) {
|
||||||
|
int n = 6;
|
||||||
|
int t4[6] = { 3, 4, 2, 3 ,5, 1 };
|
||||||
|
int revt4[6] = { 1,5,3,2, 4, 3 };
|
||||||
|
reverseArray(t4, n);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
ASSERT_EQ(t4[i], revt4[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tensorContractnReverseProd, floatTemp) {
|
||||||
|
|
||||||
|
int t3[] = { 4, 4, 3 };
|
||||||
|
|
||||||
|
int t4[] = { 3, 4, 7, 2 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<float> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(3.0f); // M3.print();
|
||||||
|
M4.initVal(2.0f); // M4.print();
|
||||||
|
|
||||||
|
int dee = 2;
|
||||||
|
|
||||||
|
try {
|
||||||
|
//tensorContractnProd(M, M3, M4, dee);
|
||||||
|
tensorContractnReverseProd(M, M3, M4, dee);
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument& e) {
|
||||||
|
printf("bye from test tensorContractnProd floatTemp invalid arg! deep:\n");
|
||||||
|
dimension dM;
|
||||||
|
extractDimNestingDepth(dM, d3, d4, dee);
|
||||||
|
dM.print();
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int l0, l1;
|
||||||
|
l0 = M3.Dim.rank - dee;
|
||||||
|
l1 = M4.Dim.rank - dee;
|
||||||
|
int pcoord3[l0];
|
||||||
|
int pcoord4[l1];
|
||||||
|
int r[dee];
|
||||||
|
int rev[dee];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
d = M.Dim;
|
||||||
|
d.print();
|
||||||
|
|
||||||
|
Tensor<float> Msum(d);
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
|
||||||
|
for (int i = 0; i < l0; i++) pcoord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < l1; i++) pcoord4[i] = idx4[i + dee];
|
||||||
|
concatArray(coord, pcoord3, pcoord4, 0, 0, l0, 0, l1);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
Msum.elements[lin] = 0.0f;
|
||||||
|
//for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
//for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < dee; i++) {
|
||||||
|
r[i] = idx4[i];
|
||||||
|
rev[i] = idx4[dee - 1 - i];
|
||||||
|
}
|
||||||
|
|
||||||
|
concatArray(coord3, pcoord3, rev, 0, 0, l0, 0, dee);
|
||||||
|
concatArray(coord4, r, pcoord4, 0, 0, dee, 0, l1);
|
||||||
|
//printf("[");printArray(coord3, M3.Dim.rank); printf("]["); printArray(coord4, M4.Dim.rank);printf("] =*= ("); printArray(coord, Msum.Dim.rank); printf(") |||");
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
|
||||||
|
Msum.elements[lin] += (M3.elements[lin3] * M4.elements[lin4]);
|
||||||
|
//printf("lin:%d lin3:%d lin4:%d el+:%f\n", lin, lin3, lin4, Msum.elements[lin]);
|
||||||
|
}
|
||||||
|
ASSERT_FLOAT_EQ(Msum.elements[lin], M.elements[lin]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(cudaTensorProd, floatTemp) {
|
||||||
|
|
||||||
|
int t3[] = { 15, 6, 24 };
|
||||||
|
|
||||||
|
int t4[] = { 23, 15, 6, 10 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<float> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(1.0f); // M3.print();
|
||||||
|
M4.initVal(0.5f); // M4.print();
|
||||||
|
|
||||||
|
cudaTensorProd(M, M3, M4);
|
||||||
|
//tensorProd(M, M4, M3);
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
d = M.Dim;
|
||||||
|
d.print();
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
for (int i = 0; i < d3.rank; i++) coord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < d4.rank; i++) coord4[i] = idx4[i];
|
||||||
|
|
||||||
|
concatArray(coord, coord3, coord4, 0, 0, d3.rank, 0, d4.rank);
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
|
||||||
|
//ASSERT_FLOAT_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
|
||||||
|
//ASSERT_FLOAT_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
ASSERT_FLOAT_EQ(M.elements[lin], M3.elements[lin3] * M4.elements[lin4]) << " M " << M.elements[lin] << " lin: " << lin << " M3: " << M3.elements[lin3] << " lin3:" << lin3 << " lin4: " << lin4 << " M4 " << M4.elements[lin4] << std::endl;
|
||||||
|
//std::cout << " M " << M.elements[lin] << " lin: " << lin << " M3: " << M3.elements[lin3] << " lin3:" << lin3 << " lin4: " << lin4 << " M4 " << M4.elements[lin4] << std::endl;
|
||||||
|
|
||||||
|
//ASSERT_NEAR(M.elements[lin], M3.elements[lin3] * M4.elements[lin4], 0.0001) << " lin: " << lin << " lin3: " << lin3 << " lin4: " << lin4;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(permuteTensor, float) {
|
||||||
|
int t4[] = { 3, 8, 2, 4 };
|
||||||
|
struct dimension d4(4, t4);
|
||||||
|
struct Tensor<float> M4(d4), M;
|
||||||
|
M4.initVal(1.0f);
|
||||||
|
permutation p(4, true);
|
||||||
|
int n = 5;
|
||||||
|
//for (int n = 0; n < 24;n++) {
|
||||||
|
PlaceToTab(p.perm, n, p.size);
|
||||||
|
printf(" %*d : ", 2, n);
|
||||||
|
for (int i = 0; i < p.size; i++)printf("(%d)%d ", i, p.perm[i]);printf("\n");
|
||||||
|
permuteTensor(M, M4, p);
|
||||||
|
//permuteTensorDef(M, M4, p);
|
||||||
|
int ind[4];
|
||||||
|
int coor[4];
|
||||||
|
size_t cM, cM4;
|
||||||
|
for (ind[0] = 0; ind[0] < M4.Dim.dim[0]; ind[0]++)
|
||||||
|
for (ind[1] = 0; ind[1] < M4.Dim.dim[1]; ind[1]++)
|
||||||
|
for (ind[2] = 0; ind[2] < M4.Dim.dim[2]; ind[2]++)
|
||||||
|
for (ind[3] = 0; ind[3] < M4.Dim.dim[3]; ind[3]++) {
|
||||||
|
p.permute(coor, ind);
|
||||||
|
cM = M.Dim.CoordToLinear(coor);
|
||||||
|
cM4 = M4.Dim.CoordToLinear(ind);
|
||||||
|
//printf("M[%ld]=%f M4[%ld]=%f \n", cM, M.elements[cM], cM4, M4.elements[cM4]);
|
||||||
|
ASSERT_FLOAT_EQ(M.elements[cM], M4.elements[cM4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(cudapermuteTensor, float) {
|
||||||
|
int t4[] = { 3, 8, 2, 4 };
|
||||||
|
struct dimension d4(4, t4);
|
||||||
|
struct Tensor<float> M4(d4), M;
|
||||||
|
M4.initVal(1.0f);
|
||||||
|
permutation p(4, true);
|
||||||
|
int n = 5;
|
||||||
|
//for (int n = 0; n < 24;n++) {
|
||||||
|
PlaceToTab(p.perm, n, p.size);
|
||||||
|
printf(" %*d : ", 2, n);
|
||||||
|
for (int i = 0; i < p.size; i++)printf("{%d}%d ", i, p.perm[i]);printf("\n");
|
||||||
|
cudapermuteTensor(M, M4, p);
|
||||||
|
//permuteTensor(M, M4, p);
|
||||||
|
//permuteTensorDef(M, M4, p);
|
||||||
|
int ind[4];
|
||||||
|
int coor[4];
|
||||||
|
size_t cM, cM4;
|
||||||
|
for (ind[0] = 0; ind[0] < M4.Dim.dim[0]; ind[0]++)
|
||||||
|
for (ind[1] = 0; ind[1] < M4.Dim.dim[1]; ind[1]++)
|
||||||
|
for (ind[2] = 0; ind[2] < M4.Dim.dim[2]; ind[2]++)
|
||||||
|
for (ind[3] = 0; ind[3] < M4.Dim.dim[3]; ind[3]++) {
|
||||||
|
p.permute(coor, ind);
|
||||||
|
cM = M.Dim.CoordToLinear(coor);
|
||||||
|
cM4 = M4.Dim.CoordToLinear(ind);
|
||||||
|
//printf("M[%ld]=%f M4[%ld]=%f \n", cM, M.elements[cM], cM4, M4.elements[cM4]);
|
||||||
|
ASSERT_FLOAT_EQ(M.elements[cM], M4.elements[cM4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(scanPermuteMatchContractTensorfromSrcToDst1, permId) {
|
||||||
|
int t[] = { 3, 8, 2, 3, 4 };
|
||||||
|
//int tm[] = { 4, 2, 7, 3 };
|
||||||
|
int tm[] = { 2, 3,4,7 };
|
||||||
|
struct dimension d(5, t);
|
||||||
|
struct dimension dm(4, tm);
|
||||||
|
struct Tensor<float> M4(d), M(dm);
|
||||||
|
M4.initVal(1.0f);
|
||||||
|
M.initVal(1.0f);
|
||||||
|
int dee = 3;
|
||||||
|
//int result[4] = { 1,3,0,2 };
|
||||||
|
int result[4] = { 0,1,2,3 };
|
||||||
|
int perm[M.Dim.rank];
|
||||||
|
ASSERT_TRUE(scanPermuteMatchContractTensorfromSrcToDst(perm, M, M4, dee));
|
||||||
|
for (int i = 0; i < M.Dim.rank; i++) printf(" %d[%d] ", i, perm[i]); printf(" first perm \n");
|
||||||
|
ASSERT_EQ(0, memcmp(result, perm, sizeof(int) * M.Dim.rank));
|
||||||
|
|
||||||
|
Tensor<float> tM;
|
||||||
|
permutation p(M.Dim.rank, perm);
|
||||||
|
permuteTensor(tM, M, p);
|
||||||
|
|
||||||
|
ASSERT_FALSE(scanPermuteMatchContractTensorfromSrcToDst(perm, M, M4, 4));
|
||||||
|
for (int i = 0; i < M.Dim.rank; i++) printf(" %d[%d] ", i, perm[i]); printf(": last perm \n");
|
||||||
|
tM.Dim.print();
|
||||||
|
int resultDim[] = { 2,3,4,7 };
|
||||||
|
ASSERT_EQ(0, memcmp(resultDim, tM.Dim.dim, sizeof(int) * tM.Dim.rank));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(scanPermuteMatchContractTensorfromSrcToDst2, floatest) {
|
||||||
|
int t[] = { 3, 8, 2, 3, 4 };
|
||||||
|
int tm[] = { 4, 2, 7, 3 };
|
||||||
|
//int tm[] = { 2, 3,4,7 };
|
||||||
|
struct dimension d(5, t);
|
||||||
|
struct dimension dm(4, tm);
|
||||||
|
struct Tensor<float> M4(d), M(dm);
|
||||||
|
M4.initVal(1.0f);
|
||||||
|
M.initVal(1.0f);
|
||||||
|
int dee = 3;
|
||||||
|
int result[4] = { 1,3,0,2 };
|
||||||
|
//int result[4] = { 0,1,2,3 };
|
||||||
|
int perm[M.Dim.rank];
|
||||||
|
ASSERT_TRUE(scanPermuteMatchContractTensorfromSrcToDst(perm, M, M4, dee));
|
||||||
|
for (int i = 0; i < M.Dim.rank; i++) printf(" %d[%d] ", i, perm[i]); printf(" first perm \n");
|
||||||
|
ASSERT_EQ(0, memcmp(result, perm, sizeof(int) * M.Dim.rank));
|
||||||
|
|
||||||
|
Tensor<float> tM;
|
||||||
|
permutation p(M.Dim.rank, perm);
|
||||||
|
permuteTensor(tM, M, p);
|
||||||
|
|
||||||
|
ASSERT_FALSE(scanPermuteMatchContractTensorfromSrcToDst(perm, M, M4, 4));
|
||||||
|
for (int i = 0; i < M.Dim.rank; i++) printf(" %d[%d] ", i, perm[i]); printf(": last perm \n");
|
||||||
|
tM.Dim.print();
|
||||||
|
int resultDim[] = { 2,3,4,7 };
|
||||||
|
ASSERT_EQ(0, memcmp(resultDim, tM.Dim.dim, sizeof(int) * tM.Dim.rank));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(cudaTensorContractNestProd, floatTemp) {
|
||||||
|
|
||||||
|
int t3[] = { 77, 8, 25 };
|
||||||
|
|
||||||
|
int t4[] = { 8, 25, 52, 144 };
|
||||||
|
struct dimension d3(3, t3), d4(4, t4), d;
|
||||||
|
|
||||||
|
struct Tensor<float> M3(d3), M4(d4), M;
|
||||||
|
M3.initVal(1.0f); // M3.print();
|
||||||
|
M4.initVal(0.0f); // M4.print();
|
||||||
|
|
||||||
|
int dee = 2;
|
||||||
|
|
||||||
|
M4.Dim.print();
|
||||||
|
|
||||||
|
try {
|
||||||
|
//tensorContractnProd(M, M3, M4, dee);
|
||||||
|
cudaTensorContractNestProd(M, M3, M4, dee);
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument& e) {
|
||||||
|
printf("bye from test tensorContractnProd floatTemp invalid arg! deep: \n");
|
||||||
|
dimension dM;
|
||||||
|
extractDimNestingDepth(dM, d3, d4, dee);
|
||||||
|
dM.print();
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int coord[M.Dim.rank];
|
||||||
|
int coord3[M3.Dim.rank];
|
||||||
|
int coord4[M4.Dim.rank];
|
||||||
|
int idx3[M3.Dim.rank];
|
||||||
|
int idx4[M4.Dim.rank];
|
||||||
|
|
||||||
|
int l0, l1;
|
||||||
|
l0 = M3.Dim.rank - dee;
|
||||||
|
l1 = M4.Dim.rank - dee;
|
||||||
|
int pcoord3[l0];
|
||||||
|
int pcoord4[l1];
|
||||||
|
int r[dee];
|
||||||
|
//int rev[dee];
|
||||||
|
|
||||||
|
int lin3, lin4, lin;
|
||||||
|
d = M.Dim;
|
||||||
|
d.print();
|
||||||
|
|
||||||
|
Tensor<float> Msum(d);
|
||||||
|
|
||||||
|
for (idx3[0] = 0; idx3[0] < d3.dim[0];idx3[0]++)
|
||||||
|
for (idx4[2] = 0; idx4[2] < d4.dim[2];idx4[2]++)
|
||||||
|
for (idx4[3] = 0; idx4[3] < d4.dim[3];idx4[3]++) {
|
||||||
|
|
||||||
|
for (int i = 0; i < l0; i++) pcoord3[i] = idx3[i];
|
||||||
|
for (int i = 0; i < l1; i++) pcoord4[i] = idx4[i + dee];
|
||||||
|
concatArray(coord, pcoord3, pcoord4, 0, 0, l0, 0, l1);
|
||||||
|
lin = d.CoordToLinear(coord);
|
||||||
|
Msum.elements[lin] = 0.0f;
|
||||||
|
//for (idx3[1] = 0; idx3[1] < d3.dim[1];idx3[1]++)
|
||||||
|
//for (idx3[2] = 0; idx3[2] < d3.dim[2]; idx3[2]++)
|
||||||
|
for (idx4[0] = 0; idx4[0] < d4.dim[0];idx4[0]++)
|
||||||
|
for (idx4[1] = 0; idx4[1] < d4.dim[1];idx4[1]++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < dee; i++) {
|
||||||
|
r[i] = idx4[i];
|
||||||
|
//rev[i] = idx4[dee - 1 - i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//concatArray(coord3, pcoord3, rev, 0, 0, l0, 0, dee);
|
||||||
|
concatArray(coord3, pcoord3, r, 0, 0, l0, 0, dee);
|
||||||
|
concatArray(coord4, r, pcoord4, 0, 0, dee, 0, l1);
|
||||||
|
//printf("[");printArray(coord3, M3.Dim.rank); printf("]["); printArray(coord4, M4.Dim.rank);printf("] =*= ("); printArray(coord, Msum.Dim.rank); printf(") |||");
|
||||||
|
lin3 = d3.CoordToLinear(coord3);
|
||||||
|
lin4 = d4.CoordToLinear(coord4);
|
||||||
|
|
||||||
|
Msum.elements[lin] += (M3.elements[lin3] * M4.elements[lin4]);
|
||||||
|
//printf("lin:%d lin3:%d lin4:%d el+:%f\n", lin, lin3, lin4, Msum.elements[lin]);
|
||||||
|
}
|
||||||
|
ASSERT_FLOAT_EQ(Msum.elements[lin], M.elements[lin]) << " lin: " << lin << " Msumelem: " << Msum.elements[lin] << " Melem: " << M.elements[lin];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NAME_TEST=is_good
|
||||||
|
CC=gcc
|
||||||
|
ROOT_DIR=$(PWD)
|
||||||
|
YTESTDIR=$(PWD)/../ytest
|
||||||
|
TOOLDIR=$(PWD)/../ytools_t
|
||||||
|
|
||||||
|
INCLUDE_DIR=$(ROOT_DIR)/src
|
||||||
|
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include
|
||||||
|
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||||
|
|
||||||
|
#SRC_DIR=$(ROOT_DIR)/src
|
||||||
|
#SRC=$(wildcard */*/*.c)
|
||||||
|
SRC=$(wildcard **/**/*.c)
|
||||||
|
#HEADS=$(OBJS:.o=.h)
|
||||||
|
TEST_DIR=$(PWD)
|
||||||
|
EXECSRC=$(NAME_TEST).c
|
||||||
|
EXEC=launch_$(NAME_TEST)_m
|
||||||
|
PERMSRC=src/permutation_t/permutation_t.c
|
||||||
|
PERMSRC_O=$(PERMSRC:.c=.o)
|
||||||
|
SETTSRC=src/set_theoric_t/set_theoric_t.c
|
||||||
|
SETTSRC_O=$(SETTSRC:.c=.o)
|
||||||
|
TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||||
|
TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||||
|
|
||||||
|
OBJ=$(SRC:.c=.o) $(TOOLSRC_O)
|
||||||
|
|
||||||
|
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||||
|
|
||||||
|
all: $(EXEC) $(LIB_YTEST)
|
||||||
|
|
||||||
|
$(EXEC): $(EXECSRC) $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
$(PERMSRC_O): $(PERMSRC) $(SETTSRC_O)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
$(TOOLSRC_O): $(TOOLSRC)
|
||||||
|
$(CC) -o $@ -c $< $(CFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean mrproper
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ)
|
||||||
|
|
||||||
|
mrproper: clean
|
||||||
|
rm -f $(EXEC)
|
||||||
|
|
||||||
|
run: $(EXEC)
|
||||||
|
$(EXEC) -h
|
||||||
Reference in New Issue
Block a user