Sha256: 7672d8d8f71836f7a9e08417557936f737f2759b2c4ce06528bceb43f970a949

Contents?: true

Size: 1.53 KB

Versions: 22

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby
# Turn on warnings
$-w = true

# This script is written by Cameron McBride.
# Thank you Cameron!

#gem 'gsl', '=1.10.3'
require 'irb/xmp'
require 'gsl'
puts "Using rb-gsl #{GSL::RB_GSL_VERSION}"

# Seed random number generator for repeatable results
srand(?r-?b+?g-?s-?l)

# The creation of the test Vector below can be replaced with any of these lines
# to show the behavior with GSL::Block, GSL::Vector::Int, and
# GSL::Vector::Int::Block.  Note that the block objects should NOT be created
# using "v = GSL::Vector[0..9].block" because the Vector object will be subject
# to garbage collection which will free the memory that the Block object points
# to.  See the BUGS file for more information.
#
# vv = GSL::Vector[0..9]; v = vv.block
# v = GSL::Vector::Int[0..9]
# vv = GSL::Vector::Int[0..9]; v = vv.block

# Apparently, IRB::Frame has a bug that prevents the defaults from working, so
# an XMP instance must be created explicitly this way instead of using the
# otherwise convenient xmp method.
XMP.new(IRB::Frame.top(-1)).puts <<END
# Create test Vector v
v = GSL::Vector[0..9]

# Create mask
mask = (v > 2)

# Show mask.where with no block
mask.where

# Show mask.where with "true" block
mask.where { true }

# Show mask.where with "false" block
# NB: Returns nil, not empty object!
mask.where { false }

# Show mask.where with no block
mask.where2

# Show mask.where with "true" block
mask.where2 { true  }

# Show mask.where with "false" block
mask.where2 { false }

# Show mask.where with random block
mask.where2 { rand > 0.5 }
END

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
gsl-2.1.0.3 examples/vector/test_gslblock.rb
gsl-2.1.0.2 examples/vector/test_gslblock.rb
gsl-2.1.0.1 examples/vector/test_gslblock.rb
gsl-2.1.0 examples/vector/test_gslblock.rb
gsl-1.16.0.6 examples/vector/test_gslblock.rb
rb-gsl-1.16.0.5 examples/vector/test_gslblock.rb
rb-gsl-1.16.0.4 examples/vector/test_gslblock.rb
rb-gsl-1.16.0.3 examples/vector/test_gslblock.rb
rb-gsl-1.16.0.3.rc1 examples/vector/test_gslblock.rb
gsl-nmatrix-1.15.3.2 examples/vector/test_gslblock.rb
gsl-nmatrix-1.15.3.1 examples/vector/test_gslblock.rb
rb-gsl-1.16.0.2 examples/vector/test_gslblock.rb
rb-gsl-1.16.0.1 examples/vector/test_gslblock.rb
rb-gsl-1.16.0 examples/vector/test_gslblock.rb
rb-gsl-1.15.3.2 examples/vector/test_gslblock.rb
rb-gsl-1.15.3.1 examples/vector/test_gslblock.rb
blackwinter-gsl-1.15.3.2 examples/vector/test_gslblock.rb
gsl-nmatrix-1.15.3.0 examples/vector/test_gslblock.rb
gsl-1.15.3 examples/vector/test_gslblock.rb
gsl-1.14.7 examples/vector/test_gslblock.rb