Generate Array?

For general discussion related FlowStone
Post Reply
User avatar
guyman
Posts: 207
Joined: Fri Mar 02, 2018 8:27 pm

Generate Array?

Post by guyman »

Ok last question for the day.
What's the best way to generate/calculate an array from scratch, in consistent relation to a function from last entry, or the index # ?
so just..
Designating # of x bins...
entering function (ie x=x+3... or x=index ..or x=index*2+3/4^179)

I'm going for pretty big arrays.....
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Generate Array?

Post by RJHollins »

Hi Guy ...

not sure exactly what your looking for ... but posted sometime back, TROG had put together a package of modules called 'TROGS TOOLZ'.

In the 'Auto Numbering folder is an AutoFunction Generator that can generate a variety of Arrays and functions.

not sure if this the latest ... but maybe can help:
Attachments
trogz_toolz_v3_1.fsm
(226.42 KiB) Downloaded 896 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Generate Array?

Post by tulamide »

guyman wrote:What's the best way to generate/calculate an array from scratch, in consistent relation to a function from last entry, or the index # ?

If you know the size of the array beforehand, the best way is to use its built in method #new:

Code: Select all

my_array = Array.new(20) { |index| index*2+3/4^179 }
## creates an array with 20 entries calculated from the code block {}


if you don't know the size beforehand you have to append to an existing array, for example:

Code: Select all

my_array = []
index = 0
my_array << index*2+3/4^179


This will make you happy: https://ruby-doc.org/core-1.9.3/index.html
"There lies the dog buried" (German saying translated literally)
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Generate Array?

Post by martinvicanek »

Some options for array creation are: :mrgreen:
Attachments
buildArray3.png
buildArray3.png (16.95 KiB) Viewed 14022 times
This one will probably upset tula ...
This one will probably upset tula ...
buildArray2.png (10.82 KiB) Viewed 14022 times
buildArray1.png
buildArray1.png (16.6 KiB) Viewed 14022 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Generate Array?

Post by tulamide »

martinvicanek wrote:...
It does, Martin, it does. But for a good reason. It's not "the best" way as asked, it's the worst way, because it's not the Ruby way. A for loop is one of the worst methods, especially when doing large arrays, as the op said.

But the other methods impress me! I would never had thought about using ASM, that's amazing!
"There lies the dog buried" (German saying translated literally)
User avatar
wlangfor@uoguelph.ca
Posts: 912
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada
Contact:

Re: Generate Array?

Post by wlangfor@uoguelph.ca »

i like to build an array, as long as you're sure the index number is accurate there really is no drawback unlike javascript or php.
My youtube channel: DSPplug
My Websites: www.dspplug.com KVRaudio flowstone products
Post Reply