Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-27 Thread RecentConvert
It works! Thanks for the help and patience. 


Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-27 Thread RecentConvert
Not sure how it's suppose to go. As I understood it from the constructors 
documentation 
*new* was how it was done, not return.


Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-27 Thread Tim Holy
On Thursday, March 27, 2014 07:41:34 AM RecentConvert wrote:
> Not sure how it's suppose to go. As I understood it from the constructors
> documentation
> *new* was how it was done, not return.

Meaning, the point is that your print("Test 3") prevents the function from 
returning anything:

function f(x)
val = 2x
println("This will not return anything")
end

function g(x)
val = 2x
println("This will return something")
val
end



Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-27 Thread Tim Holy
Status isn't returning the value created by new.
--Tim

On Thursday, March 27, 2014 05:45:08 AM RecentConvert wrote:
> It turns out the error wasn't in the code I posted but how it was then
> implemented though I still am not sure what is wrong.
> 
> This code works.
> type Status AutoBG::Vector{Bool}
>  AutoCal::Vector{Bool}
>  FrequencyLock::Vector{Bool}
>  BinomialFilter::Vector{Bool}
>  AltMode::Vector{Bool}
>  GuessLast::Vector{Bool}
>  PowerNorm::Vector{Bool}
>  ContRefLock::Vector{Bool}
> 
>  AutoSpectSave::Vector{Bool}
>  PressureLock::Vector{Bool}
>  #b11::Vector{Bool}
>  #b12::Vector{Bool}
>  WriteData::Vector{Bool}
>  RS232::Vector{Bool}
>  ElectronicBGSub::Vector{Bool}
>  #b16::Vector{Bool}
> 
>  Valve1::Vector{Bool}
>  Valve2::Vector{Bool}
>  Valve3::Vector{Bool}
>  Valve4::Vector{Bool}
>  Valve5::Vector{Bool}
>  Valve6::Vector{Bool}
>  Valve7::Vector{Bool}
>  Valve8::Vector{Bool}
> 
>  # Constructor for Status type
>  function Status(vals::Array{Int64})
>  l = int64(length(vals))
> 
>  AutoBG = Array(Bool,l)
>  AutoCal = Array(Bool,l)
>  FrequencyLock = Array(Bool,l)
>  BinomialFilter = Array(Bool,l)
>  AltMode = Array(Bool,l)
>  GuessLast = Array(Bool,l)
>  PowerNorm = Array(Bool,l)
>  ContRefLock = Array(Bool,l)
> 
>  AutoSpectSave = Array(Bool,l)
>  PressureLock = Array(Bool,l)
>  #b11 = Array(Bool,l)
>  #b12 = Array(Bool,l)
>  WriteData = Array(Bool,l)
>  RS232 = Array(Bool,l)
>  ElectronicBGSub = Array(Bool,l)
>  #b16 = Array(Bool,l)
> 
>  Valve1 = Array(Bool,l)
>  Valve2 = Array(Bool,l)
>  Valve3 = Array(Bool,l)
>  Valve4 = Array(Bool,l)
>  Valve5 = Array(Bool,l)
>  Valve6 = Array(Bool,l)
>  Valve7 = Array(Bool,l)
>  Valve8 = Array(Bool,l)
> 
>  # Parse Inputs
>  for i=1:l
>  # Byte 1
>  AutoBG[i] = vals[i] & 2^(1-1) > 0
>  AutoCal[i] = vals[i] & 2^(2-1) > 0
>  FrequencyLock[i] = vals[i] & 2^(3-1) > 0
>  BinomialFilter[i] = vals[i] & 2^(4-1) > 0
>  AltMode[i] = vals[i] & 2^(5-1) > 0
>  GuessLast[i] = vals[i] & 2^(6-1) > 0
>  PowerNorm[i] = vals[i] & 2^(7-1) > 0
>  ContRefLock[i] = vals[i] & 2^(8-1) > 0
> 
>  # Byte 2
>  AutoSpectSave[i] = vals[i] & 2^(9-1) > 0
>  PressureLock[i] = vals[i] & 2^(10-1) > 0
>  #b11[i] = vals[i] & 2^(11-1) > 0
>  #b12[i] = vals[i] & 2^(12-1) > 0
>  WriteData[i] = vals[i] & 2^(13-1) > 0
>  RS232[i] = vals[i] & 2^(14-1) > 0
>  ElectronicBGSub[i] = vals[i] & 2^(15-1) > 0
>  #b16[i] = vals[i] & 2^(16-1) > 0
> 
>  # Byte 3
>  Valve1[i] = vals[i] & 2^(17-1) > 0
>  Valve2[i] = vals[i] & 2^(18-1) > 0
>  Valve3[i] = vals[i] & 2^(19-1) > 0
>  Valve4[i] = vals[i] & 2^(20-1) > 0
>  Valve5[i] = vals[i] & 2^(21-1) > 0
>  Valve6[i] = vals[i] & 2^(22-1) > 0
>  Valve7[i] = vals[i] & 2^(23-1) > 0
>  Valve8[i] = vals[i] & 2^(24-1) > 0
>  end # End of conversion
>  println("AutoBG Length: " * string(length(AutoBG)))
> 
> #new(AutoBG,AutoCal,FrequencyLock,BinomialFilter,AltMode,GuessLast,PowerNorm
> ,ContRefLock,AutoSpectSave,PressureLock,b11,b12,WriteData,RS232,ElectronicBG
> Sub,b16,Valve1_temp,Valve2_temp,Valve3_temp,Valve4_temp,Valve5_temp,Valve6_t
> emp,Valve7_temp,Valve8_temp)
> new(AutoBG,AutoCal,FrequencyLock,BinomialFilter,AltMode,GuessLast,PowerNorm
> ,ContRefLock,AutoSpectSave,PressureLock,WriteData,RS232,ElectronicBGSub,
> Valve1,Valve2,Valve3,Valve4,Valve5,Valve6,Valve7,Valve8)
>  end # End of constructor
>  end # End of type
> 
> 
>  y = [1:10]
>  x = Status(y)
> 
> 
>  # Properties
>  println("Type: " * string(typeof(x)))
>  println(x.AutoBG)
> 
> I'm trying to build a module for functions related to an instrument we have
> and the Status type was placed in there. The module looks like this.
>  module Aerodyne
> 
>  export Status, aerodyne
> 
>  type Status
>  AutoBG::Vector{Bool}
>  AutoCal::Vector{Bool}
>  FrequencyLock::Vector{Bool}
>  BinomialFilter::Vector{Bool}
>  AltMode::Vector{Bool}
>  GuessLast::Vector{Bool}
>  PowerNorm::Vector{Bool}
>  ContRefLock::Vector{Bool}
> 
>  AutoSpectSave::Vector{Bool}
>  PressureLock::Vector{Bool}
>  #b11::Vector{Bool}
>  #b12::Vector{Bool}
>  WriteData::Vector{Bool}
>  RS232::Vector{Bool}
>  ElectronicBGSub::Vector{Bool}
>  #b16::Vector{Bool}
> 
>  Valve1::Vector{Bool}
>  Valve2::Vector{Bool}
>  Valve3::Vector{Bool}
>  Valve4::Vector{Bool}
>  Valve5::Vector{Bool}
>  Valve6::Vector{Bool}
>  Valve7::Vector{Bool}
>  Valve8::Vector{Bool}
> 
>  # Constructor for Status type
>  function Status(vals::Array{Int64})
>  l = int64(length(vals))
> 
>  AutoBG = Array(Bool,l)
>  AutoCal = Array(Bool,l)
>  FrequencyLock = Array(Bool,l)
>  BinomialFilter = Array(Bool,l)
>  AltMode = Array(Bool,l)
>  GuessLast = Array(Bool,l)
>  PowerNorm = Array(Bool,l)
>  ContRefLock = Array(Bool,l)
> 
>  AutoSpectSave = Array(Bool,l)
>  PressureLock = Array(Bool,l)
>  #b11 = Array(Bool,l)
>  #b12 = Array(Bool,l)
>  WriteData = Array(Bool,l)
> 

Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread Tim Holy
I get

