Page 1 of 1
Visual Prolog Speed
Posted: 1 Jun 2020 9:30
by CalmoSoft
Hello Thomas et All,
I want to test the speed of Visual Prolog with two dimensional array (4000x4000 items)
I want to store to indices: array(i,j) = i*j
Can you post me a sample?
Greetings,
Gal Zsolt
(~ CalmoSoft ~)
Re: Visual Prolog Speed
Posted: 1 Jun 2020 12:05
by Harrison Pratt
The "Game of Life" I posted in
Visual Prolog Tips & Samples uses a 2D matrix.
http://discuss.visual-prolog.com/viewto ... 52674c8555
Re: Visual Prolog Speed
Posted: 1 Jun 2020 12:20
by CalmoSoft
Hello Harrison,
Thanks for your useful help.
I look at it.
Greetings,
Gal Zsolt
(~ Calmosoft ~)
Re: Visual Prolog Speed
Posted: 2 Jun 2020 6:20
by CalmoSoft
Hello Harrison et All,
I need your help.
I can not write the code.
Can you help me?
Greetings,
Gal Zsolt
(~ Calmosoft ~)
Re: Visual Prolog Speed
Posted: 2 Jun 2020 12:27
by Harrison Pratt
Hi Gal,
I don't understand what you mean by "I can not write the code."
Were you able to look at the Game of Life (GOL) code?
Do you need a very simple example of using a 2D matrix?
Re: Visual Prolog Speed
Posted: 2 Jun 2020 12:56
by CalmoSoft
Hello Harrison,
Yes, I need a very simple example of using a 2D matrix.
Greetings,
Gal Zsolt
(~ CalmoSoft~)
Re: Visual Prolog Speed
Posted: 2 Jun 2020 14:10
by Harrison Pratt
Code: Select all
class predicates
demo : ().
clauses
demo() :-
% create matrix
Rows = 100,
Cols = 100,
Matrix2D = array2M::newInitialize(Rows, Cols, 0),
% insert some values
Matrix2D:set(0, 0, 11),
Matrix2D:set(0, 1, 22),
% retrieve some values
ValueA = Matrix2D:get(0, 0),
ValueB = Matrix2D:get(0, 1),
% how big?
SizeX = Matrix2D:sizeX, % note that sizeX and sizeY are properties
SizeY = Matrix2D:sizeY,
% get all non-zero values; note that keys are stored as tuples(Row,Col)
VV =
[ V ||
tuple(tuple(R, C), V) = Matrix2D:getAll_nd(),
V <> 0
].
Look at the
collection class Help file for more info.
You should run this sample code in a simple console application and use the debugger to look at the data structures that are used.
Re: Visual Prolog Speed
Posted: 2 Jun 2020 17:34
by CalmoSoft
Hello Harrison,
Thanks for your useful help.
I try to use them.
Greetings,
Gal Zsolt
(~ CalmoSoft ~)
Re: Visual Prolog Speed
Posted: 2 Jun 2020 17:45
by CalmoSoft
Hello Harrison,
I hope I have the last question.
I want to use nested loops like this in
Ring language:
array = newlist(4000,4000)
for n= 1 to 4000
for m= 1 to 4000
array[n][m] = n*m
next
next
Greetings,
Gal Zsolt
(~
CalmoSoft ~)
Re: Visual Prolog Speed
Posted: 3 Jun 2020 2:35
by Harrison Pratt
You are infinitely more expert in Ring than I am.
Re: Visual Prolog Speed
Posted: 3 Jun 2020 8:32
by Thomas Linder Puls
array2M has 0-based indices. But if you ignore the 0 indices and just make the array one larger at each dimension then you can use 1-based indices.
The initialization code can look like this:
Code: Select all
Size = 4000,
Array = array2M::new(Size + 1, Size + 1),
foreach N = std::fromTo(1, Size) do
foreach M = std::fromTo(1, Size) do
Array:set(N, M, N * M)
end foreach
end foreach
If you like you can also combine the iteration into a single foreach:
Code: Select all
Size = 4000,
Array = array2M::new(Size + 1, Size + 1),
foreach N = std::fromTo(1, Size) and M = std::fromTo(1, Size) do
Array:set(N, M, N * M)
end foreach
Re: Visual Prolog Speed
Posted: 3 Jun 2020 13:41
by CalmoSoft
Hello Thomas,
Thanks for your useful help.
I will use them.
Greetings,
Gal Zsolt
(~
CalmoSoft ~)