Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #50126 > unrolled thread

Dot product

Started byRon Aaron <rambamist@gmail.com>
First post2016-08-15 07:19 +0300
Last post2016-08-18 17:19 +0000
Articles 6 — 4 participants

Back to article view | Back to comp.lang.forth


Contents

  Dot product Ron Aaron <rambamist@gmail.com> - 2016-08-15 07:19 +0300
    Re: Dot product lawrencedo99@gmail.com - 2016-08-14 21:57 -0700
      Re: Dot product Ron Aaron <rambamist@gmail.com> - 2016-08-15 08:33 +0300
    Re: Dot product lehs <skydda.barnen@gmail.com> - 2016-08-14 23:43 -0700
      Re: Dot product Ron Aaron <rambamist@gmail.com> - 2016-08-15 10:01 +0300
    Re: Dot product "WJ" <w_a_x_man@yahoo.com> - 2016-08-18 17:19 +0000

#50126 — Dot product

FromRon Aaron <rambamist@gmail.com>
Date2016-08-15 07:19 +0300
SubjectDot product
Message-ID<norft6$sva$1@dont-email.me>
From RosettaCode:

http://8th-dev.com/forum/index.php/topic,1050.0.html

[1,3,-5] [4,-2,1] ' n:* ' n:+ a:dot . cr

outputs 3

The a:dot word is a generalized dot-product of two similarly-sized
arrays.  So it can do a great deal more than a simple math dot-product.

[toc] | [next] | [standalone]


#50127

Fromlawrencedo99@gmail.com
Date2016-08-14 21:57 -0700
Message-ID<e34b433e-2b57-4ab6-93a1-3797692fb760@googlegroups.com>
In reply to#50126
On Monday, August 15, 2016 at 4:19:51 PM UTC+12, Ron Aaron wrote:
> The a:dot word is a generalized dot-product of two similarly-sized
> arrays.  So it can do a great deal more than a simple math dot-product.

Does it work on general tensors?

[toc] | [prev] | [next] | [standalone]


#50128

FromRon Aaron <rambamist@gmail.com>
Date2016-08-15 08:33 +0300
Message-ID<nork7h$6k5$1@dont-email.me>
In reply to#50127

On 08/15/2016 07:57, lawrencedo99@gmail.com wrote:
> On Monday, August 15, 2016 at 4:19:51 PM UTC+12, Ron Aaron wrote:
>> The a:dot word is a generalized dot-product of two similarly-sized
>> arrays.  So it can do a great deal more than a simple math dot-product.
> 
> Does it work on general tensors?
> 

It works on arrays.  An array can contain any other data type; tensors
are not built-in, but you can create them if you want.

[toc] | [prev] | [next] | [standalone]


#50130

Fromlehs <skydda.barnen@gmail.com>
Date2016-08-14 23:43 -0700
Message-ID<2906a9e9-5e8b-4563-92ec-034f8dcc3de1@googlegroups.com>
In reply to#50126
Den måndag 15 augusti 2016 kl. 06:19:51 UTC+2 skrev Ron Aaron:
> From RosettaCode:
> 
> http://8th-dev.com/forum/index.php/topic,1050.0.html
> 
> [1,3,-5] [4,-2,1] ' n:* ' n:+ a:dot . cr
> 
> outputs 3
> 
> The a:dot word is a generalized dot-product of two similarly-sized
> arrays.  So it can do a great deal more than a simple math dot-product.

isn't the dot product of [1,3,-5] and [4,-2,1] =1*4+3*(-2)+(-5)*1=-7?

[toc] | [prev] | [next] | [standalone]


#50131

FromRon Aaron <rambamist@gmail.com>
Date2016-08-15 10:01 +0300
Message-ID<norpch$igv$1@dont-email.me>
In reply to#50130

On 08/15/2016 09:43, lehs wrote:
> Den måndag 15 augusti 2016 kl. 06:19:51 UTC+2 skrev Ron Aaron:
>> From RosettaCode:
>>
>> http://8th-dev.com/forum/index.php/topic,1050.0.html
>>
>> [1,3,-5] [4,-2,1] ' n:* ' n:+ a:dot . cr
>>
>> outputs 3
>>
>> The a:dot word is a generalized dot-product of two similarly-sized
>> arrays.  So it can do a great deal more than a simple math dot-product.
> 
> isn't the dot product of [1,3,-5] and [4,-2,1] =1*4+3*(-2)+(-5)*1=-7?
> 

Yes.  The last '1' s/b a '-1'.  Sorry :o

[toc] | [prev] | [next] | [standalone]


#50215

From"WJ" <w_a_x_man@yahoo.com>
Date2016-08-18 17:19 +0000
Message-ID<np4qm3$8cn$1@dont-email.me>
In reply to#50126
Ron Aaron wrote:

> From RosettaCode:
> 
> http://8th-dev.com/forum/index.php/topic,1050.0.html
> 
> [1,3,-5] [4,-2,1] ' n:* ' n:+ a:dot . cr
> 
> outputs 3
> 
> The a:dot word is a generalized dot-product of two similarly-sized
> arrays.  So it can do a great deal more than a simple math dot-product.

OCaml:

let dot_prod v w mul add =
  let result = ref   (mul v.(0) w.(0))   in
  for i = 1 to (Array.length v) - 1 do
    result := add !result (mul v.(i) w.(i))
  done ;
  !result ;;


dot_prod [|1; 3;-5|] [|4;-2;-1|] ( * ) (+) ;;
 ===>
3

dot_prod [|1.; 3.; -5.|] [|4.; -2.; -1.|] ( *. ) (+.) ;;
 ===>
3.

dot_prod
  [|"foo"; "cross"; "helter"|]
  [|"bar"; "criss"; "skelter"|]
  (fun a b -> List.sort compare [a;b] |> String.concat "-")
  (Printf.sprintf "%s; %s") ;;
 ===>
"bar-foo; criss-cross; helter-skelter"


-- 
Goyim were born only to serve us....  They will work, they will plow, they will
reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef
web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782
archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web