julia> x.Valve1
12-element Array{Bool,1}:
  true
 false
  true
 false
  true
 false
  true
 false
  true
 false
  true
 false

I even went to the trouble to build Julia 0.2.1 and test it there, too; same 
result. So I can't replicate your problem. (I'm on Linux.)

How are you getting Julia? Building it yourself? Binary download? Anyway, it 
sounds like you want to try a different way of getting Julia.

--Tim

On Monday, March 24, 2014 07:18:42 AM RecentConvert wrote:
> The updated code works the same with Status([1:12]) as it does with
> vector(Dstc["StatusW"]).
> 
> type Status
>Valve1::Vector{Bool}
>Valve2::Vector{Bool}
>Valve3::Vector{Bool}
>Valve4::Vector{Bool}
>Valve5::Vector{Bool}
>Valve6::Vector{Bool}
>Valve7::Vector{Bool}
>Valve8::Vector{Bool}
> 
># Constructor for Status type
>function Status(vals::Array{Int64})
>l = int64(length(vals))
> 
>Valve1 = Array(Bool,l)
>Valve2 = Array(Bool,l)
>Valve3 = Array(Bool,l)
>Valve4 = Array(Bool,l)
>Valve5 = Array(Bool,l)
>Valve6 = Array(Bool,l)
>Valve7 = Array(Bool,l)
>Valve8 = Array(Bool,l)
> 
># Parse Inputs
>for i=1:l
>   # Byte 1
>   Valve1[i] = vals[i] & 2^(1-1) > 0
>   Valve2[i] = vals[i] & 2^(2-1) > 0
>   Valve3[i] = vals[i] & 2^(3-1) > 0
>   Valve4[i] = vals[i] & 2^(4-1) > 0
>   Valve5[i] = vals[i] & 2^(5-1) > 0
>   Valve6[i] = vals[i] & 2^(6-1) > 0
>   Valve7[i] = vals[i] & 2^(7-1) > 0
>   Valve8[i] = vals[i] & 2^(8-1) > 0
>end # End of conversion
> 
> 
>new(Valve1,Valve2,Valve3,Valve4,Valve5,Valve6,Valve7,Valve8)
> 
> 
>end # End of constructor
> end # End of type
> 
> statuses = Status(vector(Dstc["StatusW"]))
> julia> typeof(statuses) Nothing (constructor with 1 method)
> 
> julia> statuses.Valve1 ErrorException("type Nothing has no field Valve1")
> 
> 
> 
> julia> x = Status([1:12])
> 
> julia> typeof(x) Nothing (constructor with 1 method)
> 
> julia> x.Valve1 ErrorException("type Nothing has no field Valve1")


Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread RecentConvert
The updated code works the same with Status([1:12]) as it does with 
vector(Dstc["StatusW"]).

