Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,19 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
procedure dot_product is
|
||||
type vect is array(Positive range <>) of Integer;
|
||||
v1 : vect := (1,3,-5);
|
||||
v2 : vect := (4,-2,-1);
|
||||
|
||||
function dotprod(a: vect; b: vect) return Integer is
|
||||
sum : Integer := 0;
|
||||
begin
|
||||
if not (a'Length=b'Length) then raise Constraint_Error; end if;
|
||||
for p in a'Range loop
|
||||
sum := sum + a(p)*b(p);
|
||||
end loop;
|
||||
return sum;
|
||||
end dotprod;
|
||||
|
||||
begin
|
||||
put_line(Integer'Image(dotprod(v1,v2)));
|
||||
end dot_product;
|
||||
|
|
@ -1,28 +1,46 @@
|
|||
/*****************************************************************
|
||||
* arbitrary vector length/type dot/scalar product *
|
||||
* as preprocessor macro with OpenMP SIMD and tree vectorize *
|
||||
* CFLAGS="-march=native -O3 -std=<c|gnu>23 *
|
||||
* -mfpmath=<your SIMD implementation> *
|
||||
* -ftree-vectorize -fopensmp-simd" *
|
||||
*****************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdalign.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
int dot_product(int *, int *, size_t);
|
||||
|
||||
int
|
||||
main(void)
|
||||
#define cnt(a) sizeof((a))/sizeof(typeof((a)[0]))
|
||||
#define dot(a,b,t,n,i) \
|
||||
({ \
|
||||
t dst = (t)i; \
|
||||
_Pragma("omp simd reduction(+:dst)") \
|
||||
for(size_t j = 0; j < MIN(MIN(cnt(a),cnt(b)),n); j++) \
|
||||
dst += (t)((a)[j] * (b)[j]); \
|
||||
dst; \
|
||||
})
|
||||
|
||||
/* default floating point scalar */
|
||||
typedef double flt;
|
||||
/* default dot products for length 3/4
|
||||
#define dot3(a,b) dot(a,b,flt,3,0)
|
||||
#define dot4(a,b) dot(a,b,flt,4,0)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int a[3] = {1, 3, -5};
|
||||
int b[3] = {4, -2, -1};
|
||||
flt a[3] = { 1, 3, -5};
|
||||
flt b[3] = { 4, -2, -1};
|
||||
|
||||
printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));
|
||||
/**************************************************
|
||||
* cast output to double and use "%+e" allowing *
|
||||
* homogeneous formatted indented output of any *
|
||||
* numerical scalar return type of dot. *
|
||||
**************************************************/
|
||||
printf("%+e\n", (double)dot3(a, b));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
dot_product(int *a, int *b, size_t n)
|
||||
{
|
||||
int sum = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
sum += a[i] * b[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ extension op
|
|||
= self.zipBy(array, (x,y => x * y)).summarize();
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
Console.printLine(new int[]{1, 3, -5}.dotProduct(new int[]{4, -2, -1}))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
(defun dot-product (v1 v2)
|
||||
(let ((res 0))
|
||||
(dotimes (i (length v1))
|
||||
(setq res (+ (* (elt v1 i) (elt v2 i)) res)))
|
||||
res))
|
||||
|
||||
(dot-product [1 2 3] [1 2 3]) ;=> 14
|
||||
(dot-product '(1 2 3) '(1 2 3)) ;=> 14
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
function dotprod(sequence a, sequence b)
|
||||
atom sum
|
||||
a *= b
|
||||
sum = 0
|
||||
for n = 1 to length(a) do
|
||||
sum += a[n]
|
||||
end for
|
||||
return sum
|
||||
end function
|
||||
|
||||
? dotprod({1,3,-5},{4,-2,-1})
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
-- Here is an alternative method,
|
||||
-- using the standard Euphoria Version 4+ Math Library
|
||||
include std/math.e
|
||||
sequence a = {1,3,-5}, b = {4,-2,-1} -- Make them any length you want
|
||||
? sum(a * b)
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
(defun dot-product (a b)
|
||||
(: lists foldl #'+/2 0
|
||||
(: lists zipwith #'*/2 a b)))
|
||||
(lists:foldl #'+/2 0 (lists:zipwith #'*/2 a b)))
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
sub dotprod
|
||||
{
|
||||
my($vec_a, $vec_b) = @_;
|
||||
die "they must have the same size\n" unless @$vec_a == @$vec_b;
|
||||
my $sum = 0;
|
||||
$sum += $vec_a->[$_] * $vec_b->[$_] for 0..$#$vec_a;
|
||||
return $sum;
|
||||
}
|
||||
|
||||
my @vec_a = (1,3,-5);
|
||||
my @vec_b = (4,-2,-1);
|
||||
|
||||
print dotprod(\@vec_a,\@vec_b), "\n"; # 3
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
function dotproduct( $a, $b) {
|
||||
$a | foreach -Begin {$i = $res = 0} -Process { $res += $_*$b[$i++] } -End{$res}
|
||||
}
|
||||
dotproduct (1..2) (1..2)
|
||||
dotproduct (1..10) (11..20)
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
REBOL []
|
||||
|
||||
a: [1 3 -5]
|
||||
b: [4 -2 -1]
|
||||
|
||||
dot-product: function [v1 v2] [sum] [
|
||||
if (length? v1) != (length? v2) [
|
||||
make error! "error: vector sizes must match"
|
||||
]
|
||||
sum: 0
|
||||
repeat i length? v1 [
|
||||
sum: sum + ((pick v1 i) * (pick v2 i))
|
||||
]
|
||||
]
|
||||
|
||||
dot-product a b
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
WScript.Echo DotProduct("1,3,-5","4,-2,-1")
|
||||
|
||||
Function DotProduct(vector1,vector2)
|
||||
arrv1 = Split(vector1,",")
|
||||
arrv2 = Split(vector2,",")
|
||||
If UBound(arrv1) <> UBound(arrv2) Then
|
||||
WScript.Echo "The vectors are not of the same length."
|
||||
Exit Function
|
||||
End If
|
||||
DotProduct = 0
|
||||
For i = 0 To UBound(arrv1)
|
||||
DotProduct = DotProduct + (arrv1(i) * arrv2(i))
|
||||
Next
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue