Re: using dot_product from c++ II
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: using dot_product from c++ II         

Group: comp.lang.fortran · Group Profile
Author: Gerry Ford
Date: Feb 19, 2008 18:39

"utab" gmail.com> wrote in message
news:d0fd7cda-8a51-419a-8509-b5f097db53cd@p73g2000hsd.googlegroups.com...
>
>> Tim Prince thought that utab's subroutine went
>> out of its way tomake something hard. I saw no source posting after
>> this
>> serious criticism.
>
> I could not get this point, could you be a bit more specific on that?
>
utab,

I never saw an update of your source that would reflect any of the forum
criticisms.

This is the latest version of my c++ program to match:

// vector3.cpp contributor: Jim Langston
#include
#include
#include
#include

double dot_product (const std::vector& vec_a, const
std::vector& vec_b)
{
if ( vec_a.size() != vec_b.size() )
{
std::cerr << "Vectors for dot product are not same size!\n";
return 0.0;
}

double sum = 0;
for ( std::size_t i = 0; i < vec_a.size(); ++i )
{
sum += vec_a[i] * vec_b[i];
}
return std::pow(sum, .5);
}

// Following prototype is not needed in this program since
// the definition is above, but would be used in another
// source file without the previous definition.
double dot_product (const std::vector& vec_a, const
std::vector& vec_b);

int main()
{
std::vector vec_a;
std::vector vec_b;

for ( int i = 0; i < 4; ++i )
{
vec_a.push_back( std::sqrt( static_cast( i )) );
vec_b.push_back( (-1.0) *i * i );
}

std::cout.precision(16);

std::copy(vec_a.begin(), vec_a.end(),
std::ostream_iterator(std::cout, "\n"));
std::copy(vec_b.begin(), vec_b.end(),
std::ostream_iterator(std::cout, "\n"));

std::cout << "Dot Product: " << dot_product(vec_a, vec_b) << "\n";
return 0;
}

// g++ -o vector3 vector3.cpp -v >text57.txt 2>text58.txt

So we have our c++ function for the dot-product. That the output needs help
to reflect a negative value is fortunate: I'll ask the friendly folks in
c.l.c++ to fix that and help me herd it into an external function as well.
I have better information from the -v switch, but it's a mixed bag, as
text58 shows:

Built by Equation Solution (http://www.Equation.com).
Using built-in specs.
Target: i386-pc-mingw32
Configured with:
../gcc-4.2.3-mingw/configure --host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu
--target=i386-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3
--with-gcc --with-gnu-ld --with-gnu-as --disable-shared --disable-nls --disable-tls
--with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr
--enable-languages=c,c++,fortran --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3
--enable-threads=win32 --enable-libgomp --disable-win32-registry
Thread model: win32
gcc version 4.2.3
c:/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/cc1plus.exe -quiet -v -iprefix
c:\gcc\bin\../lib/gcc/i386-pc-mingw32/4.2.3/ vector3.cpp -quiet -dumpbase
vector3.cpp -mtune=i386 -auxbase vector3 -version -o
C:\DOCUME~1\dan\LOCALS~1\Temp/ccSBH2Z3.s
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/include/c++/4.2.3"
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/include/c++/4.2.3/i386..."
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/include/c++/4.2.3/..."
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3/home/gfortran/gcc-h..."
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/lib/gcc/i386-pc-mingw32/4..."
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/i386-pc-mingw32/in..."
ignoring nonexistent directory
"/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:/gcc/include
c:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../include/c++/4.2.3
c:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../include/c++/4.2.3/i386-pc... c:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../include/c++/4.2.3/backwa... c:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/include c:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/includeE... of search list.GNU C++ version 4.2.3 (i386-pc-mingw32) compiled by GNU C version 4.2.3.GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=131006Compiler executable checksum: 7d1ae633d2d0a50743a002fa1f809f44 c:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/bin/as.e... -o C:\DOCUME~1\dan\LOCALS~1\Temp/ccFprGbf.oC:\DOCUME~1\dan\LOCALS~1\Temp/ccSBH2Z3.s c:/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/collect2.exe --sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3 -Bdynamic -s -ovector3.exeC:/gcc/i386-pc-mingw32/lib/crt2.o -Lc:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3 -Lc:/gcc/bin/../lib/gcc -LC:/gcc/i386-pc-mingw32/lib -Lc:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/lib -Lc:/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../..C:\DOCUME~1\dan\LOCALS~1\Temp/ccFprGbf... -lstdc++ -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt# end text58.txtYikes! My tendency would be to yell at someone who brought me somethingthat looks like this. One thing I think it shows is a drawback to havingtwo open source distros: the linker seems to be confused. It's rumored thatthe information for which libraries to include is above in order to use thisc++ prog intersyntactically. I don't see it.--Gerry Ford"Er hat sich georgiert." Der Spiegel, 2008, sich auf Chimpy Eins komma nullbeziehend.
no comments
diggit! del.icio.us! reddit!