Page 1 of 1

### Visual Prolog Speed

Posted: 1 Jun 2020 9:30
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
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
Hello Harrison,

I look at it.

Greetings,
Gal Zsolt
(~ Calmosoft ~)

### Re: Visual Prolog Speed

Posted: 2 Jun 2020 6:20
Hello Harrison et All,

I can not write the code.
Can you help me?

Greetings,
Gal Zsolt
(~ Calmosoft ~)

### Re: Visual Prolog Speed

Posted: 2 Jun 2020 12:27
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
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

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
].``````

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
Hello Harrison,

I try to use them.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)

### Re: Visual Prolog Speed

Posted: 2 Jun 2020 17:45
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
You are infinitely more expert in Ring than I am.

### Re: Visual Prolog Speed

Posted: 3 Jun 2020 8:32
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
Hello Thomas,