type Status
   Valve1::Vector{Bool}
   Valve2::Vector{Bool}
   Valve3::Vector{Bool}
   Valve4::Vector{Bool}
   Valve5::Vector{Bool}
   Valve6::Vector{Bool}
   Valve7::Vector{Bool}
   Valve8::Vector{Bool}
 
   # Constructor for Status type
   function Status(vals::Array{Int64})
   l = int64(length(vals))
 
   Valve1 = Array(Bool,l)
   Valve2 = Array(Bool,l)
   Valve3 = Array(Bool,l)
   Valve4 = Array(Bool,l)
   Valve5 = Array(Bool,l)
   Valve6 = Array(Bool,l)
   Valve7 = Array(Bool,l)
   Valve8 = Array(Bool,l)
 
   # Parse Inputs
   for i=1:l
  # Byte 1
  Valve1[i] = vals[i] & 2^(1-1) > 0
  Valve2[i] = vals[i] & 2^(2-1) > 0
  Valve3[i] = vals[i] & 2^(3-1) > 0
  Valve4[i] = vals[i] & 2^(4-1) > 0
  Valve5[i] = vals[i] & 2^(5-1) > 0
  Valve6[i] = vals[i] & 2^(6-1) > 0
  Valve7[i] = vals[i] & 2^(7-1) > 0
  Valve8[i] = vals[i] & 2^(8-1) > 0
   end # End of conversion
 

   new(Valve1,Valve2,Valve3,Valve4,Valve5,Valve6,Valve7,Valve8)
 

   end # End of constructor
end # End of type

statuses = Status(vector(Dstc["StatusW"]))
julia> typeof(statuses) Nothing (constructor with 1 method)

julia> statuses.Valve1 ErrorException("type Nothing has no field Valve1")



julia> x = Status([1:12])

julia> typeof(x) Nothing (constructor with 1 method)

julia> x.Valve1 ErrorException("type Nothing has no field Valve1")


Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread Tim Holy
On Monday, March 24, 2014 03:56:08 AM RecentConvert wrote:
> statuses = Status(vector(Dstc["StatusW"]))

That's still not very helpful, because we have no idea what 
vector(Dstc["StatusW"]) yields. Does Status([1:12]) work? If so, the problem 
is in the particular inputs you're supplying. If not, then I'm not sure what's 
going on.

--Tim



[julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread RecentConvert
Thanks for the quick replies.

*Purpose:* Given a double, convert it to a collection of boolean values 
representing the statuses of various valves and settings.

I'm still torn about whether I want to input an array of values and store 
arrays of statuses in one type or create an array of the type with 
individual collections. This implementation is *intended* to be for arrays. 
It's partly to teach myself Julia so learning how to do it this way is 
important but I am also open to *just do it this really easy way*. Once I 
have the parsed statuses I can use it separate calibration data from the 
rest of the data, among other things.

I call it with the following line:
statuses = Status(vector(Dstc["StatusW"]))

The original format is a data frame.

Julia Version 0.2.1 

Commit e44b593* (2014-02-11 06:30 UTC)

Platform Info:

  System: Windows (x86_64-w64-mingw32)

  WORD_SIZE: 64





[julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread Ivar Nesje
Sorry that you did not get any response, I did not comprehend what you were 
trying to do last time.

The code you posted seems to work fine for me on 0.2.1 and 0.3-prerelease. 
How did you trigger the error?

As a side note if efficiency is important, I would recommend that you use 
Valve2::Array{Bool, 1} or the equivalent Valve2::Vector{Bool} in the type 
declaration, so that Julia knows it will not get a matrix or tensor of 
booleans from your type.

Ivar


kl. 11:02:37 UTC+1 mandag 24. mars 2014 skrev RecentConvert følgende:
>
> Is this question not clear or just uninteresting?
>


Re: [julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread Tim Holy
On Monday, March 24, 2014 03:02:37 AM RecentConvert wrote:
> Is this question not clear or just uninteresting?

You're not showing how you're actually calling the constructor. If I 
copy/paste your type definition, and then say Status([1:12]), it works just 
fine 
for me. What version of Julia are you running? I'm on master from about a week 
ago.

A few comments:
- Your arrays have ambiguous dimensionality, so this will be slow. Presumably 
it would be better to declare the fields as Valve1::Vector{Bool}. Or if you 
need multiple dimensionalities, put the dimensionality N as a parameter of the 
type, Status{N}, and declare them as Array{Bool, N}.
- I don't see the reason for "int64" in int64(length(vals)).
- You probably already know this, but in case it's useful to you: BitArrays 
represent an Int64 (or vector of Int64s) as an array of bits.

--Tim



[julia-users] Re: Build a constructor with fewer inputs than values

2014-03-24 Thread RecentConvert
Is this question not clear or just uninteresting?